diff options
author | Christian Grothoff <christian@grothoff.org> | 2013-10-09 18:01:16 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2013-10-09 18:01:16 +0000 |
commit | 25e37143ca6ddc3ea7d3c2e3fd7c66002a45e060 (patch) | |
tree | 8796fd0e148c6914897d6c53d25c6327b5a8263b | |
parent | 0904af031c4f1411419b3047f893e0672957d146 (diff) | |
download | gnunet-25e37143ca6ddc3ea7d3c2e3fd7c66002a45e060.tar.gz gnunet-25e37143ca6ddc3ea7d3c2e3fd7c66002a45e060.zip |
-switching (again) to named sockets, see #2887
-rw-r--r-- | src/arm/gnunet-service-arm.c | 4 | ||||
-rw-r--r-- | src/dns/dnsstub.c | 5 | ||||
-rw-r--r-- | src/gns/gnunet-dns2gns.c | 6 | ||||
-rw-r--r-- | src/include/gnunet_network_lib.h | 10 | ||||
-rw-r--r-- | src/nat/nat_test.c | 2 | ||||
-rw-r--r-- | src/testing/testing.c | 6 | ||||
-rw-r--r-- | src/transport/gnunet-helper-transport-bluetooth.c | 4 | ||||
-rw-r--r-- | src/transport/plugin_transport_udp.c | 4 | ||||
-rw-r--r-- | src/transport/plugin_transport_unix.c | 136 | ||||
-rw-r--r-- | src/util/client.c | 23 | ||||
-rw-r--r-- | src/util/configuration.c | 10 | ||||
-rw-r--r-- | src/util/connection.c | 15 | ||||
-rw-r--r-- | src/util/network.c | 28 | ||||
-rw-r--r-- | src/util/server.c | 2 | ||||
-rw-r--r-- | src/util/service.c | 20 | ||||
-rw-r--r-- | src/util/test_connection.c | 6 | ||||
-rw-r--r-- | src/util/test_connection_addressing.c | 2 | ||||
-rw-r--r-- | src/util/test_connection_receive_cancel.c | 6 | ||||
-rw-r--r-- | src/util/test_connection_timeout.c | 6 | ||||
-rw-r--r-- | src/util/test_server_with_client_unix.c | 7 |
20 files changed, 121 insertions, 181 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c index 1196b20aa..942534b08 100644 --- a/src/arm/gnunet-service-arm.c +++ b/src/arm/gnunet-service-arm.c | |||
@@ -622,8 +622,8 @@ create_listen_socket (struct sockaddr *sa, socklen_t addr_len, | |||
622 | "setsockopt"); | 622 | "setsockopt"); |
623 | #endif | 623 | #endif |
624 | 624 | ||
625 | if (GNUNET_NETWORK_socket_bind | 625 | if (GNUNET_OK != |
626 | (sock, (const struct sockaddr *) sa, addr_len, 0) != GNUNET_OK) | 626 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) sa, addr_len)) |
627 | { | 627 | { |
628 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, | 628 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
629 | _ | 629 | _ |
diff --git a/src/dns/dnsstub.c b/src/dns/dnsstub.c index bd85bf896..e494d24a2 100644 --- a/src/dns/dnsstub.c +++ b/src/dns/dnsstub.c | |||
@@ -169,8 +169,7 @@ open_socket (int af) | |||
169 | sa->sa_family = af; | 169 | sa->sa_family = af; |
170 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, | 170 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret, |
171 | sa, | 171 | sa, |
172 | alen, | 172 | alen)) |
173 | 0)) | ||
174 | { | 173 | { |
175 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 174 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
176 | _("Could not bind to any port: %s\n"), | 175 | _("Could not bind to any port: %s\n"), |
@@ -446,7 +445,7 @@ do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs, | |||
446 | if ( (addrlen != rs->addrlen) || | 445 | if ( (addrlen != rs->addrlen) || |
447 | (0 != memcmp (&rs->addr, | 446 | (0 != memcmp (&rs->addr, |
448 | &addr, | 447 | &addr, |
449 | addrlen)) || | 448 | addrlen)) || |
450 | (0 == GNUNET_TIME_absolute_get_remaining (rs->timeout).rel_value_us) ) | 449 | (0 == GNUNET_TIME_absolute_get_remaining (rs->timeout).rel_value_us) ) |
451 | { | 450 | { |
452 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, | 451 | GNUNET_log (GNUNET_ERROR_TYPE_DEBUG, |
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c index 4dcec6bdc..42d5ef0e2 100644 --- a/src/gns/gnunet-dns2gns.c +++ b/src/gns/gnunet-dns2gns.c | |||
@@ -616,8 +616,7 @@ run_dnsd () | |||
616 | if (GNUNET_OK != | 616 | if (GNUNET_OK != |
617 | GNUNET_NETWORK_socket_bind (listen_socket4, | 617 | GNUNET_NETWORK_socket_bind (listen_socket4, |
618 | (struct sockaddr *) &v4, | 618 | (struct sockaddr *) &v4, |
619 | sizeof (v4), | 619 | sizeof (v4))) |
620 | 0)) | ||
621 | { | 620 | { |
622 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 621 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
623 | GNUNET_NETWORK_socket_close (listen_socket4); | 622 | GNUNET_NETWORK_socket_close (listen_socket4); |
@@ -640,8 +639,7 @@ run_dnsd () | |||
640 | if (GNUNET_OK != | 639 | if (GNUNET_OK != |
641 | GNUNET_NETWORK_socket_bind (listen_socket6, | 640 | GNUNET_NETWORK_socket_bind (listen_socket6, |
642 | (struct sockaddr *) &v6, | 641 | (struct sockaddr *) &v6, |
643 | sizeof (v6), | 642 | sizeof (v6))) |
644 | 0)) | ||
645 | { | 643 | { |
646 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 644 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
647 | GNUNET_NETWORK_socket_close (listen_socket6); | 645 | GNUNET_NETWORK_socket_close (listen_socket6); |
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h index d24019f1a..042ab235e 100644 --- a/src/include/gnunet_network_lib.h +++ b/src/include/gnunet_network_lib.h | |||
@@ -131,25 +131,17 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd, | |||
131 | 131 | ||
132 | 132 | ||
133 | /** | 133 | /** |
134 | * Fail to bind if an address is already in use. | ||
135 | */ | ||
136 | #define GNUNET_BIND_EXCLUSIVE 0x01 | ||
137 | |||
138 | |||
139 | /** | ||
140 | * Bind a socket to a particular address. | 134 | * Bind a socket to a particular address. |
141 | * | 135 | * |
142 | * @param desc socket to bind | 136 | * @param desc socket to bind |
143 | * @param address address to be bound | 137 | * @param address address to be bound |
144 | * @param address_len length of address | 138 | * @param address_len length of address |
145 | * @param flags flags affecting bind behaviour | ||
146 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 139 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
147 | */ | 140 | */ |
148 | int | 141 | int |
149 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 142 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
150 | const struct sockaddr *address, | 143 | const struct sockaddr *address, |
151 | socklen_t address_len, | 144 | socklen_t address_len); |
152 | int flags); | ||
153 | 145 | ||
154 | /** | 146 | /** |
155 | * Close a socket. | 147 | * Close a socket. |
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c index 0c1d59a87..387a68d8f 100644 --- a/src/nat/nat_test.c +++ b/src/nat/nat_test.c | |||
@@ -404,7 +404,7 @@ GNUNET_NAT_test_start (const struct GNUNET_CONFIGURATION_Handle *cfg, | |||
404 | if ((ret->lsock == NULL) || | 404 | if ((ret->lsock == NULL) || |
405 | (GNUNET_OK != | 405 | (GNUNET_OK != |
406 | GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa, | 406 | GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa, |
407 | sizeof (sa), 0))) | 407 | sizeof (sa)))) |
408 | { | 408 | { |
409 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, | 409 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR, |
410 | _ | 410 | _ |
diff --git a/src/testing/testing.c b/src/testing/testing.c index a0d8e261b..4e60ae0f7 100644 --- a/src/testing/testing.c +++ b/src/testing/testing.c | |||
@@ -627,8 +627,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) | |||
627 | continue; | 627 | continue; |
628 | bind_status = GNUNET_NETWORK_socket_bind (socket, | 628 | bind_status = GNUNET_NETWORK_socket_bind (socket, |
629 | ai->ai_addr, | 629 | ai->ai_addr, |
630 | ai->ai_addrlen, | 630 | ai->ai_addrlen); |
631 | 0); | ||
632 | GNUNET_NETWORK_socket_close (socket); | 631 | GNUNET_NETWORK_socket_close (socket); |
633 | if (GNUNET_OK != bind_status) | 632 | if (GNUNET_OK != bind_status) |
634 | break; | 633 | break; |
@@ -637,8 +636,7 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system) | |||
637 | continue; | 636 | continue; |
638 | bind_status = GNUNET_NETWORK_socket_bind (socket, | 637 | bind_status = GNUNET_NETWORK_socket_bind (socket, |
639 | ai->ai_addr, | 638 | ai->ai_addr, |
640 | ai->ai_addrlen, | 639 | ai->ai_addrlen); |
641 | 0); | ||
642 | GNUNET_NETWORK_socket_close (socket); | 640 | GNUNET_NETWORK_socket_close (socket); |
643 | if (GNUNET_OK != bind_status) | 641 | if (GNUNET_OK != bind_status) |
644 | break; | 642 | break; |
diff --git a/src/transport/gnunet-helper-transport-bluetooth.c b/src/transport/gnunet-helper-transport-bluetooth.c index 343aacd19..9d5318663 100644 --- a/src/transport/gnunet-helper-transport-bluetooth.c +++ b/src/transport/gnunet-helper-transport-bluetooth.c | |||
@@ -1070,6 +1070,7 @@ read_from_the_socket (void *sock, | |||
1070 | return count; | 1070 | return count; |
1071 | } | 1071 | } |
1072 | 1072 | ||
1073 | |||
1073 | /** | 1074 | /** |
1074 | * Open the bluetooth interface for reading/writing | 1075 | * Open the bluetooth interface for reading/writing |
1075 | * | 1076 | * |
@@ -1087,7 +1088,8 @@ open_device (struct HardwareInfos *dev) | |||
1087 | addr.btAddr = 0; | 1088 | addr.btAddr = 0; |
1088 | addr.port = BT_PORT_ANY; | 1089 | addr.port = BT_PORT_ANY; |
1089 | 1090 | ||
1090 | if (GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, sizeof (SOCKADDR_BTH), 0) != GNUNET_OK) | 1091 | if (GNUNET_OK != |
1092 | GNUNET_NETWORK_socket_bind (dev->handle, (const SOCKADDR*)&addr, sizeof (SOCKADDR_BTH))) | ||
1091 | { | 1093 | { |
1092 | fprintf (stderr, "Failed to bind the socket: "); | 1094 | fprintf (stderr, "Failed to bind the socket: "); |
1093 | if (GetLastError() == WSAENETDOWN) | 1095 | if (GetLastError() == WSAENETDOWN) |
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c index 043633ab1..317454e83 100644 --- a/src/transport/plugin_transport_udp.c +++ b/src/transport/plugin_transport_udp.c | |||
@@ -2798,7 +2798,7 @@ setup_sockets (struct Plugin *plugin, | |||
2798 | GNUNET_a2s (serverAddr, addrlen)); | 2798 | GNUNET_a2s (serverAddr, addrlen)); |
2799 | /* binding */ | 2799 | /* binding */ |
2800 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6, | 2800 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6, |
2801 | serverAddr, addrlen, 0)) | 2801 | serverAddr, addrlen)) |
2802 | break; | 2802 | break; |
2803 | eno = errno; | 2803 | eno = errno; |
2804 | if (0 != plugin->port) | 2804 | if (0 != plugin->port) |
@@ -2875,7 +2875,7 @@ setup_sockets (struct Plugin *plugin, | |||
2875 | 2875 | ||
2876 | /* binding */ | 2876 | /* binding */ |
2877 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4, | 2877 | if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4, |
2878 | serverAddr, addrlen, 0)) | 2878 | serverAddr, addrlen)) |
2879 | break; | 2879 | break; |
2880 | eno = errno; | 2880 | eno = errno; |
2881 | if (0 != plugin->port) | 2881 | if (0 != plugin->port) |
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c index e80102a33..e78445a0a 100644 --- a/src/transport/plugin_transport_unix.c +++ b/src/transport/plugin_transport_unix.c | |||
@@ -348,6 +348,7 @@ reschedule_session_timeout (struct Session *s); | |||
348 | static void | 348 | static void |
349 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | 349 | unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); |
350 | 350 | ||
351 | |||
351 | /** | 352 | /** |
352 | * Function called for a quick conversion of the binary address to | 353 | * Function called for a quick conversion of the binary address to |
353 | * a numeric address. Note that the caller must not free the | 354 | * a numeric address. Note that the caller must not free the |
@@ -360,10 +361,47 @@ unix_plugin_select (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc); | |||
360 | * @return string representing the same address | 361 | * @return string representing the same address |
361 | */ | 362 | */ |
362 | static const char * | 363 | static const char * |
363 | unix_address_to_string (void *cls, const void *addr, size_t addrlen); | 364 | unix_address_to_string (void *cls, const void *addr, size_t addrlen) |
365 | { | ||
366 | static char rbuf[1024]; | ||
367 | struct UnixAddress *ua = (struct UnixAddress *) addr; | ||
368 | char *addrstr; | ||
369 | size_t addr_str_len; | ||
370 | |||
371 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) | ||
372 | { | ||
373 | GNUNET_break(0); | ||
374 | return NULL ; | ||
375 | } | ||
376 | addrstr = (char *) &ua[1]; | ||
377 | addr_str_len = ntohl (ua->addrlen); | ||
378 | |||
379 | if (addr_str_len != addrlen - sizeof(struct UnixAddress)) | ||
380 | { | ||
381 | GNUNET_break(0); | ||
382 | return NULL ; | ||
383 | } | ||
384 | |||
385 | if ('\0' != addrstr[addr_str_len - 1]) | ||
386 | { | ||
387 | GNUNET_break(0); | ||
388 | return NULL ; | ||
389 | } | ||
390 | if (strlen (addrstr) + 1 != addr_str_len) | ||
391 | { | ||
392 | GNUNET_break(0); | ||
393 | return NULL ; | ||
394 | } | ||
395 | |||
396 | GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME, | ||
397 | ntohl (ua->options), addrstr); | ||
398 | return rbuf; | ||
399 | } | ||
400 | |||
364 | 401 | ||
365 | static struct sockaddr_un * | 402 | static struct sockaddr_un * |
366 | unix_address_to_sockaddr (const char *unixpath , socklen_t *sock_len) | 403 | unix_address_to_sockaddr (const char *unixpath, |
404 | socklen_t *sock_len) | ||
367 | { | 405 | { |
368 | struct sockaddr_un *un; | 406 | struct sockaddr_un *un; |
369 | size_t slen; | 407 | size_t slen; |
@@ -380,14 +418,11 @@ unix_address_to_sockaddr (const char *unixpath , socklen_t *sock_len) | |||
380 | #if HAVE_SOCKADDR_IN_SIN_LEN | 418 | #if HAVE_SOCKADDR_IN_SIN_LEN |
381 | un->sun_len = (u_char) slen; | 419 | un->sun_len = (u_char) slen; |
382 | #endif | 420 | #endif |
383 | #if LINUX | ||
384 | un->sun_path[0] = '\0'; | ||
385 | #endif | ||
386 | |||
387 | (*sock_len) = slen; | 421 | (*sock_len) = slen; |
388 | return un; | 422 | return un; |
389 | } | 423 | } |
390 | 424 | ||
425 | |||
391 | /** | 426 | /** |
392 | * Re-schedule the main 'select' callback (unix_plugin_select) | 427 | * Re-schedule the main 'select' callback (unix_plugin_select) |
393 | * for this plugin. | 428 | * for this plugin. |
@@ -426,7 +461,7 @@ reschedule_select (struct Plugin * plugin) | |||
426 | 461 | ||
427 | 462 | ||
428 | /** | 463 | /** |
429 | * Closure to 'lookup_session_it'. | 464 | * Closure to #lookup_session_it. |
430 | */ | 465 | */ |
431 | struct LookupCtx | 466 | struct LookupCtx |
432 | { | 467 | { |
@@ -440,6 +475,9 @@ struct LookupCtx | |||
440 | */ | 475 | */ |
441 | const struct UnixAddress *ua; | 476 | const struct UnixAddress *ua; |
442 | 477 | ||
478 | /** | ||
479 | * Number of bytes in @e ua | ||
480 | */ | ||
443 | size_t ua_len; | 481 | size_t ua_len; |
444 | }; | 482 | }; |
445 | 483 | ||
@@ -450,7 +488,7 @@ struct LookupCtx | |||
450 | * @param cls the 'struct LookupCtx' | 488 | * @param cls the 'struct LookupCtx' |
451 | * @param key peer we are looking for (unused) | 489 | * @param key peer we are looking for (unused) |
452 | * @param value a session | 490 | * @param value a session |
453 | * @return GNUNET_YES if not found (continue looking), GNUNET_NO on success | 491 | * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success |
454 | */ | 492 | */ |
455 | static int | 493 | static int |
456 | lookup_session_it (void *cls, | 494 | lookup_session_it (void *cls, |
@@ -462,7 +500,7 @@ lookup_session_it (void *cls, | |||
462 | 500 | ||
463 | if (t->addrlen != lctx->ua_len) | 501 | if (t->addrlen != lctx->ua_len) |
464 | { | 502 | { |
465 | GNUNET_break (0); | 503 | GNUNET_break (0); |
466 | return GNUNET_YES; | 504 | return GNUNET_YES; |
467 | } | 505 | } |
468 | 506 | ||
@@ -708,7 +746,7 @@ struct GetSessionIteratorContext | |||
708 | * @param cls the 'struct LookupCtx' | 746 | * @param cls the 'struct LookupCtx' |
709 | * @param key peer we are looking for (unused) | 747 | * @param key peer we are looking for (unused) |
710 | * @param value a session | 748 | * @param value a session |
711 | * @return GNUNET_YES if not found (continue looking), GNUNET_NO on success | 749 | * @return #GNUNET_YES if not found (continue looking), #GNUNET_NO on success |
712 | */ | 750 | */ |
713 | static int | 751 | static int |
714 | get_session_it (void *cls, | 752 | get_session_it (void *cls, |
@@ -755,7 +793,7 @@ session_timeout (void *cls, | |||
755 | * | 793 | * |
756 | * @param cls closure ('struct Plugin*') | 794 | * @param cls closure ('struct Plugin*') |
757 | * @param session the session | 795 | * @param session the session |
758 | * @return the network type in HBO or GNUNET_SYSERR | 796 | * @return the network type in HBO or #GNUNET_SYSERR |
759 | */ | 797 | */ |
760 | static enum GNUNET_ATS_Network_Type | 798 | static enum GNUNET_ATS_Network_Type |
761 | unix_get_network (void *cls, | 799 | unix_get_network (void *cls, |
@@ -952,7 +990,7 @@ unix_plugin_send (void *cls, | |||
952 | * @param sender from which peer the message was received | 990 | * @param sender from which peer the message was received |
953 | * @param currhdr pointer to the header of the message | 991 | * @param currhdr pointer to the header of the message |
954 | * @param ua address to look for | 992 | * @param ua address to look for |
955 | * @param ua_len length of the address | 993 | * @param ua_len length of the address @a ua |
956 | */ | 994 | */ |
957 | static void | 995 | static void |
958 | unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, | 996 | unix_demultiplexer (struct Plugin *plugin, struct GNUNET_PeerIdentity *sender, |
@@ -1041,19 +1079,18 @@ unix_plugin_select_read (struct Plugin *plugin) | |||
1041 | } | 1079 | } |
1042 | else | 1080 | else |
1043 | { | 1081 | { |
1044 | #if LINUX | 1082 | LOG (GNUNET_ERROR_TYPE_DEBUG, |
1045 | un.sun_path[0] = '/'; | 1083 | "Read %d bytes from socket %s\n", |
1046 | #endif | 1084 | (int) ret, |
1047 | LOG (GNUNET_ERROR_TYPE_DEBUG, "Read %d bytes from socket %s\n", ret, | 1085 | un.sun_path); |
1048 | &un.sun_path[0]); | ||
1049 | } | 1086 | } |
1050 | 1087 | ||
1051 | GNUNET_assert (AF_UNIX == (un.sun_family)); | 1088 | GNUNET_assert (AF_UNIX == (un.sun_family)); |
1052 | ua_len = sizeof (struct UnixAddress) + strlen (&un.sun_path[0]) +1; | 1089 | ua_len = sizeof (struct UnixAddress) + strlen (un.sun_path) + 1; |
1053 | ua = GNUNET_malloc (ua_len); | 1090 | ua = GNUNET_malloc (ua_len); |
1054 | ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); | 1091 | ua->addrlen = htonl (strlen (&un.sun_path[0]) +1); |
1055 | ua->options = htonl (0); | 1092 | ua->options = htonl (0); |
1056 | memcpy (&ua[1], &un.sun_path[0], strlen (&un.sun_path[0]) +1); | 1093 | memcpy (&ua[1], &un.sun_path[0], strlen (un.sun_path) + 1); |
1057 | 1094 | ||
1058 | msg = (struct UNIXMessage *) buf; | 1095 | msg = (struct UNIXMessage *) buf; |
1059 | csize = ntohs (msg->header.size); | 1096 | csize = ntohs (msg->header.size); |
@@ -1232,7 +1269,7 @@ unix_plugin_select (void *cls, | |||
1232 | * Create a slew of UNIX sockets. If possible, use IPv6 and IPv4. | 1269 | * Create a slew of UNIX sockets. If possible, use IPv6 and IPv4. |
1233 | * | 1270 | * |
1234 | * @param cls closure for server start, should be a struct Plugin * | 1271 | * @param cls closure for server start, should be a struct Plugin * |
1235 | * @return number of sockets created or GNUNET_SYSERR on error | 1272 | * @return number of sockets created or #GNUNET_SYSERR on error |
1236 | */ | 1273 | */ |
1237 | static int | 1274 | static int |
1238 | unix_transport_server_start (void *cls) | 1275 | unix_transport_server_start (void *cls) |
@@ -1250,8 +1287,8 @@ unix_transport_server_start (void *cls) | |||
1250 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); | 1287 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket"); |
1251 | return GNUNET_SYSERR; | 1288 | return GNUNET_SYSERR; |
1252 | } | 1289 | } |
1253 | if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, (const struct sockaddr *) un, un_len, 0) | 1290 | if (GNUNET_OK != |
1254 | != GNUNET_OK) | 1291 | GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, (const struct sockaddr *) un, un_len)) |
1255 | { | 1292 | { |
1256 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); | 1293 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind"); |
1257 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); | 1294 | GNUNET_NETWORK_socket_close (plugin->unix_sock.desc); |
@@ -1274,55 +1311,6 @@ unix_transport_server_start (void *cls) | |||
1274 | 1311 | ||
1275 | 1312 | ||
1276 | /** | 1313 | /** |
1277 | * Function called for a quick conversion of the binary address to | ||
1278 | * a numeric address. Note that the caller must not free the | ||
1279 | * address and that the next call to this function is allowed | ||
1280 | * to override the address again. | ||
1281 | * | ||
1282 | * @param cls closure | ||
1283 | * @param addr binary address | ||
1284 | * @param addrlen length of the address | ||
1285 | * @return string representing the same address | ||
1286 | */ | ||
1287 | static const char * | ||
1288 | unix_address_to_string (void *cls, const void *addr, size_t addrlen) | ||
1289 | { | ||
1290 | static char rbuf[1024]; | ||
1291 | struct UnixAddress *ua = (struct UnixAddress *) addr; | ||
1292 | char *addrstr; | ||
1293 | size_t addr_str_len; | ||
1294 | |||
1295 | if ((NULL == addr) || (sizeof (struct UnixAddress) > addrlen)) | ||
1296 | { | ||
1297 | GNUNET_break(0); | ||
1298 | return NULL ; | ||
1299 | } | ||
1300 | addrstr = (char *) &ua[1]; | ||
1301 | addr_str_len = ntohl (ua->addrlen); | ||
1302 | |||
1303 | if (addr_str_len != addrlen - sizeof(struct UnixAddress)) | ||
1304 | { | ||
1305 | GNUNET_break(0); | ||
1306 | return NULL ; | ||
1307 | } | ||
1308 | |||
1309 | if ('\0' != addrstr[addr_str_len - 1]) | ||
1310 | { | ||
1311 | GNUNET_break(0); | ||
1312 | return NULL ; | ||
1313 | } | ||
1314 | if (strlen (addrstr) + 1 != addr_str_len) | ||
1315 | { | ||
1316 | GNUNET_break(0); | ||
1317 | return NULL ; | ||
1318 | } | ||
1319 | |||
1320 | GNUNET_snprintf (rbuf, sizeof(rbuf), "%s.%u.%s", PLUGIN_NAME, | ||
1321 | ntohl (ua->options), addrstr); | ||
1322 | return rbuf; | ||
1323 | } | ||
1324 | |||
1325 | /** | ||
1326 | * Function that will be called to check if a binary address for this | 1314 | * Function that will be called to check if a binary address for this |
1327 | * plugin is well-formed and corresponds to an address for THIS peer | 1315 | * plugin is well-formed and corresponds to an address for THIS peer |
1328 | * (as per our configuration). Naturally, if absolutely necessary, | 1316 | * (as per our configuration). Naturally, if absolutely necessary, |
@@ -1425,7 +1413,7 @@ static int | |||
1425 | unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, | 1413 | unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, |
1426 | void **buf, size_t *added) | 1414 | void **buf, size_t *added) |
1427 | { | 1415 | { |
1428 | struct UnixAddress *ua; | 1416 | struct UnixAddress *ua; |
1429 | char *address; | 1417 | char *address; |
1430 | char *plugin; | 1418 | char *plugin; |
1431 | char *optionstr; | 1419 | char *optionstr; |
@@ -1461,7 +1449,7 @@ unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, | |||
1461 | return GNUNET_SYSERR; | 1449 | return GNUNET_SYSERR; |
1462 | } | 1450 | } |
1463 | optionstr[0] = '\0'; | 1451 | optionstr[0] = '\0'; |
1464 | optionstr ++; | 1452 | optionstr++; |
1465 | options = atol (optionstr); | 1453 | options = atol (optionstr); |
1466 | address = strchr (optionstr, '.'); | 1454 | address = strchr (optionstr, '.'); |
1467 | if (NULL == address) | 1455 | if (NULL == address) |
@@ -1471,7 +1459,7 @@ unix_string_to_address (void *cls, const char *addr, uint16_t addrlen, | |||
1471 | return GNUNET_SYSERR; | 1459 | return GNUNET_SYSERR; |
1472 | } | 1460 | } |
1473 | address[0] = '\0'; | 1461 | address[0] = '\0'; |
1474 | address ++; | 1462 | address++; |
1475 | if (0 != strcmp(plugin, PLUGIN_NAME)) | 1463 | if (0 != strcmp(plugin, PLUGIN_NAME)) |
1476 | { | 1464 | { |
1477 | GNUNET_break (0); | 1465 | GNUNET_break (0); |
diff --git a/src/util/client.c b/src/util/client.c index 0e8804158..825c8ec52 100644 --- a/src/util/client.c +++ b/src/util/client.c | |||
@@ -829,11 +829,12 @@ GNUNET_CLIENT_service_test (const char *service, | |||
829 | { | 829 | { |
830 | /* probe UNIX support */ | 830 | /* probe UNIX support */ |
831 | struct sockaddr_un s_un; | 831 | struct sockaddr_un s_un; |
832 | size_t slen; | ||
833 | char *unixpath; | 832 | char *unixpath; |
834 | 833 | ||
835 | unixpath = NULL; | 834 | unixpath = NULL; |
836 | 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? */ | 835 | if ((GNUNET_OK == |
836 | GNUNET_CONFIGURATION_get_value_filename (cfg, service, "UNIXPATH", &unixpath)) && | ||
837 | (0 < strlen (unixpath))) /* We have a non-NULL unixpath, does that mean it's valid? */ | ||
837 | { | 838 | { |
838 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) | 839 | if (strlen (unixpath) >= sizeof (s_un.sun_path)) |
839 | { | 840 | { |
@@ -852,21 +853,13 @@ GNUNET_CLIENT_service_test (const char *service, | |||
852 | { | 853 | { |
853 | memset (&s_un, 0, sizeof (s_un)); | 854 | memset (&s_un, 0, sizeof (s_un)); |
854 | s_un.sun_family = AF_UNIX; | 855 | s_un.sun_family = AF_UNIX; |
855 | slen = strlen (unixpath) + 1; | 856 | strncpy (s_un.sun_path, unixpath, sizeof (s_un.sun_path) - 1); |
856 | if (slen >= sizeof (s_un.sun_path)) | ||
857 | slen = sizeof (s_un.sun_path) - 1; | ||
858 | memcpy (s_un.sun_path, unixpath, slen); | ||
859 | s_un.sun_path[slen] = '\0'; | ||
860 | slen = sizeof (struct sockaddr_un); | ||
861 | #if LINUX | ||
862 | s_un.sun_path[0] = '\0'; | ||
863 | #endif | ||
864 | #if HAVE_SOCKADDR_IN_SIN_LEN | 857 | #if HAVE_SOCKADDR_IN_SIN_LEN |
865 | s_un.sun_len = (u_char) slen; | 858 | s_un.sun_len = (u_char) sizeof (struct sockaddr_un); |
866 | #endif | 859 | #endif |
867 | if (GNUNET_OK != | 860 | if (GNUNET_OK != |
868 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un, | 861 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un, |
869 | slen, GNUNET_BIND_EXCLUSIVE)) | 862 | sizeof (struct sockaddr_un))) |
870 | { | 863 | { |
871 | /* failed to bind => service must be running */ | 864 | /* failed to bind => service must be running */ |
872 | GNUNET_free (unixpath); | 865 | GNUNET_free (unixpath); |
@@ -916,7 +909,7 @@ GNUNET_CLIENT_service_test (const char *service, | |||
916 | { | 909 | { |
917 | if (GNUNET_OK != | 910 | if (GNUNET_OK != |
918 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in, | 911 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in, |
919 | sizeof (s_in), GNUNET_BIND_EXCLUSIVE)) | 912 | sizeof (s_in))) |
920 | { | 913 | { |
921 | /* failed to bind => service must be running */ | 914 | /* failed to bind => service must be running */ |
922 | GNUNET_free (hostname); | 915 | GNUNET_free (hostname); |
@@ -949,7 +942,7 @@ GNUNET_CLIENT_service_test (const char *service, | |||
949 | { | 942 | { |
950 | if (GNUNET_OK != | 943 | if (GNUNET_OK != |
951 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6, | 944 | GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6, |
952 | sizeof (s_in6), GNUNET_BIND_EXCLUSIVE)) | 945 | sizeof (s_in6))) |
953 | { | 946 | { |
954 | /* failed to bind => service must be running */ | 947 | /* failed to bind => service must be running */ |
955 | GNUNET_free (hostname); | 948 | GNUNET_free (hostname); |
diff --git a/src/util/configuration.c b/src/util/configuration.c index d7076fac1..1e516b825 100644 --- a/src/util/configuration.c +++ b/src/util/configuration.c | |||
@@ -88,8 +88,8 @@ struct GNUNET_CONFIGURATION_Handle | |||
88 | 88 | ||
89 | /** | 89 | /** |
90 | * Modification indication since last save | 90 | * Modification indication since last save |
91 | * GNUNET_NO if clean, GNUNET_YES if dirty, | 91 | * #GNUNET_NO if clean, #GNUNET_YES if dirty, |
92 | * GNUNET_SYSERR on error (i.e. last save failed) | 92 | * #GNUNET_SYSERR on error (i.e. last save failed) |
93 | */ | 93 | */ |
94 | int dirty; | 94 | int dirty; |
95 | 95 | ||
@@ -142,10 +142,10 @@ GNUNET_CONFIGURATION_destroy (struct GNUNET_CONFIGURATION_Handle *cfg) | |||
142 | * @param cfg configuration to update | 142 | * @param cfg configuration to update |
143 | * @param mem the memory block of serialized configuration | 143 | * @param mem the memory block of serialized configuration |
144 | * @param size the size of the memory block | 144 | * @param size the size of the memory block |
145 | * @param allow_inline set to GNUNET_YES if we recursively load configuration | 145 | * @param allow_inline set to #GNUNET_YES if we recursively load configuration |
146 | * from inlined configurations; GNUNET_NO if not and raise warnings | 146 | * from inlined configurations; #GNUNET_NO if not and raise warnings |
147 | * when we come across them | 147 | * when we come across them |
148 | * @return GNUNET_OK on success, GNUNET_ERROR on error | 148 | * @return #GNUNET_OK on success, #GNUNET_ERROR on error |
149 | */ | 149 | */ |
150 | int | 150 | int |
151 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, | 151 | GNUNET_CONFIGURATION_deserialize (struct GNUNET_CONFIGURATION_Handle *cfg, |
diff --git a/src/util/connection.c b/src/util/connection.c index a429f2f7e..eeabebdf7 100644 --- a/src/util/connection.c +++ b/src/util/connection.c | |||
@@ -826,22 +826,13 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | |||
826 | #ifdef AF_UNIX | 826 | #ifdef AF_UNIX |
827 | struct GNUNET_CONNECTION_Handle *connection; | 827 | struct GNUNET_CONNECTION_Handle *connection; |
828 | struct sockaddr_un *un; | 828 | struct sockaddr_un *un; |
829 | size_t slen; | ||
830 | 829 | ||
831 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ | 830 | GNUNET_assert (0 < strlen (unixpath)); /* sanity check */ |
832 | un = GNUNET_new (struct sockaddr_un); | 831 | un = GNUNET_new (struct sockaddr_un); |
833 | un->sun_family = AF_UNIX; | 832 | un->sun_family = AF_UNIX; |
834 | slen = strlen (unixpath); | 833 | strncpy(un->sun_path, unixpath, sizeof(un->sun_path) - 1); |
835 | if (slen >= sizeof (un->sun_path)) | ||
836 | slen = sizeof (un->sun_path) - 1; | ||
837 | memcpy (un->sun_path, unixpath, slen); | ||
838 | un->sun_path[slen] = '\0'; | ||
839 | slen = sizeof (struct sockaddr_un); | ||
840 | #if HAVE_SOCKADDR_IN_SIN_LEN | 834 | #if HAVE_SOCKADDR_IN_SIN_LEN |
841 | un->sun_len = (u_char) slen; | 835 | un->sun_len = (u_char) sizeof (struct sockaddr_un); |
842 | #endif | ||
843 | #if LINUX | ||
844 | un->sun_path[0] = '\0'; | ||
845 | #endif | 836 | #endif |
846 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); | 837 | connection = GNUNET_new (struct GNUNET_CONNECTION_Handle); |
847 | connection->cfg = cfg; | 838 | connection->cfg = cfg; |
@@ -850,7 +841,7 @@ GNUNET_CONNECTION_create_from_connect_to_unixpath (const struct | |||
850 | connection->port = 0; | 841 | connection->port = 0; |
851 | connection->hostname = NULL; | 842 | connection->hostname = NULL; |
852 | connection->addr = (struct sockaddr *) un; | 843 | connection->addr = (struct sockaddr *) un; |
853 | connection->addrlen = slen; | 844 | connection->addrlen = sizeof (struct sockaddr_un); |
854 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); | 845 | connection->sock = GNUNET_NETWORK_socket_create (AF_UNIX, SOCK_STREAM, 0); |
855 | if (NULL == connection->sock) | 846 | if (NULL == connection->sock) |
856 | { | 847 | { |
diff --git a/src/util/network.c b/src/util/network.c index a921998e9..7a4b2a0b3 100644 --- a/src/util/network.c +++ b/src/util/network.c | |||
@@ -87,7 +87,9 @@ GNUNET_NETWORK_test_pf (int pf) | |||
87 | { | 87 | { |
88 | if (EAFNOSUPPORT == errno) | 88 | if (EAFNOSUPPORT == errno) |
89 | return GNUNET_NO; | 89 | return GNUNET_NO; |
90 | fprintf (stderr, "Failed to create test socket: %s\n", STRERROR (errno)); | 90 | GNUNET_log (GNUNET_ERROR_TYPE_WARNING, |
91 | "Failed to create test socket: %s\n", | ||
92 | STRERROR (errno)); | ||
91 | return GNUNET_SYSERR; | 93 | return GNUNET_SYSERR; |
92 | } | 94 | } |
93 | #if WINDOWS | 95 | #if WINDOWS |
@@ -383,20 +385,18 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc, | |||
383 | * @param desc socket to bind | 385 | * @param desc socket to bind |
384 | * @param address address to be bound | 386 | * @param address address to be bound |
385 | * @param address_len length of @a address | 387 | * @param address_len length of @a address |
386 | * @param flags flags affecting bind behaviour | ||
387 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise | 388 | * @return #GNUNET_OK on success, #GNUNET_SYSERR otherwise |
388 | */ | 389 | */ |
389 | int | 390 | int |
390 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | 391 | GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, |
391 | const struct sockaddr *address, | 392 | const struct sockaddr *address, |
392 | socklen_t address_len, | 393 | socklen_t address_len) |
393 | int flags) | ||
394 | { | 394 | { |
395 | int ret; | 395 | int ret; |
396 | socklen_t bind_address_len = address_len; | 396 | socklen_t bind_address_len = address_len; |
397 | 397 | ||
398 | #ifdef LINUX | 398 | #ifdef LINUX |
399 | if (address->sa_family == AF_UNIX) | 399 | if (AF_UNIX == address->sa_family) |
400 | { | 400 | { |
401 | const struct sockaddr_un *address_un = (const struct sockaddr_un *)address; | 401 | const struct sockaddr_un *address_un = (const struct sockaddr_un *)address; |
402 | if (address_un->sun_path[0] == '\0') | 402 | if (address_un->sun_path[0] == '\0') |
@@ -431,16 +431,6 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
431 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); | 431 | LOG_STRERROR (GNUNET_ERROR_TYPE_DEBUG, "setsockopt"); |
432 | } | 432 | } |
433 | #endif | 433 | #endif |
434 | #ifndef LINUX | ||
435 | #ifndef MINGW | ||
436 | if (address->sa_family == AF_UNIX && (flags & GNUNET_BIND_EXCLUSIVE) == 0) | ||
437 | { | ||
438 | const struct sockaddr_un *un = (const struct sockaddr_un *) address; | ||
439 | |||
440 | (void) unlink (un->sun_path); | ||
441 | } | ||
442 | #endif | ||
443 | #endif | ||
444 | ret = bind (desc->fd, address, bind_address_len); | 434 | ret = bind (desc->fd, address, bind_address_len); |
445 | #ifdef MINGW | 435 | #ifdef MINGW |
446 | if (SOCKET_ERROR == ret) | 436 | if (SOCKET_ERROR == ret) |
@@ -449,12 +439,10 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc, | |||
449 | if (ret != 0) | 439 | if (ret != 0) |
450 | return GNUNET_SYSERR; | 440 | return GNUNET_SYSERR; |
451 | #ifndef MINGW | 441 | #ifndef MINGW |
452 | #ifndef LINUX | ||
453 | desc->addr = GNUNET_malloc (address_len); | 442 | desc->addr = GNUNET_malloc (address_len); |
454 | memcpy (desc->addr, address, address_len); | 443 | memcpy (desc->addr, address, address_len); |
455 | desc->addrlen = address_len; | 444 | desc->addrlen = address_len; |
456 | #endif | 445 | #endif |
457 | #endif | ||
458 | return GNUNET_OK; | 446 | return GNUNET_OK; |
459 | } | 447 | } |
460 | 448 | ||
@@ -483,17 +471,17 @@ GNUNET_NETWORK_socket_close (struct GNUNET_NETWORK_Handle *desc) | |||
483 | #else | 471 | #else |
484 | ret = close (desc->fd); | 472 | ret = close (desc->fd); |
485 | #endif | 473 | #endif |
486 | #ifndef LINUX | ||
487 | #ifndef MINGW | 474 | #ifndef MINGW |
488 | if ((desc->af == AF_UNIX) && (NULL != desc->addr)) | 475 | if ((desc->af == AF_UNIX) && (NULL != desc->addr)) |
489 | { | 476 | { |
490 | const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; | 477 | const struct sockaddr_un *un = (const struct sockaddr_un *) desc->addr; |
491 | 478 | ||
492 | if (0 != unlink (un->sun_path)) | 479 | if (0 != unlink (un->sun_path)) |
493 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, "unlink", un->sun_path); | 480 | LOG_STRERROR_FILE (GNUNET_ERROR_TYPE_WARNING, |
481 | "unlink", | ||
482 | un->sun_path); | ||
494 | } | 483 | } |
495 | #endif | 484 | #endif |
496 | #endif | ||
497 | GNUNET_NETWORK_socket_free_memory_only_ (desc); | 485 | GNUNET_NETWORK_socket_free_memory_only_ (desc); |
498 | return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; | 486 | return (ret == 0) ? GNUNET_OK : GNUNET_SYSERR; |
499 | } | 487 | } |
diff --git a/src/util/server.c b/src/util/server.c index e00b2ffb8..397e32f8c 100644 --- a/src/util/server.c +++ b/src/util/server.c | |||
@@ -468,7 +468,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen) | |||
468 | return NULL; | 468 | return NULL; |
469 | } | 469 | } |
470 | /* bind the socket */ | 470 | /* bind the socket */ |
471 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen, 0)) | 471 | if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen)) |
472 | { | 472 | { |
473 | eno = errno; | 473 | eno = errno; |
474 | if (EADDRINUSE != errno) | 474 | if (EADDRINUSE != errno) |
diff --git a/src/util/service.c b/src/util/service.c index eb3a84221..b8975f418 100644 --- a/src/util/service.c +++ b/src/util/service.c | |||
@@ -834,24 +834,15 @@ add_unixpath (struct sockaddr **saddrs, socklen_t * saddrlens, | |||
834 | { | 834 | { |
835 | #ifdef AF_UNIX | 835 | #ifdef AF_UNIX |
836 | struct sockaddr_un *un; | 836 | struct sockaddr_un *un; |
837 | size_t slen; | ||
838 | 837 | ||
839 | un = GNUNET_malloc (sizeof (struct sockaddr_un)); | 838 | un = GNUNET_malloc (sizeof (struct sockaddr_un)); |
840 | un->sun_family = AF_UNIX; | 839 | un->sun_family = AF_UNIX; |
841 | slen = strlen (unixpath) + 1; | 840 | strncpy (un->sun_path, unixpath, sizeof (un->sun_path) - 1); |
842 | if (slen >= sizeof (un->sun_path)) | ||
843 | slen = sizeof (un->sun_path) - 1; | ||
844 | memcpy (un->sun_path, unixpath, slen); | ||
845 | un->sun_path[slen] = '\0'; | ||
846 | slen = sizeof (struct sockaddr_un); | ||
847 | #if LINUX | ||
848 | un->sun_path[0] = '\0'; | ||
849 | #endif | ||
850 | #if HAVE_SOCKADDR_IN_SIN_LEN | 841 | #if HAVE_SOCKADDR_IN_SIN_LEN |
851 | un->sun_len = (u_char) slen; | 842 | un->sun_len = (u_char) sizeof (struct sockaddr_un); |
852 | #endif | 843 | #endif |
853 | *saddrs = (struct sockaddr *) un; | 844 | *saddrs = (struct sockaddr *) un; |
854 | *saddrlens = slen; | 845 | *saddrlens = sizeof (struct sockaddr_un); |
855 | #else | 846 | #else |
856 | /* this function should never be called | 847 | /* this function should never be called |
857 | * unless AF_UNIX is defined! */ | 848 | * unless AF_UNIX is defined! */ |
@@ -989,6 +980,11 @@ GNUNET_SERVICE_get_server_addresses (const char *service_name, | |||
989 | LOG (GNUNET_ERROR_TYPE_INFO, | 980 | LOG (GNUNET_ERROR_TYPE_INFO, |
990 | _("Using `%s' instead\n"), unixpath); | 981 | _("Using `%s' instead\n"), unixpath); |
991 | } | 982 | } |
983 | if (GNUNET_OK != | ||
984 | GNUNET_DISK_directory_create_for_file (unixpath)) | ||
985 | GNUNET_log_strerror_file (GNUNET_ERROR_TYPE_ERROR, | ||
986 | "mkdir", | ||
987 | unixpath); | ||
992 | } | 988 | } |
993 | if (NULL != unixpath) | 989 | if (NULL != unixpath) |
994 | { | 990 | { |
diff --git a/src/util/test_connection.c b/src/util/test_connection.c index 124f3c9d3..13c800995 100644 --- a/src/util/test_connection.c +++ b/src/util/test_connection.c | |||
@@ -62,9 +62,9 @@ open_listen_socket () | |||
62 | if (GNUNET_NETWORK_socket_setsockopt | 62 | if (GNUNET_NETWORK_socket_setsockopt |
63 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 63 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
64 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | 64 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
65 | GNUNET_assert (GNUNET_NETWORK_socket_bind | 65 | GNUNET_assert (GNUNET_OK == |
66 | (desc, (const struct sockaddr *) &sa, | 66 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, |
67 | sizeof (sa), 0) == GNUNET_OK); | 67 | sizeof (sa))); |
68 | GNUNET_NETWORK_socket_listen (desc, 5); | 68 | GNUNET_NETWORK_socket_listen (desc, 5); |
69 | return desc; | 69 | return desc; |
70 | } | 70 | } |
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c index ea6acdd53..adab28d40 100644 --- a/src/util/test_connection_addressing.c +++ b/src/util/test_connection_addressing.c | |||
@@ -65,7 +65,7 @@ open_listen_socket () | |||
65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | 65 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
66 | if (GNUNET_OK != | 66 | if (GNUNET_OK != |
67 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, | 67 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, |
68 | sizeof (sa), 0)) | 68 | sizeof (sa))) |
69 | { | 69 | { |
70 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, | 70 | GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, |
71 | "bind"); | 71 | "bind"); |
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c index e47712d3f..32a00fcfa 100644 --- a/src/util/test_connection_receive_cancel.c +++ b/src/util/test_connection_receive_cancel.c | |||
@@ -61,9 +61,9 @@ open_listen_socket () | |||
61 | if (GNUNET_NETWORK_socket_setsockopt | 61 | if (GNUNET_NETWORK_socket_setsockopt |
62 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 62 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
63 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | 63 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
64 | GNUNET_assert (GNUNET_NETWORK_socket_bind | 64 | GNUNET_assert (GNUNET_OK == |
65 | (desc, (const struct sockaddr *) &sa, | 65 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, |
66 | sizeof (sa), 0) == GNUNET_OK); | 66 | sizeof (sa))); |
67 | GNUNET_NETWORK_socket_listen (desc, 5); | 67 | GNUNET_NETWORK_socket_listen (desc, 5); |
68 | return desc; | 68 | return desc; |
69 | } | 69 | } |
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c index 27170ed41..ec8057cf2 100644 --- a/src/util/test_connection_timeout.c +++ b/src/util/test_connection_timeout.c | |||
@@ -58,9 +58,9 @@ open_listen_socket () | |||
58 | if (GNUNET_NETWORK_socket_setsockopt | 58 | if (GNUNET_NETWORK_socket_setsockopt |
59 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) | 59 | (desc, SOL_SOCKET, SO_REUSEADDR, &on, sizeof (on)) != GNUNET_OK) |
60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); | 60 | GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt"); |
61 | GNUNET_assert (GNUNET_NETWORK_socket_bind | 61 | GNUNET_assert (GNUNET_OK == |
62 | (desc, (const struct sockaddr *) &sa, | 62 | GNUNET_NETWORK_socket_bind (desc, (const struct sockaddr *) &sa, |
63 | sizeof (sa), 0) == GNUNET_OK); | 63 | sizeof (sa))); |
64 | GNUNET_NETWORK_socket_listen (desc, 5); | 64 | GNUNET_NETWORK_socket_listen (desc, 5); |
65 | return desc; | 65 | return desc; |
66 | } | 66 | } |
diff --git a/src/util/test_server_with_client_unix.c b/src/util/test_server_with_client_unix.c index 30e993411..49b70478d 100644 --- a/src/util/test_server_with_client_unix.c +++ b/src/util/test_server_with_client_unix.c | |||
@@ -130,20 +130,15 @@ task (void *cls, const struct GNUNET_SCHEDULER_TaskContext *tc) | |||
130 | { | 130 | { |
131 | struct sockaddr_un un; | 131 | struct sockaddr_un un; |
132 | const char *unixpath = "/tmp/testsock"; | 132 | const char *unixpath = "/tmp/testsock"; |
133 | size_t slen = strlen (unixpath); | ||
134 | struct sockaddr *sap[2]; | 133 | struct sockaddr *sap[2]; |
135 | socklen_t slens[2]; | 134 | socklen_t slens[2]; |
136 | 135 | ||
137 | memset (&un, 0, sizeof (un)); | 136 | memset (&un, 0, sizeof (un)); |
138 | un.sun_family = AF_UNIX; | 137 | un.sun_family = AF_UNIX; |
139 | memcpy (un.sun_path, unixpath, slen); | 138 | strncpy(un.sun_path, unixpath, sizeof (un.sun_path) - 1); |
140 | un.sun_path[slen] = '\0'; | ||
141 | #if HAVE_SOCKADDR_IN_SIN_LEN | 139 | #if HAVE_SOCKADDR_IN_SIN_LEN |
142 | un.sun_len = (u_char) sizeof (un); | 140 | un.sun_len = (u_char) sizeof (un); |
143 | #endif | 141 | #endif |
144 | #if LINUX | ||
145 | un.sun_path[0] = '\0'; | ||
146 | #endif | ||
147 | 142 | ||
148 | sap[0] = (struct sockaddr *) &un; | 143 | sap[0] = (struct sockaddr *) &un; |
149 | slens[0] = sizeof (un); | 144 | slens[0] = sizeof (un); |