diff --git a/src/router.c b/src/router.c index 6b2c737..327dc5a 100644 --- a/src/router.c +++ b/src/router.c @@ -204,7 +204,14 @@ DWORD router_main(void *arg) { continue; } - add_host(packet->src_net, packet->src_node, addr.sin_addr.s_addr); + /* Replace destination network field of packet with source IP address + * so that the client can cache it. + */ + + char dest_net[4]; + + memcpy(dest_net, packet->dest_net, 4); + memcpy(packet->dest_net, &(addr.sin_addr.s_addr), 4); struct router_addr *ra = router->addrs; @@ -212,7 +219,7 @@ DWORD router_main(void *arg) { if( ra->local_port && (ra->filter_ptype < 0 || ra->filter_ptype == packet->ptype) && - (memcmp(packet->dest_net, ra->addr.sa_netnum, 4) == 0 || memcmp(packet->dest_net, f6, 4) == 0) && + (memcmp(dest_net, ra->addr.sa_netnum, 4) == 0 || memcmp(dest_net, f6, 4) == 0) && (memcmp(packet->dest_node, ra->addr.sa_nodenum, 6) == 0 || memcmp(packet->dest_node, f6, 6) == 0) && packet->dest_socket == ra->addr.sa_socket ) { diff --git a/src/winsock.c b/src/winsock.c index 5d7bd50..6eb330e 100644 --- a/src/winsock.c +++ b/src/winsock.c @@ -322,6 +322,17 @@ static int recv_packet(ipx_socket *sockptr, char *buf, int bufsize, int flags, s return -1; } + if(rval < sizeof(ipx_packet) || rval != packet->size + sizeof(ipx_packet) - 1) { + log_printf("Invalid packet received on loopback port!"); + + free(packet); + WSASetLastError(WSAEWOULDBLOCK); + return -1; + } + + /* Router thread replaces destination network number with source IP address */ + add_host(packet->src_net, packet->src_node, *((uint32_t*)packet->dest_net)); + if(addr) { addr->sa_family = AF_IPX; memcpy(addr->sa_netnum, packet->src_net, 4);