From 7a5a1375cf3220f9c69a9b51ebaf56b6d7f41db4 Mon Sep 17 00:00:00 2001 From: dormando Date: Thu, 26 Mar 2009 00:19:00 -0700 Subject: fix a handful of socket listen bugs. AF_UNSPEC is still necessary for UDP sometimes. We guarantee that at least one address returned from getaddrinfo binds successfully, and in cases of lacking network or ipv6 addresses some of those socket() calls might fail. That's normal. We were bailing on them. This change also removes the need to pass AI_ADDRCONFIG on machines with ipv6 stacks disabled. --- memcached.c | 13 ++++--------- 1 file changed, 4 insertions(+), 9 deletions(-) diff --git a/memcached.c b/memcached.c index 350a671..7666511 100644 --- a/memcached.c +++ b/memcached.c @@ -3603,7 +3603,6 @@ static int new_socket(struct addrinfo *ai) { int flags; if ((sfd = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol)) == -1) { - perror("socket()"); return -1; } @@ -3669,12 +3668,6 @@ static int server_socket(const int port, enum protocol prot) { */ memset(&hints, 0, sizeof (hints)); hints.ai_flags = AI_PASSIVE; - - /* Only use AI_ADDRCONFIG if a hostname is specified, otherwise we might - * not get results for INADDR_ANY. */ - if (settings.inter) - hints.ai_flags |= AI_ADDRCONFIG; - hints.ai_family = AF_UNSPEC; hints.ai_socktype = IS_UDP(prot) ? SOCK_DGRAM : SOCK_STREAM; @@ -3692,8 +3685,10 @@ static int server_socket(const int port, enum protocol prot) { for (next= ai; next; next= next->ai_next) { conn *listen_conn_add; if ((sfd = new_socket(next)) == -1) { - freeaddrinfo(ai); - return 1; + /* getaddrinfo can return "junk" addresses, + * we make sure at least one works before erroring. + */ + continue; } #ifdef IPV6_V6ONLY -- cgit v1.2.1