From f73194fbbbe3cf075ce82c2d5e56274245e042e6 Mon Sep 17 00:00:00 2001 From: Yash Katkar <63966974+yk8329@users.noreply.github.com> Date: Fri, 29 Mar 2024 21:05:16 +0000 Subject: [PATCH] feat: add the padding if the packet length is odd while updating udp checksum --- examples/network/sta2eth/main/ethernet_iface.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/examples/network/sta2eth/main/ethernet_iface.c b/examples/network/sta2eth/main/ethernet_iface.c index 87c99182d3..edc451a0c3 100644 --- a/examples/network/sta2eth/main/ethernet_iface.c +++ b/examples/network/sta2eth/main/ethernet_iface.c @@ -118,6 +118,10 @@ static void update_udp_checksum(uint16_t *udp_header, uint16_t* ip_header) for (int i = 0; i < payload_len/2; i++) { sum += htons(*ptr++); } + // add the padding if the packet length is odd + if (payload_len & 1) { + sum += (*((uint8_t *)ptr) << 8); + } // add some IP header data ptr = ip_header + 6; for (int i = 0; i < 4; i++) { // IP addresses