version 1.1.1.1, 2016/10/18 13:28:18
|
version 1.1.1.2, 2021/03/17 00:36:46
|
Line 1
|
Line 1
|
/* |
/* |
* 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 |
* California, through Lawrence Berkeley National Laboratory (subject |
* to receipt of any required approvals from the U.S. Dept. of |
* to receipt of any required approvals from the U.S. Dept. of |
* Energy). All rights reserved. |
* Energy). All rights reserved. |
Line 33
|
Line 33
|
#include "iperf.h" |
#include "iperf.h" |
#include "iperf_api.h" |
#include "iperf_api.h" |
|
|
|
int gerror; |
|
|
|
char iperf_timestrerr[100]; |
|
|
/* Do a printf to stderr. */ |
/* Do a printf to stderr. */ |
void |
void |
iperf_err(struct iperf_test *test, const char *format, ...) |
iperf_err(struct iperf_test *test, const char *format, ...) |
{ |
{ |
va_list argp; |
va_list argp; |
char str[1000]; |
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); |
va_start(argp, format); |
vsnprintf(str, sizeof(str), format, argp); |
vsnprintf(str, sizeof(str), format, argp); |
if (test != NULL && test->json_output && test->json_top != NULL) |
if (test != NULL && test->json_output && test->json_top != NULL) |
cJSON_AddStringToObject(test->json_top, "error", str); |
cJSON_AddStringToObject(test->json_top, "error", str); |
else |
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); |
fprintf(test->outfile, "iperf3: %s\n", str); |
} |
} |
else { |
else { |
|
if (ct) { |
|
fprintf(stderr, "%s", ct); |
|
} |
fprintf(stderr, "iperf3: %s\n", str); |
fprintf(stderr, "iperf3: %s\n", str); |
} |
} |
va_end(argp); |
va_end(argp); |
Line 60 iperf_errexit(struct iperf_test *test, const char *for
|
Line 81 iperf_errexit(struct iperf_test *test, const char *for
|
{ |
{ |
va_list argp; |
va_list argp; |
char str[1000]; |
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); |
va_start(argp, format); |
vsnprintf(str, sizeof(str), format, argp); |
vsnprintf(str, sizeof(str), format, argp); |
if (test != NULL && test->json_output && test->json_top != NULL) { |
if (test != NULL && test->json_output && test->json_top != NULL) { |
cJSON_AddStringToObject(test->json_top, "error", str); |
cJSON_AddStringToObject(test->json_top, "error", str); |
iperf_json_finish(test); |
iperf_json_finish(test); |
} else |
} 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); |
fprintf(test->outfile, "iperf3: %s\n", str); |
} |
} |
else { |
else { |
|
if (ct) { |
|
fprintf(stderr, "%s", ct); |
|
} |
fprintf(stderr, "iperf3: %s\n", str); |
fprintf(stderr, "iperf3: %s\n", str); |
} |
} |
va_end(argp); |
va_end(argp); |
Line 82 iperf_errexit(struct iperf_test *test, const char *for
|
Line 120 iperf_errexit(struct iperf_test *test, const char *for
|
int i_errno; |
int i_errno; |
|
|
char * |
char * |
iperf_strerror(int i_errno) | iperf_strerror(int int_errno) |
{ |
{ |
static char errstr[256]; |
static char errstr[256]; |
int len, perr, herr; |
int len, perr, herr; |
Line 91 iperf_strerror(int i_errno)
|
Line 129 iperf_strerror(int i_errno)
|
len = sizeof(errstr); |
len = sizeof(errstr); |
memset(errstr, 0, len); |
memset(errstr, 0, len); |
|
|
switch (i_errno) { | switch (int_errno) { |
case IENONE: |
case IENONE: |
snprintf(errstr, len, "no error"); |
snprintf(errstr, len, "no error"); |
break; |
break; |
Line 122 iperf_strerror(int i_errno)
|
Line 160 iperf_strerror(int i_errno)
|
case IEINTERVAL: |
case IEINTERVAL: |
snprintf(errstr, len, "invalid report interval (min = %g, max = %g seconds)", MIN_INTERVAL, MAX_INTERVAL); |
snprintf(errstr, len, "invalid report interval (min = %g, max = %g seconds)", MIN_INTERVAL, MAX_INTERVAL); |
break; |
break; |
case IEBIND: | case IEBIND: /* UNUSED */ |
snprintf(errstr, len, "--bind must be specified to use --cport"); |
snprintf(errstr, len, "--bind must be specified to use --cport"); |
break; |
break; |
case IEUDPBLOCKSIZE: |
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; |
break; |
case IEBADTOS: | case IEBADTOS: |
snprintf(errstr, len, "bad TOS value (must be between 0 and 255 inclusive)"); | 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; |
break; |
|
case IEBADPORT: |
|
snprintf(errstr, len, "port number must be between 1 and 65535 inclusive"); |
|
break; |
case IEMSS: |
case IEMSS: |
snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS); |
snprintf(errstr, len, "TCP MSS too large (maximum = %d bytes)", MAX_MSS); |
break; |
break; |
Line 168 iperf_strerror(int i_errno)
|
Line 218 iperf_strerror(int i_errno)
|
snprintf(errstr, len, "test initialization failed"); |
snprintf(errstr, len, "test initialization failed"); |
perr = 1; |
perr = 1; |
break; |
break; |
|
case IEAUTHTEST: |
|
snprintf(errstr, len, "test authorization failed"); |
|
break; |
case IELISTEN: |
case IELISTEN: |
snprintf(errstr, len, "unable to start listener for connections"); |
snprintf(errstr, len, "unable to start listener for connections"); |
|
herr = 1; |
perr = 1; |
perr = 1; |
break; |
break; |
case IECONNECT: |
case IECONNECT: |
snprintf(errstr, len, "unable to connect to server"); |
snprintf(errstr, len, "unable to connect to server"); |
perr = 1; |
perr = 1; |
|
herr = 1; |
break; |
break; |
case IEACCEPT: |
case IEACCEPT: |
snprintf(errstr, len, "unable to accept connection from client"); |
snprintf(errstr, len, "unable to accept connection from client"); |
Line 302 iperf_strerror(int i_errno)
|
Line 357 iperf_strerror(int i_errno)
|
break; |
break; |
case IESTREAMLISTEN: |
case IESTREAMLISTEN: |
snprintf(errstr, len, "unable to start stream listener"); |
snprintf(errstr, len, "unable to start stream listener"); |
|
herr = 1; |
perr = 1; |
perr = 1; |
break; |
break; |
case IESTREAMCONNECT: |
case IESTREAMCONNECT: |
Line 359 iperf_strerror(int i_errno)
|
Line 415 iperf_strerror(int i_errno)
|
snprintf(errstr, len, "unable to set socket pacing"); |
snprintf(errstr, len, "unable to set socket pacing"); |
perr = 1; |
perr = 1; |
break; |
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) |
if (herr || perr) |
strncat(errstr, ": ", len - strlen(errstr) - 1); |
strncat(errstr, ": ", len - strlen(errstr) - 1); |
if (h_errno && herr) { | if (errno && perr) |
strncat(errstr, hstrerror(h_errno), len - strlen(errstr) - 1); | |
} else if (errno && perr) { | |
strncat(errstr, strerror(errno), len - strlen(errstr) - 1); |
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; |
return errstr; |