gnunet-svn
[Top][All Lists]
Advanced

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

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


From: gnunet
Subject: [GNUnet-SVN] r29635 - gnunet/src/util
Date: Thu, 26 Sep 2013 20:03:30 +0200

Author: grothoff
Date: 2013-09-26 20:03:30 +0200 (Thu, 26 Sep 2013)
New Revision: 29635

Modified:
   gnunet/src/util/network.c
Log:
Applying 1st patch from Andrew Cann (see also #2887).


https://canndrew.org/misc/trim_abstract_socket_paths.diff [^]

This changes the addrlen argument passed to the connect, bind and sendto
syscalls to reflect the length of the string in sockaddr_un.sun_path. I
was trying to talk to GNUnet services using socat and discovered that it
expects abstract sockets to be created this way and won't connect
otherwise. Looking at some other programs that I could talk to using
socat (dbus, X11), this is how they create abstract sockets as well.


Modified: gnunet/src/util/network.c
===================================================================
--- gnunet/src/util/network.c   2013-09-26 17:20:17 UTC (rev 29634)
+++ gnunet/src/util/network.c   2013-09-26 18:03:30 UTC (rev 29635)
@@ -393,7 +393,21 @@
                             int flags)
 {
   int ret;
+  socklen_t bind_address_len = address_len;
 
+#ifdef LINUX
+  if (address->sa_family == AF_UNIX)
+  {
+    const struct sockaddr_un *address_un = (const struct sockaddr_un *)address;
+    if (address_un->sun_path[0] == '\0')
+      bind_address_len = \
+          sizeof (struct sockaddr_un) \
+        - sizeof (address_un->sun_path) \
+        + strnlen (address_un->sun_path + 1, sizeof (address_un->sun_path) - 
1) \
+        + 1;
+  }
+#endif
+
 #ifdef IPV6_V6ONLY
 #ifdef IPPROTO_IPV6
   {
@@ -427,7 +441,7 @@
   }
 #endif
 #endif
-  ret = bind (desc->fd, address, address_len);
+  ret = bind (desc->fd, address, bind_address_len);
 #ifdef MINGW
   if (SOCKET_ERROR == ret)
     SetErrnoFromWinsockError (WSAGetLastError ());
@@ -544,6 +558,18 @@
 {
   int ret;
 
+#ifdef LINUX
+  if (address->sa_family == AF_UNIX)
+  {
+    const struct sockaddr_un *address_un = (const struct sockaddr_un *)address;
+    if(address_un->sun_path[0] == '\0')
+      address_len = \
+          sizeof (struct sockaddr_un) \
+        - sizeof (address_un->sun_path) \
+        + strnlen (address_un->sun_path + 1, sizeof (address_un->sun_path) - 
1) \
+        + 1;
+  }
+#endif
   ret = connect (desc->fd, address, address_len);
 
 #ifdef MINGW
@@ -768,6 +794,18 @@
 #ifdef MSG_NOSIGNAL
   flags |= MSG_NOSIGNAL;
 #endif
+#ifdef LINUX
+  if (dest_addr->sa_family == AF_UNIX)
+  {
+    const struct sockaddr_un *dest_addr_un = (const struct sockaddr_un 
*)dest_addr;
+    if (dest_addr_un->sun_path[0] == '\0')
+      dest_len = \
+          sizeof (struct sockaddr) \
+        - sizeof (dest_addr_un->sun_path) \
+        + strnlen (dest_addr_un->sun_path + 1, sizeof (dest_addr_un->sun_path) 
- 1) \
+        + 1;
+  }
+#endif
   ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len);
 #ifdef MINGW
   if (SOCKET_ERROR == ret)




reply via email to

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