gnunet-svn
[Top][All Lists]
Advanced

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

[GNUnet-SVN] r30063 - in gnunet/src: arm dns gns include nat testing tra


From: gnunet
Subject: [GNUnet-SVN] r30063 - in gnunet/src: arm dns gns include nat testing transport util
Date: Wed, 9 Oct 2013 20:01:16 +0200

Author: grothoff
Date: 2013-10-09 20:01:16 +0200 (Wed, 09 Oct 2013)
New Revision: 30063

Modified:
   gnunet/src/arm/gnunet-service-arm.c
   gnunet/src/dns/dnsstub.c
   gnunet/src/gns/gnunet-dns2gns.c
   gnunet/src/include/gnunet_network_lib.h
   gnunet/src/nat/nat_test.c
   gnunet/src/testing/testing.c
   gnunet/src/transport/gnunet-helper-transport-bluetooth.c
   gnunet/src/transport/plugin_transport_udp.c
   gnunet/src/transport/plugin_transport_unix.c
   gnunet/src/util/client.c
   gnunet/src/util/configuration.c
   gnunet/src/util/connection.c
   gnunet/src/util/network.c
   gnunet/src/util/server.c
   gnunet/src/util/service.c
   gnunet/src/util/test_connection.c
   gnunet/src/util/test_connection_addressing.c
   gnunet/src/util/test_connection_receive_cancel.c
   gnunet/src/util/test_connection_timeout.c
   gnunet/src/util/test_server_with_client_unix.c
Log:
-switching (again) to named sockets, see #2887

Modified: gnunet/src/arm/gnunet-service-arm.c
===================================================================
--- gnunet/src/arm/gnunet-service-arm.c 2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/arm/gnunet-service-arm.c 2013-10-09 18:01:16 UTC (rev 30063)
@@ -622,8 +622,8 @@
                         "setsockopt");
 #endif
 
-  if (GNUNET_NETWORK_socket_bind
-      (sock, (const struct sockaddr *) sa, addr_len, 0) != GNUNET_OK)
+  if (GNUNET_OK !=
+      GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, 
addr_len))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
                  _

Modified: gnunet/src/dns/dnsstub.c
===================================================================
--- gnunet/src/dns/dnsstub.c    2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/dns/dnsstub.c    2013-10-09 18:01:16 UTC (rev 30063)
@@ -169,8 +169,7 @@
   sa->sa_family = af;
   if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret,
                                               sa,
