Updated cksum.
authorfredrik@DOLDA2000.COM <fredrik@DOLDA2000.COM@959494ce-11ee-0310-bf91-de5d638817bd>
Fri, 29 Apr 2005 00:35:06 +0000 (00:35 +0000)
committerfredrik@DOLDA2000.COM <fredrik@DOLDA2000.COM@959494ce-11ee-0310-bf91-de5d638817bd>
Fri, 29 Apr 2005 00:35:06 +0000 (00:35 +0000)
git-svn-id: svn+ssh://svn.dolda2000.com/srv/svn/repos/src/icmp-dn@212 959494ce-11ee-0310-bf91-de5d638817bd

idnlookup.c

index bd45b75..43518ef 100644 (file)
@@ -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)