From: Marko Kreen Date: Mon, 18 Mar 2013 15:44:15 +0000 (+0200) Subject: ipv6: Set IPV6_V6ONLY on listen socket. X-Git-Tag: pgbouncer_1_6_rc1~42 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2df26081d4e811bbc0d99369a2f81653e2a59074;p=pgbouncer 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 --- 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);