-                                              alen,
-                                               0))
+                                              alen))
   {
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                _("Could not bind to any port: %s\n"),
@@ -446,7 +445,7 @@
     if ( (addrlen != rs->addrlen) ||
         (0 != memcmp (&rs->addr,
                       &addr,
-                      addrlen)) ||     
+                      addrlen)) ||
        (0 == GNUNET_TIME_absolute_get_remaining (rs->timeout).rel_value_us) )
     {
       GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,

Modified: gnunet/src/gns/gnunet-dns2gns.c
===================================================================
--- gnunet/src/gns/gnunet-dns2gns.c     2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/gns/gnunet-dns2gns.c     2013-10-09 18:01:16 UTC (rev 30063)
@@ -616,8 +616,7 @@
       if (GNUNET_OK !=
          GNUNET_NETWORK_socket_bind (listen_socket4,
                                      (struct sockaddr *) &v4,
-                                     sizeof (v4),
-                                      0))
+                                     sizeof (v4)))
        {
          GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
          GNUNET_NETWORK_socket_close (listen_socket4);
@@ -640,8 +639,7 @@
       if (GNUNET_OK !=
          GNUNET_NETWORK_socket_bind (listen_socket6,
                                      (struct sockaddr *) &v6,
-                                     sizeof (v6),
-                                      0))
+                                     sizeof (v6)))
        {
          GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
          GNUNET_NETWORK_socket_close (listen_socket6);

Modified: gnunet/src/include/gnunet_network_lib.h
===================================================================
--- gnunet/src/include/gnunet_network_lib.h     2013-10-09 17:37:19 UTC (rev 
30062)
+++ gnunet/src/include/gnunet_network_lib.h     2013-10-09 18:01:16 UTC (rev 
30063)
@@ -131,25 +131,17 @@
 
 
 /**
- * Fail to bind if an address is already in use.
- */
-#define GNUNET_BIND_EXCLUSIVE 0x01
-
-
-/**
  * Bind a socket to a particular address.
  *
  * @param desc socket to bind
  * @param address address to be bound
  * @param address_len length of address
- * @param flags flags affecting bind behaviour
  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  */
 int
 GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
                             const struct sockaddr *address,
-                            socklen_t address_len,
-                            int flags);
+                            socklen_t address_len);
 
 /**
  * Close a socket.

Modified: gnunet/src/nat/nat_test.c
===================================================================
--- gnunet/src/nat/nat_test.c   2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/nat/nat_test.c   2013-10-09 18:01:16 UTC (rev 30063)
@@ -404,7 +404,7 @@
     if ((ret->lsock == NULL) ||
         (GNUNET_OK !=
          GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa,
-                                     sizeof (sa), 0)))
+                                     sizeof (sa))))
     {
       GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
                   _

Modified: gnunet/src/testing/testing.c
===================================================================
--- gnunet/src/testing/testing.c        2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/testing/testing.c        2013-10-09 18:01:16 UTC (rev 30063)
@@ -627,8 +627,7 @@
           continue;
         bind_status = GNUNET_NETWORK_socket_bind (socket,
                                                   ai->ai_addr,
-                                                  ai->ai_addrlen,
-                                                  0);
+                                                  ai->ai_addrlen);
         GNUNET_NETWORK_socket_close (socket);
         if (GNUNET_OK != bind_status)
           break;
@@ -637,8 +636,7 @@
           continue;
         bind_status = GNUNET_NETWORK_socket_bind (socket,
                                                   ai->ai_addr,
-                                                  ai->ai_addrlen,
-                                                  0);
+                                                  ai->ai_addrlen);
         GNUNET_NETWORK_socket_close (socket);
         if (GNUNET_OK != bind_status)
           break;

Modified: gnunet/src/transport/gnunet-helper-transport-bluetooth.c
===================================================================
--- gnunet/src/transport/gnunet-helper-transport-bluetooth.c    2013-10-09 
17:37:19 UTC (rev 30062)
+++ gnunet/src/transport/gnunet-helper-transport-bluetooth.c    2013-10-09 
18:01:16 UTC (rev 30063)
@@ -1070,6 +1070,7 @@
   return count;
 }
 
+
 /**
  * Open the bluetooth interface for reading/writing
  *
@@ -1087,7 +1088,8 @@
     addr.btAddr = 0;
     addr.port = BT_PORT_ANY;
 
-    if (GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, 
sizeof (SOCKADDR_BTH), 0) != GNUNET_OK)
+    if (GNUNET_OK != 
+       GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, sizeof 
(SOCKADDR_BTH)))
     {
       fprintf (stderr, "Failed to bind the socket: ");
       if (GetLastError() == WSAENETDOWN)

Modified: gnunet/src/transport/plugin_transport_udp.c
===================================================================
--- gnunet/src/transport/plugin_transport_udp.c 2013-10-09 17:37:19 UTC (rev 
30062)
+++ gnunet/src/transport/plugin_transport_udp.c 2013-10-09 18:01:16 UTC (rev 
30063)
@@ -2798,7 +2798,7 @@
                                 GNUNET_a2s (serverAddr, addrlen));
                /* binding */
                if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6,
-                                                            serverAddr, 
addrlen, 0))
+                                                            serverAddr, 
addrlen))
                        break;
                eno = errno;
                if (0 != plugin->port)
@@ -2875,7 +2875,7 @@
 
       /* binding */
       if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4,
-                                                   serverAddr, addrlen, 0))
+                                                   serverAddr, addrlen))
                break;
       eno = errno;
       if (0 != plugin->port)

Modified: gnunet/src/transport/plugin_transport_unix.c
===================================================================
--- gnunet/src/transport/plugin_transport_unix.c        2013-10-09 17:37:19 UTC 
(rev 30062)
+++ gnunet/src/transport/plugin_transport_unix.c        2013-10-09 18:01:16 UTC 
(rev 30063)
@@ -348,6 +348,7 @@
 static void
 unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc);
 
+
 /**
  * Function called for a quick conversion of the binary address to
  * a numeric address.  Note that the caller must not free the
@@ -360,10 +361,47 @@
  * @return string representing the same address
  */
 static const char *
-unix_address_to_string (void *cls, const void *addr, size_t addrlen);
+unix_address_to_string (void *cls, const void *addr, size_t addrlen)
+{
+  static char rbuf[1024];
+  struct UnixAddress *ua = (struct UnixAddress *) addr;
+  char *addrstr;
+  size_t addr_str_len;
 
+  if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
+  addrstr = (char *) &ua[1];
+  addr_str_len = ntohl (ua->addrlen);
+
+  if (addr_str_len != addrlen - sizeof(struct UnixAddress))
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
+
+  if ('\0' != addrstr[addr_str_len - 1])
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
+  if (strlen (addrstr) + 1 != addr_str_len)
+  {
+    GNUNET_break(0);
+    return NULL ;
+  }
+
+  GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME,
+      ntohl (ua->options), addrstr);
+  return rbuf;
+}
+
+
 static struct sockaddr_un *
-unix_address_to_sockaddr (const char *unixpath , socklen_t *sock_len)
+unix_address_to_sockaddr (const char *unixpath,
+                          socklen_t *sock_len)
 {
   struct sockaddr_un *un;
   size_t slen;
@@ -380,14 +418,11 @@
 #if HAVE_SOCKADDR_IN_SIN_LEN
   un->sun_len = (u_char) slen;
 #endif
-#if LINUX
-  un->sun_path[0] = '\0';
-#endif
-
   (*sock_len) = slen;
   return un;
 }
 
+
 /**
  * Re-schedule the main 'select' callback (unix_plugin_select)
  * for this plugin.
@@ -426,7 +461,7 @@
 
 
 /**
- * Closure to 'lookup_session_it'.
+ * Closure to #lookup_session_it.
  */
 struct LookupCtx
 {
@@ -440,6 +475,9 @@
    */
   const struct UnixAddress *ua;
 
+  /**
+   * Number of bytes in @e ua
+   */
   size_t ua_len;
 };
 
@@ -450,7 +488,7 @@
  * @param cls the 'struct LookupCtx'
  * @param key peer we are looking for (unused)
  * @param value a session
- * @return GNUNET_YES if not found (continue looking), GNUNET_NO on success
+ * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
  */
 static int
 lookup_session_it (void *cls,
@@ -462,7 +500,7 @@
 
   if (t->addrlen != lctx->ua_len)
   {
-       GNUNET_break (0);
+    GNUNET_break (0);
     return GNUNET_YES;
   }
 
@@ -708,7 +746,7 @@
  * @param cls the 'struct LookupCtx'
  * @param key peer we are looking for (unused)
  * @param value a session
- * @return GNUNET_YES if not found (continue looking), GNUNET_NO on success
+ * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success
  */
 static int
 get_session_it (void *cls,
@@ -755,7 +793,7 @@
  *
  * @param cls closure ('struct Plugin*')
  * @param session the session
- * @return the network type in HBO or GNUNET_SYSERR
+ * @return the network type in HBO or #GNUNET_SYSERR
  */
 static enum GNUNET_ATS_Network_Type
 unix_get_network (void *cls,
@@ -952,7 +990,7 @@
  * @param sender from which peer the message was received
  * @param currhdr pointer to the header of the message
  * @param ua address to look for
- * @param ua_len length of the address
+ * @param ua_len length of the address @a ua
  */
 static void
 unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender,
@@ -1041,19 +1079,18 @@
   }
   else
   {
-#if LINUX
-    un.sun_path[0] = '/';
-#endif
-    LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret,
-                &un.sun_path[0]);
+    LOG (GNUNET_ERROR_TYPE_DEBUG,
+        "Read %d bytes from socket %s\n",
+        (int) ret,
+        un.sun_path);
   }
 
   GNUNET_assert (AF_UNIX == (un.sun_family));
-  ua_len = sizeof (struct UnixAddress) + strlen (&un.sun_path[0]) +1;
+  ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1;
   ua = GNUNET_malloc (ua_len);
   ua->addrlen = htonl (strlen (&un.sun_path[0]) +1);
   ua->options = htonl (0);
-  memcpy (&ua[1], &un.sun_path[0], strlen (&un.sun_path[0]) +1);
+  memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1);
 
   msg = (struct UNIXMessage *) buf;
   csize = ntohs (msg->header.size);
