1
1

Improve error handling and documentation for -f/--format. (#568)

We now reject all invalid format characters given as the
argument to the -f/--format flag.  All valid characters are now
documented in the usage message and manual page.

Towards #566.
Этот коммит содержится в:
Bruce A. Mah 2017-05-08 10:01:15 -07:00 коммит произвёл GitHub
родитель 67653543ad
Коммит 37d913dfcc
5 изменённых файлов: 25 добавлений и 3 удалений

Просмотреть файл

@ -23,7 +23,7 @@ establish both a server and a client.
set server port to listen on/connect to to \fIn\fR (default 5201)
.TP
.BR -f ", " --format " "
[kmKM] format to report: Kbits, Mbits, KBytes, MBytes
[kmgtKMGT] format to report: Kbits/Mbits/Gbits/Tbits
.TP
.BR -i ", " --interval " \fIn\fR"
pause \fIn\fR seconds between periodic bandwidth reports;

Просмотреть файл

@ -709,7 +709,25 @@ iperf_parse_arguments(struct iperf_test *test, int argc, char **argv)
test->server_port = atoi(optarg);
break;
case 'f':
test->settings->unit_format = *optarg;
if (!optarg) {
i_errno = IEBADFORMAT;
return -1;
}
test->settings->unit_format = *optarg;
if (test->settings->unit_format == 'k' ||
test->settings->unit_format == 'K' ||
test->settings->unit_format == 'm' ||
test->settings->unit_format == 'M' ||
test->settings->unit_format == 'g' ||
test->settings->unit_format == 'G' ||
test->settings->unit_format == 't' ||
test->settings->unit_format == 'T') {
break;
}
else {
i_errno = IEBADFORMAT;
return -1;
}
break;
case 'i':
/* XXX: could potentially want separate stat collection and reporting intervals,

Просмотреть файл

@ -302,6 +302,7 @@ enum {
IEBADTOS = 21, // Bad TOS value
IESETCLIENTAUTH = 22, // Bad configuration of client authentication
IESETSERVERAUTH = 23, // Bad configuration of server authentication
IEBADFORMAT = 24, // Bad format argument to -f
/* Test errors */
IENEWTEST = 100, // Unable to create a new test (check perror)
IEINITTEST = 101, // Test initialization failed (check perror)

Просмотреть файл

@ -137,6 +137,9 @@ iperf_strerror(int int_errno)
case IESETSERVERAUTH:
snprintf(errstr, len, "you must specify path to a valid private rsa server to be used and a user credential file");
break;
case IEBADFORMAT:
snprintf(errstr, len, "bad format specifier (valid formats are in the set [kmgtKMGT])");
break;
case IEMSS:
snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS);
break;

Просмотреть файл

@ -98,7 +98,7 @@ const char usage_longstr[] = "Usage: iperf3 [-s|-c host] [options]\n"
" iperf3 [-h|--help] [-v|--version]\n\n"
"Server or Client:\n"
" -p, --port # server port to listen on/connect to\n"
" -f, --format [kmgKMG] format to report: Kbits, Mbits, KBytes, MBytes\n"
" -f, --format [kmgtKMGT] format to report: Kbits, Mbits, Gbits, Tbits\n"
" -i, --interval # seconds between periodic bandwidth reports\n"
" -F, --file name xmit/recv the specified file\n"
#if defined(HAVE_CPU_AFFINITY)