gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r15284 - gnunet/src/util


From: gnunet
Subject: [GNUnet-SVN] r15284 - gnunet/src/util
Date: Tue, 24 May 2011 18:35:59 +0200

Author: wachs
Date: 2011-05-24 18:35:59 +0200 (Tue, 24 May 2011)
New Revision: 15284

Modified:
   gnunet/src/util/network.c
Log:
bug on bsd


Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2011-05-24 16:26:10 UTC (rev 15283)
+++ gnunet/src/util/network.c   2011-05-24 16:35:59 UTC (rev 15284)
@@ -29,7 +29,7 @@
 #include "disk.h"
 #include "gnunet_container_lib.h"
 
-#define DEBUG_NETWORK GNUNET_NO
+#define DEBUG_NETWORK GNUNET_YES
 
 #ifndef INVALID_SOCKET
 #define INVALID_SOCKET -1
@@ -49,6 +49,17 @@
    * Address family / domain.
    */
   int af;
+
+  /**
+   * Number of bytes in addr.
+   */
+  socklen_t addrlen;
+
+  /**
+   * Address we were bound to, or NULL.
+   */
+  struct sockaddr *addr;
+
 };
 
 
@@ -279,23 +290,30 @@
 #endif
 #endif
 #endif
+#ifndef LINUX
+#ifndef MINGW
+  if (address->sa_family == AF_UNIX)
+    {
+      const struct sockaddr_un *un = (const struct sockaddr_un*) address;
+      (void) unlink (un->sun_path);
+    }
+#endif
+#endif
   ret = bind (desc->fd, address, address_len);
 #ifdef MINGW
   if (SOCKET_ERROR == ret)
     SetErrnoFromWinsockError (WSAGetLastError ());
-#else
+#endif
+  if (ret != 0)
+         return GNUNET_SYSERR;
+#ifndef MINGW
 #ifndef LINUX
-  if ( (ret == 0) && (address->sa_family == AF_UNIX))
-    {
-      const struct sockaddr_un *un = (const struct sockaddr_un*) address;
-      if (0 != unlink (un->sun_path))
-       GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
-                                 "unlink",
-                                 un->sun_path);
-    }
+  desc->addr = GNUNET_malloc (address_len);
+  memcpy (desc->addr, address, address_len);
+  desc->addrlen = address_len;
 #endif
 #endif
-  return ret == 0 ? GNUNET_OK : GNUNET_SYSERR;
+  return GNUNET_OK;
 }
 
 
@@ -315,6 +333,19 @@
 #else
   ret = close (desc->fd);
 #endif
+#ifndef LINUX
+#ifndef MINGW
+  if ( (desc->af == AF_UNIX) && (NULL != desc->addr) )
+    {
+      const struct sockaddr_un *un = (const struct sockaddr_un*) desc->addr;
+      if (0 != unlink (un->sun_path))
+         GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_WARNING,
+                                 "unlink",
+                                 un->sun_path);
+    }
+#endif
+#endif
+   GNUNET_free_non_null (desc->addr);
   GNUNET_free (desc);
   return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
 }




reply via email to

[Prev in Thread] Current Thread [Next in Thread]