1
0
mirror of https://github.com/mfontanini/libtins synced 2026-01-25 19:51:34 +01:00

Fix overall checksum calculation

This commit is contained in:
Matias Fontanini
2015-12-29 09:57:42 -03:00
parent afe778d03c
commit 67d31fd62c
7 changed files with 148 additions and 72 deletions

View File

@@ -262,12 +262,12 @@ void ICMP::write_serialization(uint8_t *buffer, uint32_t total_sz, const PDU *)
}
// Calculate checksum
uint32_t checksum = Utils::do_checksum(buffer, buffer + total_sz);
uint32_t checksum = Utils::sum_range(buffer, buffer + total_sz);
while (checksum >> 16) {
checksum = (checksum & 0xffff) + (checksum >> 16);
}
// Write back only the 2 checksum bytes
_icmp.check = Endian::host_to_be<uint16_t>(~checksum);
_icmp.check = ~checksum;
memcpy(buffer + 2, &_icmp.check, sizeof(uint16_t));
}