summaryrefslogtreecommitdiffstats
path: root/transport/socket/src/name.c
diff options
context:
space:
mode:
authorCorentin Chary <corentin.chary@gmail.com>2009-10-27 12:59:54 +0000
committerAnand V. Avati <avati@dev.gluster.com>2009-11-03 07:29:38 -0800
commit190cbd78add970655dbfe93182961745d16240e4 (patch)
tree2151384fcbd5ff8424e802185a6ba7b19b8f0b63 /transport/socket/src/name.c
parent05ba65c143ff35cf9a2bbd022711877efb8c67d4 (diff)
transport/name.c: refine the address resolution logic when listen-host is not specified.
- when listen-host is not specified and there are are no interfaces having adresses belonging to the address-family specified, listen at 0.0.0.0/::0. - this patch is necessary since with AI_ADDRCONFIG, getaddrinfo fails if there are no active interfaces for the address family specified and when listen-host is specified we still want the functionality provided with usage of AI_ADDRCONFIG. Signed-off-by: Corentin Chary <corentin.chary@gmail.com> Signed-off-by: Anand V. Avati <avati@dev.gluster.com> BUG: 339 (glusterfsd fails to start when there are no active interfaces having address in the address family configured.) URL: http://bugs.gluster.com/cgi-bin/bugzilla3/show_bug.cgi?id=339
Diffstat (limited to 'transport/socket/src/name.c')
-rw-r--r--transport/socket/src/name.c21
1 files changed, 18 insertions, 3 deletions
diff --git a/transport/socket/src/name.c b/transport/socket/src/name.c
index d7a232e03..6d538ba34 100644
--- a/transport/socket/src/name.c
+++ b/transport/socket/src/name.c
@@ -19,6 +19,7 @@
#include <sys/types.h>
#include <sys/socket.h>
+#include <netinet/in.h>
#include <errno.h>
#include <netdb.h>
#include <string.h>
@@ -368,7 +369,21 @@ af_inet_server_get_local_sockaddr (transport_t *this,
if (listen_host_data)
{
listen_host = data_to_str (listen_host_data);
- }
+ } else {
+ if (addr->sa_family == AF_INET6) {
+ struct sockaddr_in6 *in = (struct sockaddr_in6 *) addr;
+ in->sin6_addr = in6addr_any;
+ in->sin6_port = htons(listen_port);
+ *addr_len = sizeof(struct sockaddr_in6);
+ goto out;
+ } else if (addr->sa_family == AF_INET) {
+ struct sockaddr_in *in = (struct sockaddr_in *) addr;
+ in->sin_addr.s_addr = htonl(INADDR_ANY);
+ in->sin_port = htons(listen_port);
+ *addr_len = sizeof(struct sockaddr_in);
+ goto out;
+ }
+ }
memset (service, 0, sizeof (service));
sprintf (service, "%d", listen_port);
@@ -384,7 +399,7 @@ af_inet_server_get_local_sockaddr (transport_t *this,
"getaddrinfo failed for host %s, service %s (%s)",
listen_host, service, gai_strerror (ret));
ret = -1;
- goto err;
+ goto out;
}
memcpy (addr, res->ai_addr, res->ai_addrlen);
@@ -392,7 +407,7 @@ af_inet_server_get_local_sockaddr (transport_t *this,
freeaddrinfo (res);
-err:
+out:
return ret;
}