Commit 765443c7 authored by Alessandro Rubini's avatar Alessandro Rubini

udp: bugfix for checksum generation

the UDP checlsum was miscalculated for odd-sized payload. The last
byte was not used in calculation.
Signed-off-by: Alessandro Rubini's avatarAlessandro Rubini <rubini@gnudd.com>
parent 0887cbbe
......@@ -40,9 +40,9 @@ void fill_udp(uint8_t * buf, int len, struct wr_udp_addr *uaddr)
buf[UDP_CHECKSUM] = 0;
buf[UDP_CHECKSUM + 1] = 0;
sum =
ipv4_checksum((unsigned short *)(buf + UDP_VIRT_SADDR),
(len - UDP_VIRT_SADDR) / 2);
buf[len] = '\0'; /* pad, in case the payload is odd */
sum = ipv4_checksum((unsigned short *)(buf + UDP_VIRT_SADDR),
(len + 1 - UDP_VIRT_SADDR) / 2);
if (sum == 0)
sum = 0xFFFF;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment