Otherwise it attempts to take over ipv4 port
which fails if the ipv4 was initialized previously.
Reported-by: Guillaume Lelarge
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);