Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/ambrop72/badvpn.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAmbroz Bizjak <ambrop7@gmail.com>2017-03-12 14:02:02 +0300
committerAmbroz Bizjak <ambrop7@gmail.com>2017-03-12 14:02:02 +0300
commitffd16e27d0bd58fec068fa9271b33fe559efb5a5 (patch)
treece591415323c9bb2f7d23f690c2fa42a8bc588f2
parent6a4654b7462cdd3170f1a59f86546311f0448062 (diff)
Fix bug UDP checksum calculation.
Check for zero result should be done after not before inverting.
-rw-r--r--misc/udp_proto.h8
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)