From b2c2a407cf7c7d17b4bded283c6bd3af5c92e6f7 Mon Sep 17 00:00:00 2001 From: fbernon Date: Wed, 12 Mar 2008 10:56:40 +0000 Subject: [PATCH] contrib/apps/ping.c: Fix bug #22530 "api_msg.c's recv_raw() does not consume data", and the ping sample (with LWIP_SOCKET=1, the code did the wrong supposition that lwip_recvfrom returned the IP payload, without the IP header). --- apps/ping/ping.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/apps/ping/ping.c b/apps/ping/ping.c index 426529f..d084c6a 100644 --- a/apps/ping/ping.c +++ b/apps/ping/ping.c @@ -151,15 +151,17 @@ ping_recv(int s) char buf[64]; int fromlen, len; struct sockaddr_in from; + struct ip_hdr *iphdr; struct icmp_echo_hdr *iecho; while((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) { - if (len >= sizeof(struct icmp_echo_hdr)) { + if (len >= (sizeof(struct ip_hdr)+sizeof(struct icmp_echo_hdr))) { LWIP_DEBUGF( PING_DEBUG, ("ping: recv ")); ip_addr_debug_print(PING_DEBUG, (struct ip_addr *)&(from.sin_addr)); LWIP_DEBUGF( PING_DEBUG, (" %lu ms\n", (sys_now()-ping_time))); - iecho = (struct icmp_echo_hdr *)buf; + iphdr = (struct ip_hdr *)buf; + iecho = (struct icmp_echo_hdr *)(buf+(IPH_HL(iphdr) * 4)); if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num))) { /* do some ping result processing */ PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER));