mirror of
https://github.com/genodelabs/genode.git
synced 2025-04-16 23:39:31 +00:00
internet checksum: use signed long for accumulator
We used to use 'unsigned long' for the accumulating variable when calculating internet checksums. However, 'signed long' is more in accordance with RFC 1071 and will allow us to share the same back end for folding, once we implement incremental updating of internet checksums. Ref #4555
This commit is contained in:
parent
6b3ed6c75b
commit
d69e89f5cb
@ -31,7 +31,7 @@ struct Packed_uint8
|
||||
|
||||
static uint16_t checksum_of_raw_data(Packed_uint16 const *data_ptr,
|
||||
size_t data_sz,
|
||||
addr_t sum)
|
||||
signed long sum)
|
||||
{
|
||||
/* add up bytes in pairs */
|
||||
for (; data_sz > 1; data_sz -= sizeof(Packed_uint16)) {
|
||||
@ -77,7 +77,7 @@ uint16_t Net::internet_checksum_pseudo_ip(Packed_uint16 const *data_ptr,
|
||||
* | 4 bytes | 4 bytes | 1 byte | 1 byte | 2 bytes |
|
||||
* --------------------------------------------------------------
|
||||
*/
|
||||
addr_t sum = host_to_big_endian((uint16_t)ip_prot) + ip_data_sz_be;
|
||||
signed long sum { host_to_big_endian((uint16_t)ip_prot) + ip_data_sz_be };
|
||||
for (size_t i = 0; i < Ipv4_packet::ADDR_LEN; i += 2)
|
||||
sum += *(uint16_t*)&ip_src.addr[i] + *(uint16_t*)&ip_dst.addr[i];
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user