diff --git a/src/iperf.h b/src/iperf.h index 6f43cb4..8e62e6d 100644 --- a/src/iperf.h +++ b/src/iperf.h @@ -199,6 +199,7 @@ enum IPERF_START = 15, IPERF_DONE = 16, ACCESS_DENIED = -1, + SERVER_ERROR = -2, }; #define SEC_TO_NS 1000000000 /* too big for enum on some platforms */ diff --git a/src/iperf_api.c b/src/iperf_api.c index 7d14a8f..f2d6f1e 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -673,7 +673,8 @@ parse_parameters(struct iperf_test *test) int iperf_exchange_parameters(struct iperf_test * test) { - int s; + int s, msg; + char state; if (test->role == 'c') { @@ -685,8 +686,24 @@ iperf_exchange_parameters(struct iperf_test * test) if (parse_parameters(test) < 0) return (-1); - if ((s = test->protocol->listen(test)) < 0) + if ((s = test->protocol->listen(test)) < 0) { + state = SERVER_ERROR; + if (Nwrite(test->ctrl_sck, &state, sizeof(state), Ptcp) < 0) { + i_errno = IESENDMESSAGE; + return (-1); + } + msg = htonl(i_errno); + if (Nwrite(test->ctrl_sck, &msg, sizeof(msg), Ptcp) < 0) { + i_errno = IECTRLWRITE; + return (-1); + } + msg = htonl(errno); + if (Nwrite(test->ctrl_sck, &msg, sizeof(msg), Ptcp) < 0) { + i_errno = IECTRLWRITE; + return (-1); + } return (-1); + } FD_SET(s, &test->read_set); test->max_fd = (s > test->max_fd) ? s : test->max_fd; test->prot_listener = s; diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c index 333477e..4685698 100644 --- a/src/iperf_client_api.c +++ b/src/iperf_client_api.c @@ -47,7 +47,7 @@ iperf_create_streams(struct iperf_test *test) int iperf_handle_message_client(struct iperf_test *test) { - int rval; + int rval, perr; if ((rval = read(test->ctrl_sck, &test->state, sizeof(char))) <= 0) { if (rval == 0) { @@ -93,6 +93,18 @@ iperf_handle_message_client(struct iperf_test *test) case ACCESS_DENIED: i_errno = IEACCESSDENIED; return (-1); + case SERVER_ERROR: + if (Nread(test->ctrl_sck, &i_errno, sizeof(i_errno), Ptcp) < 0) { + i_errno = IECTRLREAD; + return (-1); + } + i_errno = ntohl(i_errno); + if (Nread(test->ctrl_sck, &perr, sizeof(perr), Ptcp) < 0) { + i_errno = IECTRLREAD; + return (-1); + } + errno = ntohl(perr); + return (-1); default: i_errno = IEMESSAGE; return (-1);