@@ -1232,7 +1269,7 @@
  * Create a slew of UNIX sockets.  If possible, use IPv6 and IPv4.
  *
  * @param cls closure for server start, should be a struct Plugin *
- * @return number of sockets created or GNUNET_SYSERR on error
+ * @return number of sockets created or #GNUNET_SYSERR on error
  */
 static int
 unix_transport_server_start (void *cls)
@@ -1250,8 +1287,8 @@
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
     return GNUNET_SYSERR;
   }
-  if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, (const struct 
sockaddr *)  un, un_len, 0)
-      != GNUNET_OK)
+  if (GNUNET_OK !=
+      GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, (const struct 
sockaddr *)  un, un_len))
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
     GNUNET_NETWORK_socket_close (plugin->unix_sock.desc);
@@ -1274,55 +1311,6 @@
 
 
 /**
- * Function called for a quick conversion of the binary address to
- * a numeric address.  Note that the caller must not free the
- * address and that the next call to this function is allowed
- * to override the address again.
- *
- * @param cls closure
- * @param addr binary address
- * @param addrlen length of the address
- * @return string representing the same address
- */
-static const char *
-unix_address_to_string (void *cls, const void *addr, size_t addrlen)
-{
-  static char rbuf[1024];
-  struct UnixAddress *ua = (struct UnixAddress *) addr;
-  char *addrstr;
-  size_t addr_str_len;
-
-  if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen))
-  {
-    GNUNET_break(0);
-    return NULL ;
-  }
-  addrstr = (char *) &ua[1];
-  addr_str_len = ntohl (ua->addrlen);
-
-  if (addr_str_len != addrlen - sizeof(struct UnixAddress))
-  {
-    GNUNET_break(0);
-    return NULL ;
-  }
-
-  if ('\0' != addrstr[addr_str_len - 1])
-  {
-    GNUNET_break(0);
-    return NULL ;
-  }
-  if (strlen (addrstr) + 1 != addr_str_len)
-  {
-    GNUNET_break(0);
-    return NULL ;
-  }
-
-  GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME,
-      ntohl (ua->options), addrstr);
-  return rbuf;
-}
-
-/**
  * Function that will be called to check if a binary address for this
  * plugin is well-formed and corresponds to an address for THIS peer
  * (as per our configuration).  Naturally, if absolutely necessary,
@@ -1425,7 +1413,7 @@
 unix_string_to_address (void *cls, const char *addr, uint16_t addrlen,
     void **buf, size_t *added)
 {
-       struct UnixAddress *ua;
+  struct UnixAddress *ua;
   char *address;
   char *plugin;
   char *optionstr;
@@ -1461,7 +1449,7 @@
     return GNUNET_SYSERR;
   }
   optionstr[0] = '\0';
-  optionstr ++;
+  optionstr++;
   options = atol (optionstr);
   address = strchr (optionstr, '.');
   if (NULL == address)
@@ -1471,7 +1459,7 @@
     return GNUNET_SYSERR;
   }
   address[0] = '\0';
-  address ++;
+  address++;
   if (0 != strcmp(plugin, PLUGIN_NAME))
   {
     GNUNET_break (0);

Modified: gnunet/src/util/client.c
===================================================================
--- gnunet/src/util/client.c    2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/util/client.c    2013-10-09 18:01:16 UTC (rev 30063)
@@ -829,11 +829,12 @@
   {
     /* probe UNIX support */
     struct sockaddr_un s_un;
-    size_t slen;
     char *unixpath;
 
     unixpath = NULL;
