diff --git a/configure.ac b/configure.ac index 60d0ac4..8c26b7e 100644 --- a/configure.ac +++ b/configure.ac @@ -50,4 +50,17 @@ AC_C_CONST AC_CHECK_HEADERS([netinet/sctp.h], AC_DEFINE([HAVE_SCTP], [1], [Have SCTP support.])) +# Check for TCP_CONGESTION sockopt (believed to be Linux only) +AC_CACHE_CHECK([TCP_CONGESTION socket option], +[iperf3_cv_header_tcp_congestion], +AC_EGREP_CPP(yes, +[#include +#ifdef TCP_CONGESTION + yes +#endif +],iperf3_cv_header_tcp_congestion=yes,iperf3_cv_header_tcp_congestion=no)) +if test "x$iperf3_cv_header_tcp_congestion" = "xyes"; then + AC_DEFINE([HAVE_TCP_CONGESTION], [1], [Have TCP_CONGESTION sockopt.]) +fi + AC_OUTPUT([Makefile src/Makefile examples/Makefile]) diff --git a/src/iperf_api.c b/src/iperf_api.c index 86f342f..20a7abb 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -570,9 +570,9 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) {"affinity", required_argument, NULL, 'A'}, #endif {"title", required_argument, NULL, 'T'}, -#if defined(linux) && defined(TCP_CONGESTION) +#if defined(HAVE_TCP_CONGESTION) {"linux-congestion", required_argument, NULL, 'C'}, -#endif +#endif /* HAVE_TCP_CONGESTION */ #if defined(HAVE_SCTP) {"sctp", no_argument, NULL, OPT_SCTP}, #endif @@ -792,13 +792,13 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) client_flag = 1; break; case 'C': -#if defined(linux) && defined(TCP_CONGESTION) +#if defined(HAVE_TCP_CONGESTION) test->congestion = strdup(optarg); client_flag = 1; -#else /* linux */ +#else /* HAVE_TCP_CONGESTION */ i_errno = IEUNIMP; return -1; -#endif /* linux */ +#endif /* HAVE_TCP_CONGESTION */ break; case 'd': test->debug = 1; diff --git a/src/iperf_tcp.c b/src/iperf_tcp.c index fa5c08d..037bc16 100644 --- a/src/iperf_tcp.c +++ b/src/iperf_tcp.c @@ -20,6 +20,7 @@ #include #include +#include "config.h" #include "iperf.h" #include "iperf_api.h" #include "iperf_tcp.h" @@ -196,7 +197,7 @@ iperf_tcp_listen(struct iperf_test *test) } printf("SO_SNDBUF is %u\n", opt); } -#if defined(linux) && defined(TCP_CONGESTION) +#if defined(HAVE_TCP_CONGESTION) if (test->congestion) { if (setsockopt(s, IPPROTO_TCP, TCP_CONGESTION, test->congestion, strlen(test->congestion)) < 0) { close(s); @@ -205,7 +206,7 @@ iperf_tcp_listen(struct iperf_test *test) return -1; } } -#endif +#endif /* HAVE_TCP_CONGESTION */ opt = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &opt, sizeof(opt)) < 0) { saved_errno = errno; diff --git a/src/locale.c b/src/locale.c index 4b768f4..d1ff026 100644 --- a/src/locale.c +++ b/src/locale.c @@ -106,9 +106,9 @@ const char usage_longstr[] = "Usage: iperf [-s|-c host] [options]\n" " -R, --reverse run in reverse mode (server sends, client receives)\n" " -w, --window #[KMG] TCP window size (socket buffer size)\n" " -B, --bind bind to a specific interface\n" -#if defined(linux) +#if defined(HAVE_TCP_CONGESTION) " -C, --linux-congestion set TCP congestion control algorithm (Linux only)\n" -#endif +#endif /* HAVE_TCP_CONGESTION */ " -M, --set-mss # set TCP maximum segment size (MTU - 40 bytes)\n" " -N, --nodelay set TCP no delay, disabling Nagle's Algorithm\n" " -4, --version4 only use IPv4\n"