X-Git-Url: http://erislabs.net/gitweb/?a=blobdiff_plain;f=lib%2Frecvfrom.c;h=2f0ecdb57cddaf556e17277422555d7d083854c2;hb=ab624c1a8f744419fdb653b77250153a3563203f;hp=a9c0affea5f5b9e95a0d7eb800dd58902c0c79fa;hpb=441aa3044f43e5572f58c354f01e6bc070acd5c7;p=gnulib.git diff --git a/lib/recvfrom.c b/lib/recvfrom.c index a9c0affea..2f0ecdb57 100644 --- a/lib/recvfrom.c +++ b/lib/recvfrom.c @@ -1,6 +1,6 @@ /* recvfrom.c --- wrappers for Windows recvfrom function - Copyright (C) 2008 Free Software Foundation, Inc. + Copyright (C) 2008-2012 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 @@ -28,21 +28,31 @@ #undef recvfrom -int -rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from, - int *fromlen) +ssize_t +rpl_recvfrom (int fd, void *buf, size_t len, int flags, struct sockaddr *from, + socklen_t *fromlen) { - int frombufsize = *fromlen; 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 (*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; + } }