diff options
author | Ted Lemon <source@isc.org> | 1997-03-05 06:15:00 +0000 |
---|---|---|
committer | Ted Lemon <source@isc.org> | 1997-03-05 06:15:00 +0000 |
commit | f09bfe772e5df38a6d12cb8e3849a9e9181a70ac (patch) | |
tree | 81bbafe6108b6da27af7864682df4adc37d268ce /common/packet.c | |
parent | d5e5a87a4878726878f17229d3070efcccfcc64d (diff) | |
download | isc-dhcp-f09bfe772e5df38a6d12cb8e3849a9e9181a70ac.tar.gz |
New IP header checksum code supplied by Anatoli Logvinski
Diffstat (limited to 'common/packet.c')
-rw-r--r-- | common/packet.c | 18 |
1 files changed, 6 insertions, 12 deletions
diff --git a/common/packet.c b/common/packet.c index 1fc9a0bb..b7752e23 100644 --- a/common/packet.c +++ b/common/packet.c @@ -40,9 +40,10 @@ * Enterprises, see ``http://www.vix.com''. */ + #ifndef lint static char copyright[] = -"$Id: packet.c,v 1.12 1997/02/18 14:32:51 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium. All rights reserved.\n"; +"$Id: packet.c,v 1.13 1997/03/05 06:15:00 mellon Exp $ Copyright (c) 1996 The Internet Software Consortium. All rights reserved.\n"; #endif /* not lint */ #include "dhcpd.h" @@ -75,7 +76,6 @@ static u_int32_t checksum (buf, nbytes, sum) #endif sum += (u_int16_t) ntohs(*((u_int16_t *)buf)++); } - /* If there's a single byte left over, checksum it, too. Network byte order is big-endian, so the remaining byte is the high byte. */ if (i < nbytes) { @@ -97,26 +97,20 @@ static u_int32_t wrapsum (sum) #ifdef DEBUG_CHECKSUM debug ("wrapsum (%x)", sum); #endif - - while (sum > 0x10000) { - sum = (sum >> 16) + (sum & 0xFFFF); -#ifdef DEBUG_CHECKSUM_VERBOSE - debug ("sum = %x", sum); -#endif - sum += (sum >> 16); + while (sum >> 16) { #ifdef DEBUG_CHECKSUM_VERBOSE debug ("sum = %x", sum); #endif + sum = (sum & 0xFFFF) + (sum >> 16); } - sum = sum ^ 0xFFFF; #ifdef DEBUG_CHECKSUM_VERBOSE debug ("sum = %x", sum); #endif #ifdef DEBUG_CHECKSUM - debug ("wrapsum returns %x", htons (sum)); + debug ("wrapsum returns %x", htons (~sum)); #endif - return htons(sum); + return htons(~sum); } #endif /* PACKET_ASSEMBLY || PACKET_DECODING */ |