From: russor Date: Mon, 18 Apr 2016 22:22:50 +0000 (-0700) Subject: correct checksum calculation when adding the overflow overflows X-Git-Tag: v0.87~12^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=refs%2Fpull%2F110%2Fhead;p=thirdparty%2Fmtr.git correct checksum calculation when adding the overflow overflows you can see this with a bit pattern of FF and a large packet length --- diff --git a/net.c b/net.c index f743492..60b2b68 100644 --- 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); }