From 1f4b249abb9d79e842171ec787d3baf5e7149ced Mon Sep 17 00:00:00 2001 From: Jef Poskanzer Date: Mon, 28 Jan 2013 14:19:07 -0800 Subject: [PATCH] Better fix for the -u/-l argument parsing mixup. This one avoids the problem of explicitly setting the UDP block size to the TCP default and getting ignored. --- src/iperf_api.c | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/src/iperf_api.c b/src/iperf_api.c index b9f4103..54e1f96 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -367,7 +367,9 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) {NULL, 0, NULL, 0} }; char ch; + int blksize; + blksize = 0; while ((ch = getopt_long(argc, argv, "c:p:st:uP:B:b:l:w:i:n:RS:Nvh6VdM:f:", longopts, NULL)) != -1) { switch (ch) { case 'c': @@ -411,8 +413,6 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) */ } set_protocol(test, Pudp); - if (test->settings->blksize == DEFAULT_TCP_BLKSIZE) - test->settings->blksize = DEFAULT_UDP_BLKSIZE; break; case 'P': if (test->role == 's') { @@ -441,11 +441,7 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) i_errno = IECLIENTONLY; return -1; } - test->settings->blksize = unit_atoi(optarg); - if (test->settings->blksize > MAX_BLOCKSIZE) { - i_errno = IEBLOCKSIZE; - return -1; - } + blksize = unit_atoi(optarg); break; case 'w': // XXX: This is a socket buffer, not specific to TCP @@ -531,6 +527,19 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv) exit(1); } } + + if (blksize == 0) { + if (test->protocol->id == Pudp) + blksize = DEFAULT_UDP_BLKSIZE; + else + blksize = DEFAULT_TCP_BLKSIZE; + } + if (blksize <= 0 || blksize > MAX_BLOCKSIZE) { + i_errno = IEBLOCKSIZE; + return -1; + } + test->settings->blksize = blksize; + /* For subsequent calls to getopt */ #ifdef __APPLE__ optreset = 1;