From 7eb63c1c2d8e3d8e2aac90779f6abedf38ad4b54 Mon Sep 17 00:00:00 2001 From: david Date: Fri, 3 Jul 2009 18:27:31 +0000 Subject: [PATCH] On some BSD systems, we have to byte-swap the ip_len and ip_off fields before sending. In send_ip_packet, unswap them after sending so that the buffer is returned unmodified. Do the packet trace after unswapping the values so that the correct length and fragmentation offset are reported. On Mac OS X, an ip_len of 60 (0x003c) was being reported as 15360 (0x3c00) and when ip_off had the DF flag set (0x4000), it looked like a fragmentation offset of 512 (0x0040 * 8). --- tcpip.cc | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tcpip.cc b/tcpip.cc index f3eca192d..674eb101f 100644 --- a/tcpip.cc +++ b/tcpip.cc @@ -1370,8 +1370,6 @@ do { retries++; } while( res == -1); - PacketTrace::trace(PacketTrace::SENT, packet, len); - return res; } @@ -1442,6 +1440,15 @@ int send_ip_packet(int sd, struct eth_nfo *eth, u8 *packet, unsigned int packetl res = Sendto("send_ip_packet", sd, packet, packetlen, 0, (struct sockaddr *)&sock, (int)sizeof(struct sockaddr_in)); + + /* Undo the byte order switching. */ +#if FREEBSD || BSDI || NETBSD || DEC || MACOSX + ip->ip_len = htons(ip->ip_len); + ip->ip_off = htons(ip->ip_off); +#endif + + PacketTrace::trace(PacketTrace::SENT, packet, packetlen); + return res; }