-    if ((GNUNET_OK == GNUNET_CONFIGURATION_get_value_string (cfg, service, 
"UNIXPATH", &unixpath)) && (0 < strlen (unixpath)))  /* We have a non-NULL 
unixpath, does that mean it's valid? */
+    if ((GNUNET_OK == 
+        GNUNET_CONFIGURATION_get_value_filename (cfg, service, "UNIXPATH", 
&unixpath)) && 
+       (0 < strlen (unixpath)))  /* We have a non-NULL unixpath, does that 
mean it's valid? */
     {
       if (strlen (unixpath) >= sizeof (s_un.sun_path))
       {
@@ -852,21 +853,13 @@
       {
        memset (&s_un, 0, sizeof (s_un));
        s_un.sun_family = AF_UNIX;
-       slen = strlen (unixpath) + 1;
-       if (slen >= sizeof (s_un.sun_path))
-         slen = sizeof (s_un.sun_path) - 1;
-       memcpy (s_un.sun_path, unixpath, slen);
-       s_un.sun_path[slen] = '\0';
-       slen = sizeof (struct sockaddr_un);
-#if LINUX
-       s_un.sun_path[0] = '\0';
-#endif
+        strncpy (s_un.sun_path, unixpath, sizeof (s_un.sun_path) - 1);
 #if HAVE_SOCKADDR_IN_SIN_LEN
-       s_un.sun_len = (u_char) slen;
+        s_un.sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif
        if (GNUNET_OK !=
            GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un,
-                                       slen, GNUNET_BIND_EXCLUSIVE))
+                                       sizeof (struct sockaddr_un)))
         {
          /* failed to bind => service must be running */
          GNUNET_free (unixpath);
@@ -916,7 +909,7 @@
     {
       if (GNUNET_OK !=
           GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in,
-                                      sizeof (s_in), GNUNET_BIND_EXCLUSIVE))
+                                      sizeof (s_in)))
       {
         /* failed to bind => service must be running */
         GNUNET_free (hostname);
@@ -949,7 +942,7 @@
     {
       if (GNUNET_OK !=
           GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6,
-                                      sizeof (s_in6), GNUNET_BIND_EXCLUSIVE))
+                                      sizeof (s_in6)))
       {
         /* failed to bind => service must be running */
         GNUNET_free (hostname);

Modified: gnunet/src/util/configuration.c
===================================================================
--- gnunet/src/util/configuration.c     2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/util/configuration.c     2013-10-09 18:01:16 UTC (rev 30063)
@@ -88,8 +88,8 @@
 
   /**
    * Modification indication since last save
-   * GNUNET_NO if clean, GNUNET_YES if dirty,
-   * GNUNET_SYSERR on error (i.e. last save failed)
+   * #GNUNET_NO if clean, #GNUNET_YES if dirty,
+   * #GNUNET_SYSERR on error (i.e. last save failed)
    */
   int dirty;
 
@@ -142,10 +142,10 @@
  * @param cfg configuration to update
  * @param mem the memory block of serialized configuration
  * @param size the size of the memory block
- * @param allow_inline set to GNUNET_YES if we recursively load configuration
- *          from inlined configurations; GNUNET_NO if not and raise warnings
+ * @param allow_inline set to #GNUNET_YES if we recursively load configuration
+ *          from inlined configurations; #GNUNET_NO if not and raise warnings
  *          when we come across them
- * @return GNUNET_OK on success, GNUNET_ERROR on error
+ * @return #GNUNET_OK on success, #GNUNET_ERROR on error
  */
 int
 GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg,

Modified: gnunet/src/util/connection.c
===================================================================
--- gnunet/src/util/connection.c        2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/util/connection.c        2013-10-09 18:01:16 UTC (rev 30063)
@@ -826,23 +826,14 @@
 #ifdef AF_UNIX
   struct GNUNET_CONNECTION_Handle *connection;
   struct sockaddr_un *un;
-  size_t slen;
 
   GNUNET_assert (0 < strlen (unixpath));        /* sanity check */
   un = GNUNET_new (struct sockaddr_un);
   un->sun_family = AF_UNIX;
-  slen = strlen (unixpath);
-  if (slen >= sizeof (un->sun_path))
-    slen = sizeof (un->sun_path) - 1;
-  memcpy (un->sun_path, unixpath, slen);
-  un->sun_path[slen] = '\0';
-  slen = sizeof (struct sockaddr_un);
+  strncpy(un->sun_path, unixpath, sizeof(un->sun_path) - 1);
 #if HAVE_SOCKADDR_IN_SIN_LEN
-  un->sun_len = (u_char) slen;
+  un->sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif
-#if LINUX
-  un->sun_path[0] = '\0';
-#endif
   connection = GNUNET_new (struct GNUNET_CONNECTION_Handle);
   connection->cfg = cfg;
   connection->write_buffer_size = GNUNET_SERVER_MIN_BUFFER_SIZE;
@@ -850,7 +841,7 @@
   connection->port = 0;
   connection->hostname = NULL;
   connection->addr = (struct sockaddr *) un;
-  connection->addrlen = slen;
+  connection->addrlen = sizeof (struct sockaddr_un);
   connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0);
   if (NULL == connection->sock)
   {

Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/util/network.c   2013-10-09 18:01:16 UTC (rev 30063)
@@ -87,7 +87,9 @@
   {
     if (EAFNOSUPPORT == errno)
       return GNUNET_NO;
-    fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno));
+    GNUNET_log (GNUNET_ERROR_TYPE_WARNING, 
+               "Failed to create test socket: %s\n", 
+               STRERROR (errno));
     return GNUNET_SYSERR;
   }
 #if WINDOWS
