From 7c19414c37f8780f5d012d1e0d09b85436c98ee9 Mon Sep 17 00:00:00 2001 From: Daniel Collins Date: Mon, 14 Apr 2014 22:45:38 +0100 Subject: [PATCH] Use appropriate MTU for packet size limits. --- src/interface.c | 2 +- src/interface.h | 3 +++ src/winsock.c | 13 ++++++++++--- 3 files changed, 14 insertions(+), 4 deletions(-) diff --git a/src/interface.c b/src/interface.c index 7897ae9..4d0c1f8 100644 --- a/src/interface.c +++ b/src/interface.c @@ -414,7 +414,7 @@ static void _init_pcap_interfaces(void) } char errbuf[PCAP_ERRBUF_SIZE]; - pcap_t *pcap = pcap_open(i->name, 1500 /* TODO */, PCAP_OPENFLAG_MAX_RESPONSIVENESS, 0, NULL, errbuf); + pcap_t *pcap = pcap_open(i->name, ETHERNET_MTU, PCAP_OPENFLAG_MAX_RESPONSIVENESS, 0, NULL, errbuf); if(!pcap) { log_printf(LOG_ERROR, "Could not open WinPcap interface '%s': %s", i->name, errbuf); diff --git a/src/interface.h b/src/interface.h index d25d583..b2efba3 100644 --- a/src/interface.h +++ b/src/interface.h @@ -29,6 +29,9 @@ extern "C" { #endif +/* TODO: Dynamic MTU, per interface. */ +#define ETHERNET_MTU 1500 + #define WILDCARD_IFACE_HWADDR addr48_in((unsigned char[]){0x00,0x00,0x00,0x00,0x00,0x00}) typedef struct ipx_interface_ip ipx_interface_ip_t; diff --git a/src/winsock.c b/src/winsock.c index a8311be..a15940a 100644 --- a/src/winsock.c +++ b/src/winsock.c @@ -72,6 +72,13 @@ static size_t strsize(void *str, bool unicode) : strlen(str) + 1; } +static int _max_ipx_payload(void) +{ + return ipx_use_pcap + ? (ETHERNET_MTU - sizeof(real_ipx_packet_t)) + : MAX_DATA_SIZE; +} + #define PUSH_NAME(name) \ { \ int i = 0; \ @@ -921,7 +928,7 @@ int WSAAPI getsockopt(SOCKET fd, int level, int optname, char FAR *optval, int F } else if(optname == IPX_MAXSIZE) { - RETURN_INT_OPT(MAX_DATA_SIZE); + RETURN_INT_OPT(_max_ipx_payload()); } else if(optname == IPX_ADDRESS) { @@ -944,7 +951,7 @@ int WSAAPI getsockopt(SOCKET fd, int level, int optname, char FAR *optval, int F ipxdata->wan = FALSE; ipxdata->status = FALSE; - ipxdata->maxpkt = MAX_DATA_SIZE; + ipxdata->maxpkt = _max_ipx_payload(); ipxdata->linkspeed = 100000; /* 10MBps */ free_ipx_interface(nic); @@ -1406,7 +1413,7 @@ int WSAAPI sendto(SOCKET fd, const char *buf, int len, int flags, const struct s } } - if(len > MAX_DATA_SIZE) + if(len > _max_ipx_payload()) { WSASetLastError(WSAEMSGSIZE);