diff options
author | Bruce A. Mah <bmah@es.net> | 2013-12-18 14:43:12 -0800 |
---|---|---|
committer | Bruce A. Mah <bmah@es.net> | 2013-12-18 14:43:12 -0800 |
commit | cfe8c5fb470efa0b5fc8b9d53d618cb0eda051dc (patch) | |
tree | 690e07b8f5ec2b948d993502a70c91e9b4c6d730 /src/net.c | |
parent | a45a0d37b459d293f35aed6ea40b07f6b90b4044 (diff) | |
download | iperf3-cfe8c5fb470efa0b5fc8b9d53d618cb0eda051dc.tar.gz |
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)
Diffstat (limited to 'src/net.c')
-rw-r--r-- | src/net.c | 14 |
1 files changed, 12 insertions, 2 deletions
@@ -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) { |