diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-09-26 18:03:30 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-09-26 18:03:30 +0000 |
commit | 5f6f8c183270c3d6723342ea1ab6b40cc5fb7201 (patch) | |
tree | 01bc384a2a1918ef385c4e6f79b5e54f120b700d /src/util/network.c | |
parent | 4365da8f681ae3e45f311bad63c9f29415dab2ca (diff) | |
download | gnunet-5f6f8c183270c3d6723342ea1ab6b40cc5fb7201.tar.gz gnunet-5f6f8c183270c3d6723342ea1ab6b40cc5fb7201.zip |
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.
Diffstat (limited to 'src/util/network.c')
-rw-r--r-- | src/util/network.c | 40 |
1 files changed, 39 insertions, 1 deletions
diff --git a/src/util/network.c b/src/util/network.c index 0dbc0b094..c0b977368 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -393,6 +393,20 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
393 | int flags) | 393 | int flags) |
394 | { | 394 | { |
395 | int ret; | 395 | int ret; |
396 | socklen_t bind_address_len = address_len; | ||
397 | |||
398 | #ifdef LINUX | ||
399 | if (address->sa_family == AF_UNIX) | ||
400 | { | ||
401 | const struct sockaddr_un *address_un = (const struct sockaddr_un *)address; | ||
402 | if (address_un->sun_path[0] == '\0') | ||
403 | bind_address_len = \ | ||
404 | sizeof (struct sockaddr_un) \ | ||
405 | - sizeof (address_un->sun_path) \ | ||
406 | + strnlen (address_un->sun_path + 1, sizeof (address_un->sun_path) - 1) \ | ||
407 | + 1; | ||
408 | } | ||
409 | #endif | ||
396 | 410 | ||
397 | #ifdef IPV6_V6ONLY | 411 | #ifdef IPV6_V6ONLY |
398 | #ifdef IPPROTO_IPV6 | 412 | #ifdef IPPROTO_IPV6 |
@@ -427,7 +441,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
427 | } | 441 | } |
428 | #endif | 442 | #endif |
429 | #endif | 443 | #endif |
430 | ret = bind (desc->fd, address, address_len); | 444 | ret = bind (desc->fd, address, bind_address_len); |
431 | #ifdef MINGW | 445 | #ifdef MINGW |
432 | if (SOCKET_ERROR == ret) | 446 | if (SOCKET_ERROR == ret) |
433 | SetErrnoFromWinsockError (WSAGetLastError ()); | 447 | SetErrnoFromWinsockError (WSAGetLastError ()); |
@@ -544,6 +558,18 @@ GNUNET_NETWORK_socket_connect (const struct GNUNET_NETWORK_Handle *desc, | |||
544 | { | 558 | { |
545 | int ret; | 559 | int ret; |
546 | 560 | ||
561 | #ifdef LINUX | ||
562 | if (address->sa_family == AF_UNIX) | ||
563 | { | ||
564 | const struct sockaddr_un *address_un = (const struct sockaddr_un *)address; | ||
565 | if(address_un->sun_path[0] == '\0') | ||
566 | address_len = \ | ||
567 | sizeof (struct sockaddr_un) \ | ||
568 | - sizeof (address_un->sun_path) \ | ||
569 | + strnlen (address_un->sun_path + 1, sizeof (address_un->sun_path) - 1) \ | ||
570 | + 1; | ||
571 | } | ||
572 | #endif | ||
547 | ret = connect (desc->fd, address, address_len); | 573 | ret = connect (desc->fd, address, address_len); |
548 | 574 | ||
549 | #ifdef MINGW | 575 | #ifdef MINGW |
@@ -768,6 +794,18 @@ GNUNET_NETWORK_socket_sendto (const struct GNUNET_NETWORK_Handle * desc, | |||
768 | #ifdef MSG_NOSIGNAL | 794 | #ifdef MSG_NOSIGNAL |
769 | flags |= MSG_NOSIGNAL; | 795 | flags |= MSG_NOSIGNAL; |
770 | #endif | 796 | #endif |
797 | #ifdef LINUX | ||
798 | if (dest_addr->sa_family == AF_UNIX) | ||
799 | { | ||
800 | const struct sockaddr_un *dest_addr_un = (const struct sockaddr_un *)dest_addr; | ||
801 | if (dest_addr_un->sun_path[0] == '\0') | ||
802 | dest_len = \ | ||
803 | sizeof (struct sockaddr) \ | ||
804 | - sizeof (dest_addr_un->sun_path) \ | ||
805 | + strnlen (dest_addr_un->sun_path + 1, sizeof (dest_addr_un->sun_path) - 1) \ | ||
806 | + 1; | ||
807 | } | ||
808 | #endif | ||
771 | ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len); | 809 | ret = sendto (desc->fd, message, length, flags, dest_addr, dest_len); |
772 | #ifdef MINGW | 810 | #ifdef MINGW |
773 | if (SOCKET_ERROR == ret) | 811 | if (SOCKET_ERROR == ret) |