From 3e58489a5823126fd1d51fcfb74994f9e8fe4e86 Mon Sep 17 00:00:00 2001 From: Ji Jianwen Date: Sat, 24 Mar 2018 07:10:38 +0800 Subject: [PATCH] Fix -B with some SCTP tests, which is part of #678 (#715) Got the following error when running server side with -B option: Server side: ./iperf3 -s -B ----------------------------------------------------------- Server listening on 5201 ----------------------------------------------------------- iperf3: error - unable to start stream listener: Bad file descriptor ----------------------------------------------------------- Client side: ./iperf3 -c --sctp iperf3: error - unable to start stream listener: No such file or directory Similar fix as below for TCP: commit eb1cfe5e162d08efdf18fa12cd6627cfdcd675a7 Author: Bruce A. Mah Date: Fri Aug 1 16:24:14 2014 -0700 Another iteration on issue #193, fixes -B with some TCP tests. Signed-off-by: Jianwen Ji --- src/iperf_sctp.c | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/src/iperf_sctp.c b/src/iperf_sctp.c index a0869a36c..810cac438 100644 --- a/src/iperf_sctp.c +++ b/src/iperf_sctp.c @@ -165,7 +165,16 @@ iperf_sctp_listen(struct iperf_test *test) snprintf(portstr, 6, "%d", test->server_port); memset(&hints, 0, sizeof(hints)); - hints.ai_family = (test->settings->domain == AF_UNSPEC ? AF_INET6 : test->settings->domain); + /* + * If binding to the wildcard address with no explicit address + * family specified, then force us to get an AF_INET6 socket. + * More details in the comments in netanounce(). + */ + if (test->settings->domain == AF_UNSPEC && !test->bind_address) { + hints.ai_family = AF_INET6; + } else { + hints.ai_family = test->settings->domain; + } hints.ai_socktype = SOCK_STREAM; hints.ai_flags = AI_PASSIVE; if (getaddrinfo(test->bind_address, portstr, &hints, &res) != 0) { @@ -180,10 +189,11 @@ iperf_sctp_listen(struct iperf_test *test) } #if defined(IPV6_V6ONLY) && !defined(__OpenBSD__) - if (test->settings->domain == AF_UNSPEC || test->settings->domain == AF_INET6) { + if (res->ai_family == AF_INET6 && (test->settings->domain == AF_UNSPEC || + test->settings->domain == AF_INET6)) { if (test->settings->domain == AF_UNSPEC) opt = 0; - else if (test->settings->domain == AF_INET6) + else opt = 1; if (setsockopt(s, IPPROTO_IPV6, IPV6_V6ONLY, (char *) &opt, sizeof(opt)) < 0) {