sock: set IPv6_V6ONLY on IPv6 sockets

This allows listening on the same port on IPv4 and IPv6 simultaneously;
otherwise, the second listen call would fail with an "address in use"
error.

Change-Id: I75010a2d1ec6559653e0bda40517dc13d8f5b9a5
Signed-off-by: Daniel Verkamp <daniel.verkamp@intel.com>
Reviewed-on: https://review.gerrithub.io/401718
Tested-by: SPDK Automated Test System <sys_sgsw@intel.com>
Reviewed-by: Shuhei Matsumoto <shuhei.matsumoto.xt@hitachi.com>
Reviewed-by: Jim Harris <james.r.harris@intel.com>
This commit is contained in:
Daniel Verkamp 2018-02-27 16:18:03 -07:00 committed by Jim Harris
parent ad14da9eab
commit 08ad304011

View File

@ -227,6 +227,15 @@ retry:
continue;
}
if (res->ai_family == AF_INET6) {
rc = setsockopt(fd, IPPROTO_IPV6, IPV6_V6ONLY, &val, sizeof val);
if (rc != 0) {
close(fd);
/* error */
continue;
}
}
if (type == SPDK_SOCK_CREATE_LISTEN) {
rc = bind(fd, res->ai_addr, res->ai_addrlen);
if (rc != 0) {