diff options
author | Ambroz Bizjak <ambrop7@gmail.com> | 2017-03-12 14:02:02 +0300 |
---|---|---|
committer | Ambroz Bizjak <ambrop7@gmail.com> | 2017-03-12 14:02:02 +0300 |
commit | ffd16e27d0bd58fec068fa9271b33fe559efb5a5 (patch) | |
tree | ce591415323c9bb2f7d23f690c2fa42a8bc588f2 | |
parent | 6a4654b7462cdd3170f1a59f86546311f0448062 (diff) |
Fix bug UDP checksum calculation.
Check for zero result should be done after not before inverting.
-rw-r--r-- | misc/udp_proto.h | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/misc/udp_proto.h b/misc/udp_proto.h index 23ec69a..844936f 100644 --- a/misc/udp_proto.h +++ b/misc/udp_proto.h @@ -92,11 +92,13 @@ static uint16_t udp_checksum (const struct udp_header *header, const uint8_t *pa t = (t & 0xFFFF) + (t >> 16); } + t = ~t; + if (t == 0) { t = UINT16_MAX; } - return hton16(~t); + return hton16(t); } static uint16_t udp_ip6_checksum (const struct udp_header *header, const uint8_t *payload, uint16_t payload_len, const uint8_t *source_addr, const uint8_t *dest_addr) @@ -128,11 +130,13 @@ static uint16_t udp_ip6_checksum (const struct udp_header *header, const uint8_t t = (t & 0xFFFF) + (t >> 16); } + t = ~t; + if (t == 0) { t = UINT16_MAX; } - return hton16(~t); + return hton16(t); } static int udp_check (const uint8_t *data, int data_len, struct udp_header *out_header, uint8_t **out_payload, int *out_payload_len) |