diff options
author | dormando <dormando@rydia.net> | 2009-03-26 00:19:00 -0700 |
---|---|---|
committer | Dustin Sallings <dustin@spy.net> | 2009-03-29 10:16:55 -0700 |
commit | 7a5a1375cf3220f9c69a9b51ebaf56b6d7f41db4 (patch) | |
tree | cb738c8c6bd82575c09a6dc8228103460b606bcc | |
parent | 1b2e6edb9980590728305be4f00be1da60201738 (diff) | |
download | memcached-7a5a1375cf3220f9c69a9b51ebaf56b6d7f41db4.tar.gz |
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.
-rw-r--r-- | memcached.c | 13 |
1 files 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 |