Safer checksum

This commit is contained in:
Baptiste Wicht 2016-09-26 11:44:57 +02:00
parent ef48b85e54
commit aa4c559a3a
No known key found for this signature in database
GPG Key ID: C5566B6C7F884532

View File

@ -36,14 +36,14 @@ network::connection_handler<udp_connection> connections;
void compute_checksum(network::ethernet::packet& packet){
auto* ip_header = reinterpret_cast<network::ip::header*>(packet.payload + packet.tag(1));
auto* udp_header = reinterpret_cast<network::udp::header*>(packet.payload + packet.index);
auto* udp_header = reinterpret_cast<network::udp::header*>(packet.payload + packet.tag(2));
udp_header->checksum = 0;
auto length = switch_endian_16(udp_header->length);
// Accumulate the Payload
auto sum = network::checksum_add_bytes(packet.payload + packet.index, length);
auto sum = network::checksum_add_bytes(packet.payload + packet.tag(2), length);
// Accumulate the IP addresses
sum += network::checksum_add_bytes(&ip_header->source_ip, 8);