@@ -383,20 +385,18 @@
  * @param desc socket to bind
  * @param address address to be bound
  * @param address_len length of @a address
- * @param flags flags affecting bind behaviour
  * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise
  */
 int
 GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
                             const struct sockaddr *address,
-                            socklen_t address_len,
-                            int flags)
+                            socklen_t address_len)
 {
   int ret;
   socklen_t bind_address_len = address_len;
 
 #ifdef LINUX
-  if (address->sa_family == AF_UNIX)
+  if (AF_UNIX == address->sa_family)
   {
     const struct sockaddr_un *address_un = (const struct sockaddr_un *)address;
     if (address_un->sun_path[0] == '\0')
@@ -431,16 +431,6 @@
       LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt");
   }
 #endif
-#ifndef LINUX
-#ifndef MINGW
-  if (address->sa_family == AF_UNIX && (flags & GNUNET_BIND_EXCLUSIVE) == 0)
-  {
-    const struct sockaddr_un *un = (const struct sockaddr_un *) address;
-
-    (void) unlink (un->sun_path);
-  }
-#endif
-#endif
   ret = bind (desc->fd, address, bind_address_len);
 #ifdef MINGW
   if (SOCKET_ERROR == ret)
@@ -449,12 +439,10 @@
   if (ret != 0)
     return GNUNET_SYSERR;
 #ifndef MINGW
-#ifndef LINUX
   desc->addr = GNUNET_malloc (address_len);
   memcpy (desc->addr, address, address_len);
   desc->addrlen = address_len;
 #endif
-#endif
   return GNUNET_OK;
 }
 
@@ -483,17 +471,17 @@
 #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))
-      LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path);
+      LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, 
+                        "unlink", 
+                        un->sun_path);
   }
 #endif
-#endif
   GNUNET_NETWORK_socket_free_memory_only_ (desc);
   return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR;
 }

Modified: gnunet/src/util/server.c
===================================================================
--- gnunet/src/util/server.c    2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/util/server.c    2013-10-09 18:01:16 UTC (rev 30063)
@@ -468,7 +468,7 @@
     return NULL;
   }
   /* bind the socket */
-  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen, 0))
+  if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen))
   {
     eno = errno;
     if (EADDRINUSE != errno)

Modified: gnunet/src/util/service.c
===================================================================
--- gnunet/src/util/service.c   2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/util/service.c   2013-10-09 18:01:16 UTC (rev 30063)
@@ -834,24 +834,15 @@
 {
 #ifdef AF_UNIX
   struct sockaddr_un *un;
-  size_t slen;
 
   un = GNUNET_malloc (sizeof (struct sockaddr_un));
   un->sun_family = AF_UNIX;
-  slen = strlen (unixpath) + 1;
-  if (slen >= sizeof (un->sun_path))
-    slen = sizeof (un->sun_path) - 1;
-  memcpy (un->sun_path, unixpath, slen);
-  un->sun_path[slen] = '\0';
-  slen = sizeof (struct sockaddr_un);
-#if LINUX
-  un->sun_path[0] = '\0';
-#endif
+  strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1);
 #if HAVE_SOCKADDR_IN_SIN_LEN
-  un->sun_len = (u_char) slen;
+  un->sun_len = (u_char) sizeof (struct sockaddr_un);
 #endif
   *saddrs = (struct sockaddr *) un;
-  *saddrlens = slen;
+  *saddrlens = sizeof (struct sockaddr_un);
 #else
   /* this function should never be called
    * unless AF_UNIX is defined! */
@@ -989,6 +980,11 @@
       LOG (GNUNET_ERROR_TYPE_INFO,
           _("Using `%s' instead\n"), unixpath);
     }
