mirror of
https://github.com/RIOT-OS/RIOT.git
synced 2024-12-29 04:50:03 +01:00
ng_inet_csum: fix double-wrap around of carry
This commit is contained in:
parent
6ce23a42f5
commit
ad6c02b349
@ -43,11 +43,14 @@ uint16_t ng_inet_csum(uint16_t sum, const uint8_t *buf, uint16_t len)
|
||||
csum += (*buf << 8); /* add last byte as top half of 16-byte word */
|
||||
}
|
||||
|
||||
csum += csum >> 16;
|
||||
while (csum >> 16) {
|
||||
uint16_t carry = csum >> 16;
|
||||
csum = (csum & 0xffff) + carry;
|
||||
}
|
||||
|
||||
DEBUG("inet_sum: new sum = 0x%04" PRIx32 "\n", csum & 0xffff);
|
||||
DEBUG("inet_sum: new sum = 0x%04" PRIx32 "\n", csum);
|
||||
|
||||
return (csum & 0xffff);
|
||||
return csum;
|
||||
}
|
||||
|
||||
/** @} */
|
||||
|
Loading…
Reference in New Issue
Block a user