Make "iperf3 -s" accept both IPv4 and IPv6 connections on FreeBSD.
(Formerly it was just accepting IPv6.) The problem here was that FreeBSD by default wasn't allowing IPv4 mapped addresses on IPv6 sockets, whereas other platforms (specifically Linux and OS X) both do permit this. We tried to turn on mapped addresses via a setsockopt(IPV6_V6ONLY) call, but this call was broken because the level argument was incorrect. We didn't know about this because we never checked the return value. Fix this by providing the correct argument to setsockopt(). Add some error checking to this and one other setsockopt() call, so we at least don't fail silently in similar situations. Issue: 126 (FreeBSD: iperf3 -s only accepts IPv6 connections)
This commit is contained in:
parent
a45a0d37b4
commit
cfe8c5fb47
14
src/net.c
14
src/net.c
@ -117,13 +117,23 @@ netannounce(int domain, int proto, char *local, int port)
|
||||
}
|
||||
|
||||
opt = 1;
|
||||
setsockopt(s, SOL_SOCKET, SO_REUSEADDR, (char *) &opt, sizeof(opt));
|
||||
if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR,
|
||||
(char *) &opt, sizeof(opt)) < 0) {
|
||||
close(s);
|
||||
freeaddrinfo(res);
|
||||
return -1;
|
||||
}
|
||||
if (domain == AF_UNSPEC || domain == AF_INET6) {
|
||||
if (domain == AF_UNSPEC)
|
||||
opt = 0;
|
||||
else if (domain == AF_INET6)
|
||||
opt = 1;
|
||||
setsockopt(s, SOL_SOCKET, IPV6_V6ONLY, (char *) &opt, sizeof(opt));
|
||||
if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
|
||||
(char *) &opt, sizeof(opt)) < 0) {
|
||||
close(s);
|
||||
freeaddrinfo(res);
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
|
||||
if (bind(s, (struct sockaddr *) res->ai_addr, res->ai_addrlen) < 0) {
|
||||
|
Loading…
Reference in New Issue
Block a user