From 9cc7607e53dd79a74ed52c044a2bd8f39598b53c Mon Sep 17 00:00:00 2001 From: "fredrik@DOLDA2000.COM" Date: Fri, 29 Apr 2005 00:35:06 +0000 Subject: [PATCH] Updated cksum. git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/icmp-dn@212 959494ce-11ee-0310-bf91-de5d638817bd --- idnlookup.c | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/idnlookup.c b/idnlookup.c index bd45b75..43518ef 100644 --- a/idnlookup.c +++ b/idnlookup.c @@ -86,7 +86,7 @@ void cksum(void *hdr, size_t len) struct icmphdr *ih; u_int8_t *cb; int i; - u_int8_t b1, b2; + int b1, b2; ih = (struct icmphdr *)hdr; cb = (u_int8_t *)hdr; @@ -98,9 +98,22 @@ void cksum(void *hdr, size_t len) } if(i & 1) b1 += cb[len - 1]; + while(1) { + if(b1 >= 256) { + b2 += b1 >> 8; + b1 &= 0xff; + continue; + } + if(b2 >= 256) { + b1 += b2 >> 8; + b2 &= 0xff; + continue; + } + break; + } cb = (u_int8_t *)&ih->checksum; - cb[0] = ~b1; - cb[1] = ~b2; + cb[0] = ~(u_int8_t)b1; + cb[1] = ~(u_int8_t)b2; } void usage(void) -- 2.11.0