From 2df26081d4e811bbc0d99369a2f81653e2a59074 Mon Sep 17 00:00:00 2001 From: Marko Kreen Date: Mon, 18 Mar 2013 17:44:15 +0200 Subject: [PATCH] ipv6: Set IPV6_V6ONLY on listen socket. Otherwise it attempts to take over ipv4 port which fails if the ipv4 was initialized previously. Reported-by: Guillaume Lelarge --- src/pooler.c | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/pooler.c b/src/pooler.c index f2eed47..16cef9c 100644 --- a/src/pooler.c +++ b/src/pooler.c @@ -106,6 +106,17 @@ static bool add_listen(int af, const struct sockaddr *sa, int salen) goto failed; } +#ifdef IPV6_V6ONLY + /* avoid ipv6 socket's attempt to takeover ipv4 port */ + if (af == AF_INET6) { + val = 1; + errpos = "setsockopt/IPV6_V6ONLY"; + res = setsockopt(sock, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof(val)); + if (res < 0) + goto failed; + } +#endif + /* bind it */ errpos = "bind"; res = bind(sock, sa, salen); -- 2.40.0