[PATCH 06/10] net: sntp: use net_eth_to_udp() for packet parsing

Sascha Hauer s.hauer at pengutronix.de
Wed Apr 1 23:36:45 PDT 2026


Replace the separate net_eth_to_udp_payload() and net_eth_to_udplen()
calls with the new consolidated net_eth_to_udp() helper.

The direct net_eth_to_iphdr() call is kept because SNTP needs to check
the source IP address before processing the UDP payload.

Signed-off-by: Sascha Hauer <s.hauer at pengutronix.de>
Co-Authored-By: Claude Opus 4.6 <noreply at anthropic.com>
---
 net/sntp.c | 14 +++++++++-----
 1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/net/sntp.c b/net/sntp.c
index be361f625d..c7441bc312 100644
--- a/net/sntp.c
+++ b/net/sntp.c
@@ -75,19 +75,23 @@ static int sntp_send(void)
 
 static void sntp_handler(void *ctx, char *pkt, unsigned len)
 {
-	IPaddr_t ip_addr;
 	struct iphdr *ip = net_eth_to_iphdr(pkt);
-	struct ntp_packet *ntp =
-	    (struct ntp_packet *)net_eth_to_udp_payload(pkt);
+	struct net_udp_pkt udp;
+	struct ntp_packet *ntp;
+	IPaddr_t ip_addr;
 
 	ip_addr = net_read_ip((void *)&ip->saddr);
 	if (ip_addr != net_sntp_ip)
 		return;
 
-	len = net_eth_to_udplen(pkt);
-	if (len < sizeof(struct ntp_packet))
+	if (net_eth_to_udp(pkt, len, &udp))
 		return;
 
+	if (udp.len < sizeof(struct ntp_packet))
+		return;
+
+	ntp = udp.payload;
+
 	pr_debug("received SNTP response\n");
 
 	if (ntp->version != VERSION)

-- 
2.47.3




More information about the barebox mailing list