+    if (GNUNET_OK !=
+       GNUNET_DISK_directory_create_for_file (unixpath))
+      GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR,
+                               "mkdir",
+                               unixpath);
   }
   if (NULL != unixpath)
   {

Modified: gnunet/src/util/test_connection.c
===================================================================
--- gnunet/src/util/test_connection.c   2013-10-09 17:37:19 UTC (rev 30062)
+++ gnunet/src/util/test_connection.c   2013-10-09 18:01:16 UTC (rev 30063)
@@ -62,9 +62,9 @@
   if (GNUNET_NETWORK_socket_setsockopt
       (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 
"setsockopt");
-  GNUNET_assert (GNUNET_NETWORK_socket_bind
-                 (desc, (const struct sockaddr *) &sa,
-                  sizeof (sa), 0) == GNUNET_OK);
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) 
&sa,
+                                            sizeof (sa)));
   GNUNET_NETWORK_socket_listen (desc, 5);
   return desc;
 }

Modified: gnunet/src/util/test_connection_addressing.c
===================================================================
--- gnunet/src/util/test_connection_addressing.c        2013-10-09 17:37:19 UTC 
(rev 30062)
+++ gnunet/src/util/test_connection_addressing.c        2013-10-09 18:01:16 UTC 
(rev 30063)
@@ -65,7 +65,7 @@
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 
"setsockopt");
   if (GNUNET_OK !=
       GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa,
-                                  sizeof (sa), 0))
+                                  sizeof (sa)))
   {
     GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
                          "bind");

Modified: gnunet/src/util/test_connection_receive_cancel.c
===================================================================
--- gnunet/src/util/test_connection_receive_cancel.c    2013-10-09 17:37:19 UTC 
(rev 30062)
+++ gnunet/src/util/test_connection_receive_cancel.c    2013-10-09 18:01:16 UTC 
(rev 30063)
@@ -61,9 +61,9 @@
   if (GNUNET_NETWORK_socket_setsockopt
       (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 
"setsockopt");
-  GNUNET_assert (GNUNET_NETWORK_socket_bind
-                 (desc, (const struct sockaddr *) &sa,
-                  sizeof (sa), 0) == GNUNET_OK);
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) 
&sa,
+                                            sizeof (sa)));
   GNUNET_NETWORK_socket_listen (desc, 5);
   return desc;
 }

Modified: gnunet/src/util/test_connection_timeout.c
===================================================================
--- gnunet/src/util/test_connection_timeout.c   2013-10-09 17:37:19 UTC (rev 
30062)
+++ gnunet/src/util/test_connection_timeout.c   2013-10-09 18:01:16 UTC (rev 
30063)
@@ -58,9 +58,9 @@
   if (GNUNET_NETWORK_socket_setsockopt
       (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK)
     GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, 
"setsockopt");
-  GNUNET_assert (GNUNET_NETWORK_socket_bind
-                 (desc, (const struct sockaddr *) &sa,
-                  sizeof (sa), 0) == GNUNET_OK);
+  GNUNET_assert (GNUNET_OK ==
+                GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) 
&sa,
+                                            sizeof (sa)));
   GNUNET_NETWORK_socket_listen (desc, 5);
   return desc;
 }

Modified: gnunet/src/util/test_server_with_client_unix.c
===================================================================
--- gnunet/src/util/test_server_with_client_unix.c      2013-10-09 17:37:19 UTC 
(rev 30062)
+++ gnunet/src/util/test_server_with_client_unix.c      2013-10-09 18:01:16 UTC 
(rev 30063)
@@ -130,20 +130,15 @@
 {
   struct sockaddr_un un;
   const char *unixpath = "/tmp/testsock";
-  size_t slen = strlen (unixpath);
   struct sockaddr *sap[2];
   socklen_t slens[2];
 
   memset (&un, 0, sizeof (un));
   un.sun_family = AF_UNIX;
-  memcpy (un.sun_path, unixpath, slen);
-  un.sun_path[slen] = '\0';
+  strncpy(un.sun_path, unixpath, sizeof (un.sun_path) - 1);
 #if HAVE_SOCKADDR_IN_SIN_LEN
   un.sun_len = (u_char) sizeof (un);
 #endif
-#if LINUX
-  un.sun_path[0] = '\0';
-#endif
 
   sap[0] = (struct sockaddr *) &un;
   slens[0] = sizeof (un);




reply via email to

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