]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
correct checksum calculation when adding the overflow overflows 110/head
authorrussor <russor@whatsapp.com>
Mon, 18 Apr 2016 22:22:50 +0000 (15:22 -0700)
committerrussor <russor@whatsapp.com>
Mon, 18 Apr 2016 22:22:50 +0000 (15:22 -0700)
you can see this with a bit pattern of FF and a large packet length

net.c

diff --git a/net.c b/net.c
index f743492457593302bf917f84e5ea7a553bd424dd..60b2b68dac3f283bf4e606f43532dde65c9d2c8f 100644 (file)
--- a/net.c
+++ b/net.c
@@ -247,8 +247,9 @@ int checksum(void *data, int sz)
   while (sz--) {
     sum += *(ch++);
   }
-  
-  sum = (sum >> 16) + (sum & 0xffff);  
+  while (sum >> 16) {
+    sum = (sum >> 16) + (sum & 0xffff);
+  }
 
   return (~sum & 0xffff);  
 }