--- embedaddon/iperf/src/iperf_error.c 2016/10/18 13:28:18 1.1.1.1 +++ embedaddon/iperf/src/iperf_error.c 2021/03/17 00:36:46 1.1.1.2 @@ -1,5 +1,5 @@ /* - * iperf, Copyright (c) 2014, 2015, 2016, The Regents of the University of + * iperf, Copyright (c) 2014-2020, The Regents of the University of * California, through Lawrence Berkeley National Laboratory (subject * to receipt of any required approvals from the U.S. Dept. of * Energy). All rights reserved. @@ -33,22 +33,43 @@ #include "iperf.h" #include "iperf_api.h" +int gerror; + +char iperf_timestrerr[100]; + /* Do a printf to stderr. */ void iperf_err(struct iperf_test *test, const char *format, ...) { va_list argp; char str[1000]; + time_t now; + struct tm *ltm = NULL; + char *ct = NULL; + /* Timestamp if requested */ + if (test != NULL && test->timestamps) { + time(&now); + ltm = localtime(&now); + strftime(iperf_timestrerr, sizeof(iperf_timestrerr), test->timestamp_format, ltm); + ct = iperf_timestrerr; + } + va_start(argp, format); vsnprintf(str, sizeof(str), format, argp); if (test != NULL && test->json_output && test->json_top != NULL) cJSON_AddStringToObject(test->json_top, "error", str); else - if (test && test->outfile) { + if (test && test->outfile && test->outfile != stdout) { + if (ct) { + fprintf(test->outfile, "%s", ct); + } fprintf(test->outfile, "iperf3: %s\n", str); } else { + if (ct) { + fprintf(stderr, "%s", ct); + } fprintf(stderr, "iperf3: %s\n", str); } va_end(argp); @@ -60,17 +81,34 @@ iperf_errexit(struct iperf_test *test, const char *for { va_list argp; char str[1000]; + time_t now; + struct tm *ltm = NULL; + char *ct = NULL; + /* Timestamp if requested */ + if (test != NULL && test->timestamps) { + time(&now); + ltm = localtime(&now); + strftime(iperf_timestrerr, sizeof(iperf_timestrerr), "%c ", ltm); + ct = iperf_timestrerr; + } + va_start(argp, format); vsnprintf(str, sizeof(str), format, argp); if (test != NULL && test->json_output && test->json_top != NULL) { cJSON_AddStringToObject(test->json_top, "error", str); iperf_json_finish(test); } else - if (test && test->outfile) { + if (test && test->outfile && test->outfile != stdout) { + if (ct) { + fprintf(test->outfile, "%s", ct); + } fprintf(test->outfile, "iperf3: %s\n", str); } else { + if (ct) { + fprintf(stderr, "%s", ct); + } fprintf(stderr, "iperf3: %s\n", str); } va_end(argp); @@ -82,7 +120,7 @@ iperf_errexit(struct iperf_test *test, const char *for int i_errno; char * -iperf_strerror(int i_errno) +iperf_strerror(int int_errno) { static char errstr[256]; int len, perr, herr; @@ -91,7 +129,7 @@ iperf_strerror(int i_errno) len = sizeof(errstr); memset(errstr, 0, len); - switch (i_errno) { + switch (int_errno) { case IENONE: snprintf(errstr, len, "no error"); break; @@ -122,15 +160,27 @@ iperf_strerror(int i_errno) case IEINTERVAL: snprintf(errstr, len, "invalid report interval (min = %g, max = %g seconds)", MIN_INTERVAL, MAX_INTERVAL); break; - case IEBIND: + case IEBIND: /* UNUSED */ snprintf(errstr, len, "--bind must be specified to use --cport"); break; case IEUDPBLOCKSIZE: - snprintf(errstr, len, "block size too large (maximum = %d bytes)", MAX_UDP_BLOCKSIZE); + snprintf(errstr, len, "block size invalid (minimum = %d bytes, maximum = %d bytes)", MIN_UDP_BLOCKSIZE, MAX_UDP_BLOCKSIZE); break; - case IEBADTOS: - snprintf(errstr, len, "bad TOS value (must be between 0 and 255 inclusive)"); + case IEBADTOS: + snprintf(errstr, len, "bad TOS value (must be between 0 and 255 inclusive)"); + break; + case IESETCLIENTAUTH: + snprintf(errstr, len, "you must specify a username, password, and path to a valid RSA public key"); + break; + case IESETSERVERAUTH: + snprintf(errstr, len, "you must specify a path to a valid RSA private key and a user credential file"); + break; + case IEBADFORMAT: + snprintf(errstr, len, "bad format specifier (valid formats are in the set [kmgtKMGT])"); break; + case IEBADPORT: + snprintf(errstr, len, "port number must be between 1 and 65535 inclusive"); + break; case IEMSS: snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS); break; @@ -168,13 +218,18 @@ iperf_strerror(int i_errno) snprintf(errstr, len, "test initialization failed"); perr = 1; break; + case IEAUTHTEST: + snprintf(errstr, len, "test authorization failed"); + break; case IELISTEN: snprintf(errstr, len, "unable to start listener for connections"); + herr = 1; perr = 1; break; case IECONNECT: snprintf(errstr, len, "unable to connect to server"); perr = 1; + herr = 1; break; case IEACCEPT: snprintf(errstr, len, "unable to accept connection from client"); @@ -302,6 +357,7 @@ iperf_strerror(int i_errno) break; case IESTREAMLISTEN: snprintf(errstr, len, "unable to start stream listener"); + herr = 1; perr = 1; break; case IESTREAMCONNECT: @@ -359,14 +415,29 @@ iperf_strerror(int i_errno) snprintf(errstr, len, "unable to set socket pacing"); perr = 1; break; + case IESETBUF2: + snprintf(errstr, len, "socket buffer size not set correctly"); + break; + case IEREVERSEBIDIR: + snprintf(errstr, len, "cannot be both reverse and bidirectional"); + break; + case IETOTALRATE: + snprintf(errstr, len, "total required bandwidth is larger than server limit"); + break; + default: + snprintf(errstr, len, "int_errno=%d", int_errno); + perr = 1; + break; } + /* Append the result of strerror() or gai_strerror() if appropriate */ if (herr || perr) strncat(errstr, ": ", len - strlen(errstr) - 1); - if (h_errno && herr) { - strncat(errstr, hstrerror(h_errno), len - strlen(errstr) - 1); - } else if (errno && perr) { + if (errno && perr) strncat(errstr, strerror(errno), len - strlen(errstr) - 1); + else if (herr && gerror) { + strncat(errstr, gai_strerror(gerror), len - strlen(errstr) - 1); + gerror = 0; } return errstr;