aboutsummaryrefslogtreecommitdiff
path: root/src/net.c
diff options
context:
space:
mode:
authorBruce A. Mah <bmah@es.net>2014-07-17 14:30:39 -0700
committerBruce A. Mah <bmah@es.net>2014-07-17 14:30:39 -0700
commit5b760eef47f9d0535a2e4ef0cbaee66a7735e1c0 (patch)
tree44f62232e3aad5edc65cbee7d4f5ac89136429d1 /src/net.c
parentfa0e81c8531539d012805a14912309c75a299e22 (diff)
downloadiperf3-5b760eef47f9d0535a2e4ef0cbaee66a7735e1c0.tar.gz
Fix two related bugs with -B and IPv4 addresses.
If specifying -B with an IPv4 literal address or with an FQDN that resolved to an IPv4 address, but we had not explicitly specified an address family with -4, we failed to set up the socket correctly because we assumed binding to an IPv6 address, and instead (after some error spewage) wound up binding to wildcard address. The fix in this commit has multiple parts: First, if the address family hasn't been explictly specified, don't force AF_INET6 in the hints to getaddrinfo(3). AF_UNSPEC should generate the correct (according to RFC 6724) behavior. Second, iperf_reset_test() should not discard members that were passed from command-line parameters, because that alters the behavior of the iperf3 when it tries to recreate the listening socket. In the failure situation described in this issue (and possibly other as well), the value of -B gets discarded, so on subsequent attempts to set up the listening socket it just binds to the wildcard address. While here, fix on-line help related to the -B option to match reality. Note that we're not completely in compliance with RFC 6724, which states that we should actually try all of the addresses in returned by getaddrinfo(3), rather than just the first one. Fixes Issue #193.
Diffstat (limited to 'src/net.c')
-rw-r--r--src/net.c6
1 files changed, 3 insertions, 3 deletions
diff --git a/src/net.c b/src/net.c
index cc65ebe..e69d507 100644
--- a/src/net.c
+++ b/src/net.c
@@ -107,7 +107,7 @@ netannounce(int domain, int proto, char *local, int port)
snprintf(portstr, 6, "%d", port);
memset(&hints, 0, sizeof(hints));
- hints.ai_family = (domain == AF_UNSPEC ? AF_INET6 : domain);
+ hints.ai_family = domain;
hints.ai_socktype = proto;
hints.ai_flags = AI_PASSIVE;
if (getaddrinfo(local, portstr, &hints, &res) != 0)
@@ -126,10 +126,10 @@ netannounce(int domain, int proto, char *local, int port)
freeaddrinfo(res);
return -1;
}
- if (domain == AF_UNSPEC || domain == AF_INET6) {
+ if (res->ai_family == AF_INET6 && (domain == AF_UNSPEC || domain == AF_INET6)) {
if (domain == AF_UNSPEC)
opt = 0;
- else if (domain == AF_INET6)
+ else
opt = 1;
if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY,
(char *) &opt, sizeof(opt)) < 0) {