mirror of
https://github.com/ep00ch/lwip-contrib-mac.git
synced 2024-10-12 08:23:42 +00:00
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).
This commit is contained in:
parent
19cd8d9d9a
commit
b2c2a407cf
@ -151,15 +151,17 @@ ping_recv(int s)
|
|||||||
char buf[64];
|
char buf[64];
|
||||||
int fromlen, len;
|
int fromlen, len;
|
||||||
struct sockaddr_in from;
|
struct sockaddr_in from;
|
||||||
|
struct ip_hdr *iphdr;
|
||||||
struct icmp_echo_hdr *iecho;
|
struct icmp_echo_hdr *iecho;
|
||||||
|
|
||||||
while((len = lwip_recvfrom(s, buf, sizeof(buf), 0, (struct sockaddr*)&from, (socklen_t*)&fromlen)) > 0) {
|
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 "));
|
LWIP_DEBUGF( PING_DEBUG, ("ping: recv "));
|
||||||
ip_addr_debug_print(PING_DEBUG, (struct ip_addr *)&(from.sin_addr));
|
ip_addr_debug_print(PING_DEBUG, (struct ip_addr *)&(from.sin_addr));
|
||||||
LWIP_DEBUGF( PING_DEBUG, (" %lu ms\n", (sys_now()-ping_time)));
|
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))) {
|
if ((iecho->id == PING_ID) && (iecho->seqno == htons(ping_seq_num))) {
|
||||||
/* do some ping result processing */
|
/* do some ping result processing */
|
||||||
PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER));
|
PING_RESULT((ICMPH_TYPE(iecho) == ICMP_ER));
|
||||||
|
Loading…
Reference in New Issue
Block a user