X-Git-Url: http://dolda2000.com/gitweb/?p=icmp-dn.git;a=blobdiff_plain;f=idnlookup.c;h=43518ef28fae6ff1bb8fe205e4a34425292eb8bd;hp=bd45b750583a7b433dba28445dd57da8759bbbfd;hb=9cc7607e53dd79a74ed52c044a2bd8f39598b53c;hpb=3d6143ece9dc7829a59674c2d1148830a480d7ce 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)