From 5c01581b32343bf4bec66528db6c1fc6991890a0 Mon Sep 17 00:00:00 2001 From: Jef Poskanzer Date: Mon, 19 Aug 2013 10:02:01 -0700 Subject: [PATCH] Detect that the system doesn't support IPv6 and try falling back to IPv4. --- src/iperf_server_api.c | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index b86f6a8..daae507 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -47,9 +47,21 @@ int iperf_server_listen(struct iperf_test *test) { + retry: if((test->listener = netannounce(test->settings->domain, Ptcp, test->bind_address, test->server_port)) < 0) { - i_errno = IELISTEN; - return -1; + if (errno == EAFNOSUPPORT && (test->settings->domain == AF_INET6 || test->settings->domain == AF_UNSPEC)) { + /* If we get "Address family not supported by protocol", that + ** probably means we were compiled with IPv6 but the running + ** kernel does not actually do IPv6. This is not too unusual, + ** v6 support is and perhaps always will be spotty. + */ + warning("this system does not seem to support IPv6 - trying IPv4"); + test->settings->domain = AF_INET; + goto retry; + } else { + i_errno = IELISTEN; + return -1; + } } if (!test->json_output) {