From 552106e2a494c4da89d744ce7988487f7124f491 Mon Sep 17 00:00:00 2001 From: fbernon Date: Wed, 12 Mar 2008 10:55:54 +0000 Subject: [PATCH] api_msg.c: Fix bug #22530 "api_msg.c's recv_raw() does not consume data". --- CHANGELOG | 6 ++++++ src/api/api_msg.c | 40 ++++++++++++++++++++++++++-------------- 2 files changed, 32 insertions(+), 14 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index f2e46370..740e4973 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -600,6 +600,12 @@ HISTORY ++ Bug fixes: + 2008-03-12 Frédéric Bernon, Jonathan Larmour + * api_msg.c, 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). + 2008-03-04 Jonathan Larmour * mem.c, stats.c, mem.h: apply patch #6414 to avoid compiler errors and/or warnings on some systems where mem_size_t and size_t differ. diff --git a/src/api/api_msg.c b/src/api/api_msg.c index 3464d071..0e5c32ca 100644 --- a/src/api/api_msg.c +++ b/src/api/api_msg.c @@ -70,6 +70,7 @@ static u8_t recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p, struct ip_addr *addr) { + struct pbuf *q; struct netbuf *buf; struct netconn *conn; #if LWIP_SO_RCVBUF @@ -85,21 +86,33 @@ recv_raw(void *arg, struct raw_pcb *pcb, struct pbuf *p, #else /* LWIP_SO_RCVBUF */ if ((conn != NULL) && (conn->recvmbox != SYS_MBOX_NULL)) { #endif /* LWIP_SO_RCVBUF */ - buf = memp_malloc(MEMP_NETBUF); - if (buf == NULL) { - return 0; + /* copy the whole packet into new pbufs */ + q = pbuf_alloc(PBUF_RAW, p->tot_len, PBUF_RAM); + if(q != NULL) { + if (pbuf_copy(q, p) != ERR_OK) { + pbuf_free(q); + q = NULL; + } } - pbuf_ref(p); - buf->p = p; - buf->ptr = p; - buf->addr = addr; - buf->port = pcb->protocol; - SYS_ARCH_INC(conn->recv_avail, p->tot_len); - /* Register event with callback */ - API_EVENT(conn, NETCONN_EVT_RCVPLUS, p->tot_len); - if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) { - netbuf_delete(buf); + if(q != NULL) { + buf = memp_malloc(MEMP_NETBUF); + if (buf == NULL) { + pbuf_free(q); + return 0; + } + + buf->p = q; + buf->ptr = q; + buf->addr = addr; + buf->port = pcb->protocol; + + SYS_ARCH_INC(conn->recv_avail, q->tot_len); + /* Register event with callback */ + API_EVENT(conn, NETCONN_EVT_RCVPLUS, q->tot_len); + if (sys_mbox_trypost(conn->recvmbox, buf) != ERR_OK) { + netbuf_delete(buf); + } } } @@ -1182,4 +1195,3 @@ do_gethostbyname(void *arg) #endif /* LWIP_DNS */ #endif /* LWIP_NETCONN */ -