From 2a8398dfb8a07c0f9fda41411954904e0cd9df21 Mon Sep 17 00:00:00 2001 From: Joel Cunningham Date: Thu, 25 Feb 2016 12:53:12 -0600 Subject: [PATCH] Fix bug in FIONREAD handling in LINUXMODE Fix a bug in the socket API's ioctl for FIONREAD. If the socket's lastdata was assigned the function returned without error but did not update the argument pointer. The cast type for argp was also changed to int to conform with the other SO_RCVBUF handling. --- src/api/sockets.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/api/sockets.c b/src/api/sockets.c index 92a168f2..d7054d34 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -2621,18 +2621,20 @@ lwip_ioctl(int s, long cmd, void *argp) struct pbuf *p; if (sock->lastdata) { p = ((struct netbuf *)sock->lastdata)->p; + *((int*)argp) = p->tot_len - sock->lastoffset; } else { struct netbuf *rxbuf; err_t err; if (sock->rcvevent <= 0) { - *((u16_t*)argp) = 0; + *((int*)argp) = 0; } else { err = netconn_recv(sock->conn, &rxbuf); if (err != ERR_OK) { - *((u16_t*)argp) = 0; + *((int*)argp) = 0; } else { sock->lastdata = rxbuf; - *((u16_t*)argp) = rxbuf->p->tot_len; + sock->lastoffset = 0; + *((int*)argp) = rxbuf->p->tot_len; } } }