diff --git a/server/reds.c b/server/reds.c index c54d30c..16f3087 100644 --- a/server/reds.c +++ b/server/reds.c @@ -2943,9 +2943,15 @@ static int reds_init_socket(const char *addr, int portnr, int family) setsockopt(slisten,SOL_SOCKET,SO_REUSEADDR,(void*)&on,sizeof(on)); #ifdef IPV6_V6ONLY if (e->ai_family == PF_INET6) { - /* listen on both ipv4 and ipv6 */ - setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&off, - sizeof(off)); + if (family == PF_INET6) { + /* we've been asked to listen on ipv6 only. */ + setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&on, + sizeof(on)); + } else { + /* listen on both ipv4 and ipv6 */ + setsockopt(slisten,IPPROTO_IPV6,IPV6_V6ONLY,(void*)&off, + sizeof(off)); + } } #endif if (bind(slisten, e->ai_addr, e->ai_addrlen) == 0) {