sock: set IPV6_V6ONLY on the socket before binding an IPv6 address

so that we can bind wildcard for both IPv4 and IPv6.

Signed-off-by: Michael Adam <obnox@samba.org>
(cherry picked from commit 0698e4d180)
This commit is contained in:
Michael Adam 2013-11-08 15:31:11 +01:00
parent 79f34cd113
commit bb5d6af78f

View File

@ -204,6 +204,18 @@ static int listen_on_one_socket(struct addrinfo *ad)
return -1; return -1;
} }
if (ad->ai_family == AF_INET6) {
ret = setsockopt(listenfd, IPPROTO_IPV6, IPV6_V6ONLY, &on,
sizeof(on));
if (ret != 0) {
log_message(LOG_ERR,
"setsockopt failed to set IPV6_V6ONLY: %s",
strerror(errno));
close(listenfd);
return -1;
}
}
ret = bind(listenfd, ad->ai_addr, ad->ai_addrlen); ret = bind(listenfd, ad->ai_addr, ad->ai_addrlen);
if (ret != 0) { if (ret != 0) {
log_message(LOG_ERR, "bind failed: %s", strerror (errno)); log_message(LOG_ERR, "bind failed: %s", strerror (errno));