From 16a17a496ce84c5866af45a66f181ce193a9376f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Manuel=20P=C3=A9gouri=C3=A9-Gonnard?= Date: Tue, 30 Jun 2015 11:20:22 +0200 Subject: [PATCH] Fix net_accept() for UDP sockets on Windows On Windows, recvfrom() returns an error code if the destination buffer is too small to hold the next datagram. --- library/net.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/library/net.c b/library/net.c index bfa7072d1..b3928799d 100644 --- a/library/net.c +++ b/library/net.c @@ -309,6 +309,15 @@ int mbedtls_net_accept( int bind_fd, int *client_fd, ret = recvfrom( bind_fd, buf, sizeof( buf ), MSG_PEEK, (struct sockaddr *) &client_addr, &n ); + +#if defined(_WIN32) + if( ret == SOCKET_ERROR && + WSAGetLastError() == WSAEMSGSIZE ) + { + /* We know buf is too small, thanks, just peeking here */ + ret = 0; + } +#endif } if( ret < 0 )