--- embedaddon/iperf/src/iperf_error.c 2016/10/18 13:28:18 1.1.1.1 +++ embedaddon/iperf/src/iperf_error.c 2023/09/27 11:14:54 1.1.1.3 @@ -1,5 +1,5 @@ /* - * iperf, Copyright (c) 2014, 2015, 2016, The Regents of the University of + * iperf, Copyright (c) 2014-2022, 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,24 +33,46 @@ #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) { + else { + 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 +82,36 @@ 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); + if (test != NULL && test->json_output) { + if (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 +123,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 +132,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 +163,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 +221,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"); + snprintf(errstr, len, "unable to connect to server - server may have stopped running or use a different port, firewall issue, etc."); perr = 1; + herr = 1; break; case IEACCEPT: snprintf(errstr, len, "unable to accept connection from client"); @@ -201,14 +259,14 @@ iperf_strerror(int i_errno) snprintf(errstr, len, "control socket has closed unexpectedly"); break; case IEMESSAGE: - snprintf(errstr, len, "received an unknown control message"); + snprintf(errstr, len, "received an unknown control message (ensure other side is iperf3 and not iperf)"); break; case IESENDMESSAGE: - snprintf(errstr, len, "unable to send control message"); + snprintf(errstr, len, "unable to send control message - port may not be available, the other side may have stopped running, etc."); perr = 1; break; case IERECVMESSAGE: - snprintf(errstr, len, "unable to receive control message"); + snprintf(errstr, len, "unable to receive control message - port may not be available, the other side may have stopped running, etc."); perr = 1; break; case IESENDPARAMS: @@ -286,6 +344,21 @@ iperf_strerror(int i_errno) snprintf(errstr, len, "unable to set CPU affinity"); perr = 1; break; + case IERCVTIMEOUT: + snprintf(errstr, len, "receive timeout value is incorrect or not in range"); + perr = 1; + break; + case IESNDTIMEOUT: + snprintf(errstr, len, "send timeout value is incorrect or not in range"); + perr = 1; + break; + case IEUDPFILETRANSFER: + snprintf(errstr, len, "cannot transfer file using UDP"); + break; + case IERVRSONLYRCVTIMEOUT: + snprintf(errstr, len, "client receive timeout is valid only in receiving mode"); + perr = 1; + break; case IEDAEMON: snprintf(errstr, len, "unable to become a daemon"); perr = 1; @@ -302,6 +375,7 @@ iperf_strerror(int i_errno) break; case IESTREAMLISTEN: snprintf(errstr, len, "unable to start stream listener"); + herr = 1; perr = 1; break; case IESTREAMCONNECT: @@ -336,7 +410,7 @@ iperf_strerror(int i_errno) perr = 1; break; case IESETCONGESTION: - snprintf(errstr, len, "unable to set TCP_CONGESTION: " + snprintf(errstr, len, "unable to set TCP_CONGESTION: " "Supplied congestion control algorithm not supported on this host"); break; case IEPIDFILE: @@ -359,14 +433,54 @@ 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; + case IESKEWTHRESHOLD: + snprintf(errstr, len, "skew threshold must be a positive number"); + break; + case IEIDLETIMEOUT: + snprintf(errstr, len, "idle timeout parameter is not positive or larger than allowed limit"); + break; + case IEBINDDEV: + snprintf(errstr, len, "Unable to bind-to-device (check perror, maybe permissions?)"); + break; + case IEBINDDEVNOSUPPORT: + snprintf(errstr, len, "`%%` is not supported as system does not support bind to device"); + break; + case IEHOSTDEV: + snprintf(errstr, len, "host device name (ip%%) is supported (and required) only for IPv6 link-local address"); + break; + case IENOMSG: + snprintf(errstr, len, "idle timeout for receiving data"); + break; + case IESETDONTFRAGMENT: + snprintf(errstr, len, "unable to set IP Do-Not-Fragment flag"); + break; + case IESETUSERTIMEOUT: + snprintf(errstr, len, "unable to set TCP USER_TIMEOUT"); + perr = 1; + 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;