diff --git a/src/api/api_lib.c b/src/api/api_lib.c index 28465935..89de39d1 100644 --- a/src/api/api_lib.c +++ b/src/api/api_lib.c @@ -606,12 +606,30 @@ netconn_recv_data(struct netconn *conn, void **new_buf) err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf) { - LWIP_ERROR("netconn_recv: invalid conn", (conn != NULL) && + LWIP_ERROR("netconn_recv_tcp_pbuf: invalid conn", (conn != NULL) && NETCONNTYPE_GROUP(netconn_type(conn)) == NETCONN_TCP, return ERR_ARG;); return netconn_recv_data(conn, (void **)new_buf); } +/** + * Receive data (in form of a netbuf) from a UDP or RAW netconn + * + * @param conn the netconn from which to receive data + * @param new_buf pointer where a new netbuf is stored when received data + * @return ERR_OK if data has been received, an error code otherwise (timeout, + * memory error or another error) + * ERR_ARG if conn is not a UDP/RAW netconn + */ +err_t +netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf) +{ + LWIP_ERROR("netconn_recv_udp_raw_netbuf: invalid conn", (conn != NULL) && + NETCONNTYPE_GROUP(netconn_type(conn)) != NETCONN_TCP, return ERR_ARG;); + + return netconn_recv_data(conn, (void **)new_buf); +} + /** * @ingroup netconn_common * Receive data (in form of a netbuf containing a packet buffer) from a netconn diff --git a/src/api/sockets.c b/src/api/sockets.c index 12aa6803..f67162ab 100644 --- a/src/api/sockets.c +++ b/src/api/sockets.c @@ -775,7 +775,7 @@ lwip_recvfrom(int s, void *mem, size_t len, int flags, if (NETCONNTYPE_GROUP(netconn_type(sock->conn)) == NETCONN_TCP) { err = netconn_recv_tcp_pbuf(sock->conn, (struct pbuf **)&buf); } else { - err = netconn_recv(sock->conn, (struct netbuf **)&buf); + err = netconn_recv_udp_raw_netbuf(sock->conn, (struct netbuf **)&buf); } LWIP_DEBUGF(SOCKETS_DEBUG, ("lwip_recvfrom: netconn_recv err=%d, netbuf=%p\n", err, buf)); @@ -2636,7 +2636,7 @@ lwip_ioctl(int s, long cmd, void *argp) if (sock->rcvevent <= 0) { *((int*)argp) = 0; } else { - err = netconn_recv(sock->conn, &rxbuf); + err = netconn_recv_udp_raw_netbuf(sock->conn, &rxbuf); if (err != ERR_OK) { *((int*)argp) = 0; } else { diff --git a/src/include/lwip/api.h b/src/include/lwip/api.h index 516bd163..798c29ae 100644 --- a/src/include/lwip/api.h +++ b/src/include/lwip/api.h @@ -313,6 +313,7 @@ err_t netconn_listen_with_backlog(struct netconn *conn, u8_t backlog); #define netconn_listen(conn) netconn_listen_with_backlog(conn, TCP_DEFAULT_LISTEN_BACKLOG) err_t netconn_accept(struct netconn *conn, struct netconn **new_conn); err_t netconn_recv(struct netconn *conn, struct netbuf **new_buf); +err_t netconn_recv_udp_raw_netbuf(struct netconn *conn, struct netbuf **new_buf); err_t netconn_recv_tcp_pbuf(struct netconn *conn, struct pbuf **new_buf); err_t netconn_sendto(struct netconn *conn, struct netbuf *buf, const ip_addr_t *addr, u16_t port);