X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;ds=inline;f=lib%2Frecvfrom.c;h=891259e1713633b2ac37fb95205b63caac78403e;hb=a3232e87aa43983f16befedc0b6311ac02aceacb;hp=5edd1d8b1c9df7fe79ad87098f997b1b203fe8d4;hpb=d60f3b0c6b0f93a601acd1cfd3923f94ca05abb0;p=gnulib.git diff --git a/lib/recvfrom.c b/lib/recvfrom.c index 5edd1d8b1..891259e17 100644 --- a/lib/recvfrom.c +++ b/lib/recvfrom.c @@ -1,6 +1,6 @@ /* recvfrom.c --- wrappers for Windows recvfrom function - Copyright (C) 2008-2011 Free Software Foundation, Inc. + Copyright (C) 2008-2013 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -32,17 +32,27 @@ ssize_t rpl_recvfrom (int fd, void *buf, size_t len, int flags, struct sockaddr *from, socklen_t *fromlen) { - int frombufsize = (from != NULL ? *fromlen : 0); SOCKET sock = FD_TO_SOCKET (fd); - int r = recvfrom (sock, buf, len, flags, from, fromlen); - if (r < 0) - set_winsock_errno (); - - /* Winsock recvfrom() only returns a valid 'from' when the socket is - connectionless. POSIX gives a valid 'from' for all types of sockets. */ - else if (from != NULL && *fromlen == frombufsize) - rpl_getpeername (fd, from, fromlen); - - return r; + if (sock == INVALID_SOCKET) + { + errno = EBADF; + return -1; + } + else + { + int frombufsize = (from != NULL ? *fromlen : 0); + int r = recvfrom (sock, buf, len, flags, from, fromlen); + + if (r < 0) + set_winsock_errno (); + + /* Winsock recvfrom() only returns a valid 'from' when the socket is + connectionless. POSIX gives a valid 'from' for all types of + sockets. */ + else if (from != NULL && *fromlen == frombufsize) + rpl_getpeername (fd, from, fromlen); + + return r; + } }