]> git.ipfire.org Git - thirdparty/mtr.git/commitdiff
fix checksum for odd sized packets
authorrussor <russor@whatsapp.com>
Fri, 8 Apr 2016 23:34:26 +0000 (16:34 -0700)
committerrussor <russor@whatsapp.com>
Fri, 8 Apr 2016 23:59:27 +0000 (16:59 -0700)
net.c

diff --git a/net.c b/net.c
index 48068250865c9b9842a767e10a06bceacb131333..529f496a96452c54bbf18eaf4b9fa90cea5a72ad 100644 (file)
--- a/net.c
+++ b/net.c
@@ -231,15 +231,19 @@ int calc_deltatime (float waittime)
 }
 
 
-/* This doesn't work for odd sz. I don't know enough about this to say
-   that this is wrong. It doesn't seem to cripple mtr though. -- REW */
 int checksum(void *data, int sz) 
 {
   unsigned short *ch;
   unsigned int sum;
+  char odd[2];
 
   sum = 0;
   ch = data;
+  if (sz % 2) {
+    odd[0] = ((char*)data)[sz - 1];
+    odd[1] = 0;
+    sum = *(unsigned short*)(void*)&odd;
+  }
   sz = sz / 2;
   while (sz--) {
     sum += *(ch++);