recvfrom: Allow NULL argument.
authorBruno Haible <bruno@clisp.org>
Fri, 11 Dec 2009 00:31:21 +0000 (01:31 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 11 Dec 2009 00:31:21 +0000 (01:31 +0100)
ChangeLog
lib/recvfrom.c

index 0425b9e..ff9938e 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,7 @@
+2009-12-10  Bruno Haible  <bruno@clisp.org>
+
+       * lib/recvfrom.c (rpl_recvfrom): Allow the from argument to be NULL.
+
 2009-12-10  Bruno Haible  <bruno@clisp.org>
 
        Declare which arguments expect non-NULL values, for GCC and clang.
index a9c0aff..5da14ae 100644 (file)
@@ -1,6 +1,6 @@
 /* recvfrom.c --- wrappers for Windows recvfrom function
 
-   Copyright (C) 2008 Free Software Foundation, Inc.
+   Copyright (C) 2008-2009 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,7 +32,7 @@ int
 rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
               int *fromlen)
 {
-  int frombufsize = *fromlen;
+  int frombufsize = (from != NULL ? *fromlen : 0);
   SOCKET sock = FD_TO_SOCKET (fd);
   int r = recvfrom (sock, buf, len, flags, from, fromlen);
 
@@ -41,7 +41,7 @@ rpl_recvfrom (int fd, void *buf, int len, int flags, struct sockaddr *from,
 
   /* 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)
+  else if (from != NULL && *fromlen == frombufsize)
     rpl_getpeername (fd, from, fromlen);
 
   return r;