From 745071af6578ba05397d7c1ec30116a9d9134f75 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Sat, 20 Feb 2016 11:02:20 -0800 Subject: [PATCH] Use Utils::sum_range straight into ICMP checksum value --- src/icmp.cpp | 9 ++------- 1 file changed, 2 insertions(+), 7 deletions(-) diff --git a/src/icmp.cpp b/src/icmp.cpp index 07680b0..7b69d1f 100644 --- a/src/icmp.cpp +++ b/src/icmp.cpp @@ -265,13 +265,8 @@ void ICMP::write_serialization(uint8_t* buffer, uint32_t total_sz, const PDU *) extensions_.serialize(extensions_ptr, total_sz - (extensions_ptr - buffer)); } - // Calculate checksum - 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 - header_.check = ~checksum; + // Calculate checksum and write them on the serialized header + header_.check = ~Utils::sum_range(buffer, buffer + total_sz); memcpy(buffer + 2, &header_.check, sizeof(uint16_t)); }