Index: include/lwip/sockets.h =================================================================== --- include/lwip/sockets.h (revision 2329) +++ include/lwip/sockets.h (revision 2330) @@ -115,6 +115,7 @@ #define INADDR_BROADCAST 0xffffffff /* Flags we can use with send and recv. */ +#define MSG_PEEK 0x02 #define MSG_DONTWAIT 0x40 /* Nonblocking i/o for this operation only */ Index: api/sockets.c =================================================================== --- api/sockets.c (revision 2329) +++ api/sockets.c (revision 2330) @@ -345,7 +345,7 @@ { struct lwip_socket *sock; struct netbuf *buf; - u16_t buflen, copylen; + u16_t buflen, copylen, acklen; struct ip_addr *addr; u16_t port; @@ -392,6 +392,12 @@ copylen = len; } + if ((flags & MSG_PEEK)) { + acklen = 0; + } else { + acklen = copylen; + } + /* copy the contents of the received buffer into the supplied memory pointer mem */ netbuf_copy_partial(buf, mem, copylen, sock->lastoffset); @@ -432,9 +438,9 @@ /* If this is a TCP socket, check if there is data left in the buffer. If so, it should be saved in the sock structure for next time around. */ - if (netconn_type(sock->conn) == NETCONN_TCP && buflen - copylen > 0) { + if (netconn_type(sock->conn) == NETCONN_TCP && buflen - acklen > 0) { sock->lastdata = buf; - sock->lastoffset += copylen; + sock->lastoffset += acklen; } else { sock->lastdata = NULL; sock->lastoffset = 0;