From: russor Date: Fri, 8 Apr 2016 23:34:26 +0000 (-0700) Subject: fix checksum for odd sized packets X-Git-Tag: v0.87~12^2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=6f06bc68042cdc8e6d889649f4ad48ea0ac62d71;p=thirdparty%2Fmtr.git fix checksum for odd sized packets --- diff --git a/net.c b/net.c index 4806825..529f496 100644 --- 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++);