aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/arm/gnunet-service-arm.c2
-rw-r--r--src/dns/dnsstub.c3
-rw-r--r--src/gns/gnunet-dns2gns.c6
-rw-r--r--src/gns/gnunet-gns-proxy.c2
-rw-r--r--src/gns/gnunet-service-gns_resolver.c3
-rw-r--r--src/include/gnunet_network_lib.h10
-rw-r--r--src/nat/nat_test.c2
-rw-r--r--src/testing/testing.c3
-rw-r--r--src/transport/plugin_transport_udp.c4
-rw-r--r--src/transport/plugin_transport_unix.c2
-rw-r--r--src/util/client.c6
-rw-r--r--src/util/network.c5
-rw-r--r--src/util/server.c2
-rw-r--r--src/util/test_connection.c2
-rw-r--r--src/util/test_connection_addressing.c2
-rw-r--r--src/util/test_connection_receive_cancel.c2
-rw-r--r--src/util/test_connection_timeout.c2
17 files changed, 36 insertions, 22 deletions
diff --git a/src/arm/gnunet-service-arm.c b/src/arm/gnunet-service-arm.c
index 974e983bb4..2eb8707195 100644
--- a/src/arm/gnunet-service-arm.c
+++ b/src/arm/gnunet-service-arm.c
@@ -617,7 +617,7 @@ create_listen_socket (struct sockaddr *sa, socklen_t addr_len,
#endif
if (GNUNET_NETWORK_socket_bind
- (sock, (const struct sockaddr *) sa, addr_len) != GNUNET_OK)
+ (sock, (const struct sockaddr *) sa, addr_len, 0) != GNUNET_OK)
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_
diff --git a/src/dns/dnsstub.c b/src/dns/dnsstub.c
index c755aff160..3b30d3e63a 100644
--- a/src/dns/dnsstub.c
+++ b/src/dns/dnsstub.c
@@ -169,7 +169,8 @@ open_socket (int af)
sa->sa_family = af;
if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret,
sa,
- alen))
+ alen,
+ 0))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Could not bind to any port: %s\n"),
diff --git a/src/gns/gnunet-dns2gns.c b/src/gns/gnunet-dns2gns.c
index 8350103571..ec64f0730c 100644
--- a/src/gns/gnunet-dns2gns.c
+++ b/src/gns/gnunet-dns2gns.c
@@ -608,7 +608,8 @@ run (void *cls, char *const *args, const char *cfgfile,
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (listen_socket4,
(struct sockaddr *) &v4,
- sizeof (v4)))
+ sizeof (v4),
+ 0))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
GNUNET_NETWORK_socket_close (listen_socket4);
@@ -631,7 +632,8 @@ run (void *cls, char *const *args, const char *cfgfile,
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (listen_socket6,
(struct sockaddr *) &v6,
- sizeof (v6)))
+ sizeof (v6),
+ 0))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
GNUNET_NETWORK_socket_close (listen_socket6);
diff --git a/src/gns/gnunet-gns-proxy.c b/src/gns/gnunet-gns-proxy.c
index 0135fea348..106089ddbd 100644
--- a/src/gns/gnunet-gns-proxy.c
+++ b/src/gns/gnunet-gns-proxy.c
@@ -3378,7 +3378,7 @@ run (void *cls, char *const *args, const char *cfgfile,
if ((NULL == lsock) ||
(GNUNET_OK !=
GNUNET_NETWORK_socket_bind (lsock, (const struct sockaddr *) &sa,
- sizeof (sa))))
+ sizeof (sa), 0)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
"Failed to create listen socket bound to `%s'",
diff --git a/src/gns/gnunet-service-gns_resolver.c b/src/gns/gnunet-service-gns_resolver.c
index f20cd24c9a..f3040749a5 100644
--- a/src/gns/gnunet-service-gns_resolver.c
+++ b/src/gns/gnunet-service-gns_resolver.c
@@ -1748,7 +1748,8 @@ resolve_record_dns (struct ResolverHandle *rh,
sa->sa_family = AF_INET;
if (GNUNET_OK != GNUNET_NETWORK_socket_bind (rh->dns_sock,
sa,
- sizeof (struct sockaddr_in)))
+ sizeof (struct sockaddr_in),
+ 0))
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"GNS_PHASE_REC_DNS-%llu: Error binding UDP socket for DNS lookup!\n",
diff --git a/src/include/gnunet_network_lib.h b/src/include/gnunet_network_lib.h
index 1ff397e869..1627058c5f 100644
--- a/src/include/gnunet_network_lib.h
+++ b/src/include/gnunet_network_lib.h
@@ -133,17 +133,25 @@ GNUNET_NETWORK_socket_set_blocking (struct GNUNET_NETWORK_Handle *fd,
/**
+ * Fail to bind if an address is already in use.
+ */
+#define GNUNET_BIND_EXCLUSIVE 0x01
+
+
+/**
* Bind to a connected socket
*
* @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);
+ socklen_t address_len,
+ int flags);
/**
* Close a socket.
diff --git a/src/nat/nat_test.c b/src/nat/nat_test.c
index 387a68d8f7..0c1d59a87d 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,
if ((ret->lsock == NULL) ||
(GNUNET_OK !=
GNUNET_NETWORK_socket_bind (ret->lsock, (const struct sockaddr *) &sa,
- sizeof (sa))))
+ sizeof (sa), 0)))
{
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_
diff --git a/src/testing/testing.c b/src/testing/testing.c
index f268c38d1f..d73d5ece3f 100644
--- a/src/testing/testing.c
+++ b/src/testing/testing.c
@@ -635,7 +635,8 @@ GNUNET_TESTING_reserve_port (struct GNUNET_TESTING_System *system,
continue;
bind_status = GNUNET_NETWORK_socket_bind (socket,
ai->ai_addr,
- ai->ai_addrlen);
+ ai->ai_addrlen,
+ 0);
GNUNET_NETWORK_socket_close (socket);
if (GNUNET_OK != bind_status)
break;
diff --git a/src/transport/plugin_transport_udp.c b/src/transport/plugin_transport_udp.c
index c1511889b5..fa90d16c12 100644
--- a/src/transport/plugin_transport_udp.c
+++ b/src/transport/plugin_transport_udp.c
@@ -2545,7 +2545,7 @@ setup_sockets (struct Plugin *plugin,
GNUNET_a2s (serverAddr, addrlen));
/* binding */
if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv6,
- serverAddr, addrlen))
+ serverAddr, addrlen, 0))
break;
eno = errno;
if (0 != plugin->port)
@@ -2622,7 +2622,7 @@ setup_sockets (struct Plugin *plugin,
/* binding */
if (GNUNET_OK == GNUNET_NETWORK_socket_bind (plugin->sockv4,
- serverAddr, addrlen))
+ serverAddr, addrlen, 0))
break;
eno = errno;
if (0 != plugin->port)
diff --git a/src/transport/plugin_transport_unix.c b/src/transport/plugin_transport_unix.c
index 81aa9cb94f..064a91663e 100644
--- a/src/transport/plugin_transport_unix.c
+++ b/src/transport/plugin_transport_unix.c
@@ -1150,7 +1150,7 @@ unix_transport_server_start (void *cls)
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "socket");
return GNUNET_SYSERR;
}
- if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen)
+ if (GNUNET_NETWORK_socket_bind (plugin->unix_sock.desc, serverAddr, addrlen, 0)
!= GNUNET_OK)
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR, "bind");
diff --git a/src/util/client.c b/src/util/client.c
index 73b912cc6f..b1ceede872 100644
--- a/src/util/client.c
+++ b/src/util/client.c
@@ -863,7 +863,7 @@ GNUNET_CLIENT_service_test (const char *service,
#endif
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_un,
- slen))
+ slen, GNUNET_BIND_EXCLUSIVE))
{
/* failed to bind => service must be running */
GNUNET_free (unixpath);
@@ -913,7 +913,7 @@ GNUNET_CLIENT_service_test (const char *service,
{
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in,
- sizeof (s_in)))
+ sizeof (s_in), GNUNET_BIND_EXCLUSIVE))
{
/* failed to bind => service must be running */
GNUNET_free (hostname);
@@ -946,7 +946,7 @@ GNUNET_CLIENT_service_test (const char *service,
{
if (GNUNET_OK !=
GNUNET_NETWORK_socket_bind (sock, (const struct sockaddr *) &s_in6,
- sizeof (s_in6)))
+ sizeof (s_in6), GNUNET_BIND_EXCLUSIVE))
{
/* failed to bind => service must be running */
GNUNET_free (hostname);
diff --git a/src/util/network.c b/src/util/network.c
index 659b89c0c7..ff0d0d03c3 100644
--- a/src/util/network.c
+++ b/src/util/network.c
@@ -372,7 +372,8 @@ GNUNET_NETWORK_socket_accept (const struct GNUNET_NETWORK_Handle *desc,
int
GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
const struct sockaddr *address,
- socklen_t address_len)
+ socklen_t address_len,
+ int flags)
{
int ret;
@@ -392,7 +393,7 @@ GNUNET_NETWORK_socket_bind (struct GNUNET_NETWORK_Handle *desc,
#endif
#ifndef LINUX
#ifndef MINGW
- if (address->sa_family == AF_UNIX)
+ if (address->sa_family == AF_UNIX && (flags & GNUNET_BIND_EXCLUSIVE) == 0)
{
const struct sockaddr_un *un = (const struct sockaddr_un *) address;
diff --git a/src/util/server.c b/src/util/server.c
index 2c3533d6fb..f62bf85393 100644
--- a/src/util/server.c
+++ b/src/util/server.c
@@ -422,7 +422,7 @@ open_listen_socket (const struct sockaddr *serverAddr, socklen_t socklen)
return NULL;
}
/* bind the socket */
- if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen))
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (sock, serverAddr, socklen, 0))
{
eno = errno;
if (EADDRINUSE != errno)
diff --git a/src/util/test_connection.c b/src/util/test_connection.c
index e129c80ea7..1ba20498fd 100644
--- a/src/util/test_connection.c
+++ b/src/util/test_connection.c
@@ -67,7 +67,7 @@ open_listen_socket ()
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
GNUNET_assert (GNUNET_NETWORK_socket_bind
(desc, (const struct sockaddr *) &sa,
- sizeof (sa)) == GNUNET_OK);
+ sizeof (sa), 0) == GNUNET_OK);
GNUNET_NETWORK_socket_listen (desc, 5);
return desc;
}
diff --git a/src/util/test_connection_addressing.c b/src/util/test_connection_addressing.c
index e5c8edeeb7..eeb610dd11 100644
--- a/src/util/test_connection_addressing.c
+++ b/src/util/test_connection_addressing.c
@@ -68,7 +68,7 @@ open_listen_socket ()
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)))
+ sizeof (sa), 0))
{
GNUNET_log_strerror (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK,
"bind");
diff --git a/src/util/test_connection_receive_cancel.c b/src/util/test_connection_receive_cancel.c
index 90490343c1..99905e232d 100644
--- a/src/util/test_connection_receive_cancel.c
+++ b/src/util/test_connection_receive_cancel.c
@@ -66,7 +66,7 @@ open_listen_socket ()
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
GNUNET_assert (GNUNET_NETWORK_socket_bind
(desc, (const struct sockaddr *) &sa,
- sizeof (sa)) == GNUNET_OK);
+ sizeof (sa), 0) == GNUNET_OK);
GNUNET_NETWORK_socket_listen (desc, 5);
return desc;
}
diff --git a/src/util/test_connection_timeout.c b/src/util/test_connection_timeout.c
index 8d3f775b54..6608e18dbb 100644
--- a/src/util/test_connection_timeout.c
+++ b/src/util/test_connection_timeout.c
@@ -63,7 +63,7 @@ open_listen_socket ()
GNUNET_log (GNUNET_ERROR_TYPE_ERROR | GNUNET_ERROR_TYPE_BULK, "setsockopt");
GNUNET_assert (GNUNET_NETWORK_socket_bind
(desc, (const struct sockaddr *) &sa,
- sizeof (sa)) == GNUNET_OK);
+ sizeof (sa), 0) == GNUNET_OK);
GNUNET_NETWORK_socket_listen (desc, 5);
return desc;
}