aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjef <jef@odev-vm-4.es.net>2012-09-28 16:00:14 -0700
committerjef <jef@odev-vm-4.es.net>2012-09-28 16:00:14 -0700
commit98ce496b1b75dcbfd4c21962fa4e5d898bf7930b (patch)
tree0b4c2c568f00fd32153d1d0495fa5638ec03a6f7 /src
parent56a97f9337a8557e68d48a7b5127be2199454dbd (diff)
downloadiperf3-98ce496b1b75dcbfd4c21962fa4e5d898bf7930b.tar.gz
Some changes to the iperf3 API to work with bwctl, mostly having to
do with what defs are in which include file. End result is we now have only one public include file, iperf_api.h.
Diffstat (limited to 'src')
-rw-r--r--src/Makefile.am7
-rw-r--r--src/Makefile.in7
-rw-r--r--src/iperf.h55
-rw-r--r--src/iperf_api.c243
-rw-r--r--src/iperf_api.h136
-rw-r--r--src/iperf_client_api.c30
-rw-r--r--src/iperf_client_api.h26
-rw-r--r--src/iperf_error.c2
-rw-r--r--src/iperf_error.h87
-rw-r--r--src/iperf_server_api.c9
-rw-r--r--src/iperf_server_api.h26
-rw-r--r--src/iperf_tcp.c1
-rw-r--r--src/iperf_udp.c1
-rw-r--r--src/iperf_util.c6
-rw-r--r--src/main.c3
-rw-r--r--src/t_timer.c1
-rw-r--r--src/tcp_info.c1
-rw-r--r--src/timer.c2
18 files changed, 401 insertions, 242 deletions
diff --git a/src/Makefile.am b/src/Makefile.am
index aa4429d..8a3ffca 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,7 +1,7 @@
lib_LIBRARIES = libiperf.a # Build and install a static iperf library
bin_PROGRAMS = iperf3 # Build and install an iperf binary
noinst_PROGRAMS = t_timer t_units t_uuid iperf3_profile # Build, but don't install the test programs and a profiled version of iperf3
-include_HEADERS = iperf_api.h iperf_error.h iperf_client_api.h iperf_server_api.h # Defines the headers that get installed with the program
+include_HEADERS = iperf_api.h # Defines the headers that get installed with the program
# Specify the source files and flags for the iperf library
@@ -10,11 +10,8 @@ libiperf_a_SOURCES = \
iperf_api.c \
iperf_api.h \
iperf_error.c \
- iperf_error.h \
- iperf_client_api.c \
- iperf_client_api.h \
+ iperf_client_api.c \
iperf_server_api.c \
- iperf_server_api.h \
iperf_tcp.c \
iperf_tcp.h \
iperf_udp.c \
diff --git a/src/Makefile.in b/src/Makefile.in
index cf0d257..4ed9bb3 100644
--- a/src/Makefile.in
+++ b/src/Makefile.in
@@ -231,7 +231,7 @@ sharedstatedir = @sharedstatedir@
sysconfdir = @sysconfdir@
target_alias = @target_alias@
lib_LIBRARIES = libiperf.a # Build and install a static iperf library
-include_HEADERS = iperf_api.h iperf_error.h iperf_client_api.h iperf_server_api.h # Defines the headers that get installed with the program
+include_HEADERS = iperf_api.h # Defines the headers that get installed with the program
# Specify the source files and flags for the iperf library
libiperf_a_SOURCES = \
@@ -239,11 +239,8 @@ libiperf_a_SOURCES = \
iperf_api.c \
iperf_api.h \
iperf_error.c \
- iperf_error.h \
- iperf_client_api.c \
- iperf_client_api.h \
+ iperf_client_api.c \
iperf_server_api.c \
- iperf_server_api.h \
iperf_tcp.c \
iperf_tcp.h \
iperf_udp.c \
diff --git a/src/iperf.h b/src/iperf.h
index f1a9246..9722292 100644
--- a/src/iperf.h
+++ b/src/iperf.h
@@ -48,7 +48,7 @@ struct iperf_stream_result
void *data;
};
-#define COOKIE_SIZE 37 /* size of an ascii uuid */
+#define COOKIE_SIZE 37 /* size of an ascii uuid */
struct iperf_settings
{
int domain; /* AF_INET or AF_INET6 */
@@ -173,52 +173,23 @@ struct iperf_test
void (*on_test_finish)(struct iperf_test *);
};
-enum
-{
- /* default settings */
- Ptcp = SOCK_STREAM,
- Pudp = SOCK_DGRAM,
- PORT = 5201, /* default port to listen on (don't use the same port as iperf2) */
- uS_TO_NS = 1000,
- SEC_TO_US = 1000000,
- RATE = 1024 * 1024, /* 1 Mbps */
- DURATION = 5, /* seconds */
- DEFAULT_UDP_BLKSIZE = 1450, /* 1 packet per ethernet frame, IPV6 too */
- DEFAULT_TCP_BLKSIZE = 128 * 1024, /* default read/write block size */
-
- /* other useful constants */
- TEST_START = 1,
- TEST_RUNNING = 2,
- RESULT_REQUEST = 3,
- TEST_END = 4,
- STREAM_BEGIN = 5,
- STREAM_RUNNING = 6,
- STREAM_END = 7,
- ALL_STREAMS_END = 8,
- PARAM_EXCHANGE = 9,
- CREATE_STREAMS = 10,
- SERVER_TERMINATE = 11,
- CLIENT_TERMINATE = 12,
- EXCHANGE_RESULTS = 13,
- DISPLAY_RESULTS = 14,
- IPERF_START = 15,
- IPERF_DONE = 16,
- ACCESS_DENIED = -1,
- SERVER_ERROR = -2,
-};
+/* default settings */
+#define PORT 5201 /* default port to listen on (don't use the same port as iperf2) */
+#define uS_TO_NS 1000
+#define SEC_TO_US 1000000
+#define RATE (1024 * 1024) /* 1 Mbps */
+#define DURATION 5 /* seconds */
-#define SEC_TO_NS 1000000000 /* too big for enum on some platforms */
+#define SEC_TO_NS 1000000000 /* too big for enum/const on some platforms */
#define MAX_RESULT_STRING 4096
-/* constants for command line arg sanity checks
-*/
-#define MB 1024 * 1024
-#define MAX_TCP_BUFFER 128 * MB
+/* constants for command line arg sanity checks */
+#define MB (1024 * 1024)
+#define MAX_TCP_BUFFER (128 * MB)
#define MAX_BLOCKSIZE MB
#define MAX_INTERVAL 60
#define MAX_TIME 3600
-#define MAX_MSS 9 * 1024
+#define MAX_MSS (9 * 1024)
#define MAX_STREAMS 128
-#endif
-
+#endif /* !__IPERF_H */
diff --git a/src/iperf_api.c b/src/iperf_api.c
index 375aa83..6d45bf6 100644
--- a/src/iperf_api.c
+++ b/src/iperf_api.c
@@ -34,7 +34,6 @@
#include "iperf_api.h"
#include "iperf_udp.h"
#include "iperf_tcp.h"
-#include "iperf_error.h"
#include "timer.h"
#include "units.h"
@@ -67,6 +66,142 @@ void warning(char *str)
}
+/************** Getter routines for some fields inside iperf_test *************/
+
+int
+iperf_get_test_duration( struct iperf_test* ipt )
+{
+ return ipt->duration;
+}
+
+uint64_t
+iperf_get_test_rate( struct iperf_test* ipt )
+{
+ return ipt->settings->rate;
+}
+
+char
+iperf_get_test_role( struct iperf_test* ipt )
+{
+ return ipt->role;
+}
+
+int
+iperf_get_test_blksize( struct iperf_test* ipt )
+{
+ return ipt->settings->blksize;
+}
+
+int
+iperf_get_test_socket_bufsize( struct iperf_test* ipt )
+{
+ return ipt->settings->socket_bufsize;
+}
+
+double
+iperf_get_test_reporter_interval( struct iperf_test* ipt )
+{
+ return ipt->reporter_interval;
+}
+
+double
+iperf_get_test_stats_interval( struct iperf_test* ipt )
+{
+ return ipt->stats_interval;
+}
+
+int
+iperf_get_test_num_streams( struct iperf_test* ipt )
+{
+ return ipt->num_streams;
+}
+
+int
+iperf_get_test_server_port( struct iperf_test* ipt )
+{
+ return ipt->server_port;
+}
+
+char*
+iperf_get_test_server_hostname( struct iperf_test* ipt )
+{
+ return ipt->server_hostname;
+}
+
+int
+iperf_get_test_protocol_id( struct iperf_test* ipt )
+{
+ return ipt->protocol->id;
+}
+
+/************** Setter routines for some fields inside iperf_test *************/
+
+void
+iperf_set_test_duration( struct iperf_test* ipt, int duration )
+{
+ ipt->duration = duration;
+}
+
+void
+iperf_set_test_reporter_interval( struct iperf_test* ipt, double reporter_interval )
+{
+ ipt->reporter_interval = reporter_interval;
+}
+
+void
+iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval )
+{
+ ipt->stats_interval = stats_interval;
+}
+
+void
+iperf_set_test_state( struct iperf_test* ipt, char state )
+{
+ ipt->state = state;
+}
+
+void
+iperf_set_test_blksize( struct iperf_test* ipt, int blksize )
+{
+ ipt->settings->blksize = blksize;
+}
+
+void
+iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate )
+{
+ ipt->settings->rate = rate;
+}
+
+void
+iperf_set_test_server_port( struct iperf_test* ipt, int server_port )
+{
+ ipt->server_port = server_port;
+}
+
+void
+iperf_set_test_socket_bufsize( struct iperf_test* ipt, int socket_bufsize )
+{
+ ipt->settings->socket_bufsize = socket_bufsize;
+}
+
+void
+iperf_set_test_num_streams( struct iperf_test* ipt, int num_streams )
+{
+ ipt->num_streams = num_streams;
+}
+
+void
+iperf_set_test_role( struct iperf_test* ipt, char role )
+{
+ ipt->role = role;
+}
+
+void
+iperf_set_test_server_hostname( struct iperf_test* ipt, char* server_hostname )
+{
+ ipt->server_hostname = server_hostname;
+}
+
/********************** Get/set test protocol structure ***********************/
struct protocol *
@@ -600,6 +735,14 @@ package_parameters(struct iperf_test *test)
}
+/*!!! Forwards for debugging getopt version. */
+int myopterr = 1;
+int myoptind = 0;
+int myoptopt;
+char *myoptarg;
+int mygetopt(int argc, char **argv, char *opts);
+
+
int
parse_parameters(struct iperf_test *test)
{
@@ -630,19 +773,19 @@ parse_parameters(struct iperf_test *test)
}
// XXX: Should we check for parameters exceeding maximum values here?
- while ((ch = getopt(n, params, "pt:n:m:uNP:Rw:l:b:S:")) != -1) {
+ while ((ch = mygetopt(n, params, "pt:n:m:uNP:Rw:l:b:S:")) != -1) {
switch (ch) {
case 'p':
set_protocol(test, Ptcp);
break;
case 't':
- test->duration = atoi(optarg);
+ test->duration = atoi(myoptarg);
break;
case 'n':
- test->settings->bytes = atoll(optarg);
+ test->settings->bytes = atoll(myoptarg);
break;
case 'm':
- test->settings->mss = atoi(optarg);
+ test->settings->mss = atoi(myoptarg);
break;
case 'u':
set_protocol(test, Pudp);
@@ -651,22 +794,22 @@ parse_parameters(struct iperf_test *test)
test->no_delay = 1;
break;
case 'P':
- test->num_streams = atoi(optarg);
+ test->num_streams = atoi(myoptarg);
break;
case 'R':
test->reverse = 1;
break;
case 'w':
- test->settings->socket_bufsize = atoi(optarg);
+ test->settings->socket_bufsize = atoi(myoptarg);
break;
case 'l':
- test->settings->blksize = atoi(optarg);
+ test->settings->blksize = atoi(myoptarg);
break;
case 'b':
- test->settings->rate = atoll(optarg);
+ test->settings->rate = atoll(myoptarg);
break;
case 'S':
- test->settings->tos = atoi(optarg);
+ test->settings->tos = atoi(myoptarg);
break;
}
}
@@ -900,7 +1043,7 @@ parse_results(struct iperf_test *test, char *results)
}
}
- for (strp; *strp; strp = strchr(strp, '\n')+1) {
+ for (; *strp; strp = strchr(strp, '\n')+1) {
sscanf(strp, "%d:%llu,%lf,%d,%d\n", &sid, &bytes_transferred, &jitter,
&cerror, &pcount);
SLIST_FOREACH(sp, &test->streams, streams)
@@ -1201,8 +1344,8 @@ iperf_print_intermediate(struct iperf_test *test)
char ubuf[UNIT_LEN];
char nbuf[UNIT_LEN];
struct iperf_stream *sp = NULL;
- iperf_size_t bytes = 0, bytes_sent = 0, bytes_received = 0;
- double start_time, end_time, avg_jitter;
+ iperf_size_t bytes = 0;
+ double start_time, end_time;
struct iperf_interval_results *ip = NULL;
SLIST_FOREACH(sp, &test->streams, streams) {
@@ -1239,10 +1382,10 @@ iperf_print_results (struct iperf_test *test)
char ubuf[UNIT_LEN];
char nbuf[UNIT_LEN];
struct iperf_stream *sp = NULL;
- iperf_size_t bytes = 0, bytes_sent = 0, bytes_received = 0;
+ iperf_size_t bytes_sent = 0, bytes_received = 0;
iperf_size_t total_sent = 0, total_received = 0;
double start_time, end_time, avg_jitter;
- struct iperf_interval_results *ip = NULL;
+
/* print final summary for all intervals */
printf(report_bw_header);
@@ -1250,6 +1393,7 @@ iperf_print_results (struct iperf_test *test)
start_time = 0.;
sp = SLIST_FIRST(&test->streams);
end_time = timeval_diff(&sp->result->start_time, &sp->result->end_time);
+ avg_jitter = 0;
SLIST_FOREACH(sp, &test->streams, streams) {
bytes_sent = sp->result->bytes_sent;
bytes_received = sp->result->bytes_received;
@@ -1326,15 +1470,6 @@ iperf_print_results (struct iperf_test *test)
void
iperf_reporter_callback(struct iperf_test * test)
{
- int total_packets = 0, lost_packets = 0;
- char ubuf[UNIT_LEN];
- char nbuf[UNIT_LEN];
- struct iperf_stream *sp = NULL;
- iperf_size_t bytes = 0, bytes_sent = 0, bytes_received = 0;
- iperf_size_t total_sent = 0, total_received = 0;
- double start_time, end_time, avg_jitter;
- struct iperf_interval_results *ip = NULL;
-
switch (test->state) {
case TEST_RUNNING:
case STREAM_RUNNING:
@@ -1517,3 +1652,63 @@ sig_handler(int sig)
longjmp(env, 1);
}
+
+/*!!!*/
+/* This is an old tiny version of getopt from Usenet mod.std.unix back
+** in 1985. I added it here to help debug a SEGV error that was occuring
+** inside the standard libc getopt(). However the SEGV does not occur
+** with this version. I'm sure the underlying bug is still lurking in
+** the code somewhere, but for now it is not being triggered.
+*/
+
+#define ERR(s, c) if(myopterr){\
+ char errbuf[2];\
+ errbuf[0] = c; errbuf[1] = '\n';\
+ (void) write(2, argv[0], (unsigned)strlen(argv[0]));\
+ (void) write(2, s, (unsigned)strlen(s));\
+ (void) write(2, errbuf, 2);}
+
+int
+mygetopt(int argc, char **argv, char *opts)
+{
+ static int sp = 1;
+ register int c;
+ register char *cp;
+
+ if(sp == 1) {
+ if(myoptind >= argc ||
+ argv[myoptind][0] != '-' || argv[myoptind][1] == '\0')
+ return(EOF);
+ else if(strcmp(argv[myoptind], "--") == 0) {
+ myoptind++;
+ return(EOF);
+ }
+ }
+ myoptopt = c = argv[myoptind][sp];
+ if(c == ':' || (cp=strchr(opts, c)) == NULL) {
+ ERR(": illegal option -- ", c);
+ if(argv[myoptind][++sp] == '\0') {
+ myoptind++;
+ sp = 1;
+ }
+ return('?');
+ }
+ if(*++cp == ':') {
+ if(argv[myoptind][sp+1] != '\0')
+ myoptarg = &argv[myoptind++][sp+1];
+ else if(++myoptind >= argc) {
+ ERR(": option requires an argument -- ", c);
+ sp = 1;
+ return('?');
+ } else
+ myoptarg = argv[myoptind++];
+ sp = 1;
+ } else {
+ if(argv[myoptind][++sp] == '\0') {
+ sp = 1;
+ myoptind++;
+ }
+ myoptarg = NULL;
+ }
+ return(c);
+}
diff --git a/src/iperf_api.h b/src/iperf_api.h
index 1e99380..8d78a90 100644
--- a/src/iperf_api.h
+++ b/src/iperf_api.h
@@ -11,7 +11,63 @@
#define __IPERF_API_H
#include <setjmp.h>
-#include "iperf.h"
+
+struct iperf_test;
+struct iperf_stream_result;
+struct iperf_interval_results;
+struct iperf_stream;
+
+/* default settings */
+#define Ptcp SOCK_STREAM
+#define Pudp SOCK_DGRAM
+#define DEFAULT_UDP_BLKSIZE 1450 /* 1 packet per ethernet frame, IPV6 too */
+#define DEFAULT_TCP_BLKSIZE (128 * 1024) /* default read/write block size */
+
+/* states */
+#define TEST_START 1
+#define TEST_RUNNING 2
+#define RESULT_REQUEST 3
+#define TEST_END 4
+#define STREAM_BEGIN 5
+#define STREAM_RUNNING 6
+#define STREAM_END 7
+#define ALL_STREAMS_END 8
+#define PARAM_EXCHANGE 9
+#define CREATE_STREAMS 10
+#define SERVER_TERMINATE 11
+#define CLIENT_TERMINATE 12
+#define EXCHANGE_RESULTS 13
+#define DISPLAY_RESULTS 14
+#define IPERF_START 15
+#define IPERF_DONE 16
+#define ACCESS_DENIED (-1)
+#define SERVER_ERROR (-2)
+
+/* Getter routines for some fields inside iperf_test. */
+int iperf_get_test_duration( struct iperf_test* ipt );
+char iperf_get_test_role( struct iperf_test* ipt );
+int iperf_get_test_blksize( struct iperf_test* ipt );
+uint64_t iperf_get_test_rate( struct iperf_test* ipt );
+int iperf_get_test_socket_bufsize( struct iperf_test* ipt );
+double iperf_get_test_reporter_interval( struct iperf_test* ipt );
+double iperf_get_test_stats_interval( struct iperf_test* ipt );
+int iperf_get_test_num_streams( struct iperf_test* ipt );
+int iperf_get_test_server_port( struct iperf_test* ipt );
+char* iperf_get_test_server_hostname( struct iperf_test* ipt );
+int iperf_get_test_protocol_id( struct iperf_test* ipt );
+
+/* Setter routines for some fields inside iperf_test. */
+void iperf_set_test_duration( struct iperf_test* ipt, int duration );
+void iperf_set_test_reporter_interval( struct iperf_test* ipt, double reporter_interval );
+void iperf_set_test_stats_interval( struct iperf_test* ipt, double stats_interval );
+void iperf_set_test_state( struct iperf_test* ipt, char state );
+void iperf_set_test_blksize( struct iperf_test* ipt, int blksize );
+void iperf_set_test_rate( struct iperf_test* ipt, uint64_t rate );
+void iperf_set_test_server_port( struct iperf_test* ipt, int server_port );
+void iperf_set_test_socket_bufsize( struct iperf_test* ipt, int socket_bufsize );
+void iperf_set_test_num_streams( struct iperf_test* ipt, int num_streams );
+void iperf_set_test_role( struct iperf_test* ipt, char role );
+void iperf_set_test_server_hostname( struct iperf_test* ipt, char* server_hostname );
/**
* exchange_parameters - handles the param_Exchange part for client
@@ -121,5 +177,81 @@ void iperf_on_test_finish(struct iperf_test *);
extern jmp_buf env;
-#endif
+/* Client routines. */
+int iperf_run_client(struct iperf_test *);
+int iperf_connect(struct iperf_test *);
+int iperf_create_streams(struct iperf_test *);
+int iperf_handle_message_client(struct iperf_test *);
+int iperf_client_end(struct iperf_test *);
+
+/* Server routines. */
+int iperf_run_server(struct iperf_test *);
+int iperf_server_listen(struct iperf_test *);
+int iperf_accept(struct iperf_test *);
+int iperf_handle_message_server(struct iperf_test *);
+void iperf_test_reset(struct iperf_test *);
+
+/* Error routines. */
+void iperf_error(char *);
+char *iperf_strerror(int);
+extern int i_errno;
+enum {
+ IENONE = 0, // No error
+ /* Parameter errors */
+ IESERVCLIENT = 1, // Iperf cannot be both server and client
+ IENOROLE = 2, // Iperf must either be a client (-c) or server (-s)
+ IECLIENTONLY = 3, // This option is client only
+ IEDURATION = 4, // test duration too long. Maximum value = %dMAX_TIME
+ IENUMSTREAMS = 5, // Number of parallel streams too large. Maximum value = %dMAX_STREAMS
+ IEBLOCKSIZE = 6, // Block size too large. Maximum value = %dMAX_BLOCKSIZE
+ IEBUFSIZE = 7, // Socket buffer size too large. Maximum value = %dMAX_TCP_BUFFER
+ IEINTERVAL = 8, // Report interval too large. Maxumum value = %dMAX_INTERVAL
+ IEMSS = 9, // MSS too large. Maximum value = %dMAX_MSS
+ /* Test errors */
+ IENEWTEST = 10, // Unable to create a new test (check perror)
+ IEINITTEST = 11, // Test initialization failed (check perror)
+ IELISTEN = 12, // Unable to listen for connections (check perror)
+ IECONNECT = 13, // Unable to connect to server (check herror/perror) [from netdial]
+ IEACCEPT = 14, // Unable to accept connection from client (check herror/perror)
+ IESENDCOOKIE = 15, // Unable to send cookie to server (check perror)
+ IERECVCOOKIE = 16, // Unable to receive cookie from client (check perror)
+ IECTRLWRITE = 17, // Unable to write to the control socket (check perror)
+ IECTRLREAD = 18, // Unable to read from the control socket (check perror)
+ IECTRLCLOSE = 19, // Control socket has closed unexpectedly
+ IEMESSAGE = 20, // Received an unknown message
+ IESENDMESSAGE = 21, // Unable to send control message to client/server (check perror)
+ IERECVMESSAGE = 22, // Unable to receive control message from client/server (check perror)
+ IESENDPARAMS = 23, // Unable to send parameters to server (check perror)
+ IERECVPARAMS = 24, // Unable to receive parameters from client (check perror)
+ IEPACKAGERESULTS = 25, // Unable to package results (check perror)
+ IESENDRESULTS = 26, // Unable to send results to client/server (check perror)
+ IERECVRESULTS = 27, // Unable to receive results from client/server (check perror)
+ IESELECT = 28, // Select failed (check perror)
+ IECLIENTTERM = 29, // The client has terminated
+ IESERVERTERM = 30, // The server has terminated
+ IEACCESSDENIED = 31, // The server is busy running a test. Try again later.
+ IESETNODELAY = 32, // Unable to set TCP NODELAY (check perror)
+ IESETMSS = 33, // Unable to set TCP MSS (check perror)
+ IESETBUF = 34, // Unable to set socket buffer size (check perror)
+ IESETTOS = 35, // Unable to set IP TOS (check perror)
+ IESETCOS = 36, // Unable to set IPv6 traffic class (check perror)
+ IEREUSEADDR = 37, // Unable to set reuse address on socket (check perror)
+ IENONBLOCKING = 38, // Unable to set socket to non-blocking (check perror)
+ IESETWINDOWSIZE = 39, // Unable to set socket window size (check perror)
+ IEPROTOCOL = 40, // Protocol does not exist
+ /* Stream errors */
+ IECREATESTREAM = 41, // Unable to create a new stream (check herror/perror)
+ IEINITSTREAM = 42, // Unable to initialize stream (check herror/perror)
+ IESTREAMLISTEN = 43, // Unable to start stream listener (check perror)
+ IESTREAMCONNECT = 44, // Unable to connect stream (check herror/perror)
+ IESTREAMACCEPT = 45, // Unable to accepte stream connection (check perror)
+ IESTREAMWRITE = 46, // Unable to write to stream socket (check perror)
+ IESTREAMREAD = 47, // Unable to read from stream (check perror)
+ IESTREAMCLOSE = 48, // Stream has closed unexpectedly
+ IESTREAMID = 49, // Stream has invalid ID
+ /* Timer errors */
+ IENEWTIMER = 50, // Unable to create new timer (check perror)
+ IEUPDATETIMER = 51, // Unable to update timer (check perror)
+};
+#endif /* !__IPERF_API_H */
diff --git a/src/iperf_client_api.c b/src/iperf_client_api.c
index ae9ab5a..c065b1d 100644
--- a/src/iperf_client_api.c
+++ b/src/iperf_client_api.c
@@ -15,11 +15,10 @@
#include <sys/types.h>
#include <sys/select.h>
#include <sys/uio.h>
+#include <arpa/inet.h>
#include "iperf.h"
#include "iperf_api.h"
-#include "iperf_client_api.h"
-#include "iperf_error.h"
#include "iperf_util.h"
#include "net.h"
#include "timer.h"
@@ -69,24 +68,28 @@ iperf_handle_message_client(struct iperf_test *test)
switch (test->state) {
case PARAM_EXCHANGE:
- if (iperf_exchange_parameters(test) < 0)
+ if (iperf_exchange_parameters(test) < 0) {
return (-1);
+ }
if (test->on_connect)
test->on_connect(test);
break;
case CREATE_STREAMS:
- if (iperf_create_streams(test) < 0)
+ if (iperf_create_streams(test) < 0) {
return (-1);
+ }
break;
case TEST_START:
- if (iperf_init_test(test) < 0)
+ if (iperf_init_test(test) < 0) {
return (-1);
+ }
break;
case TEST_RUNNING:
break;
case EXCHANGE_RESULTS:
- if (iperf_exchange_results(test) < 0)
+ if (iperf_exchange_results(test) < 0) {
return (-1);
+ }
break;
case DISPLAY_RESULTS:
if (test->on_test_finish)
@@ -204,20 +207,23 @@ iperf_run_client(struct iperf_test * test)
return (-1);
} else if (result > 0) {
if (FD_ISSET(test->ctrl_sck, &temp_read_set)) {
- if (iperf_handle_message_client(test) < 0)
+ if (iperf_handle_message_client(test) < 0) {
return (-1);
+ }
FD_CLR(test->ctrl_sck, &temp_read_set);
}
if (test->state == TEST_RUNNING) {
if (test->reverse) {
// Reverse mode. Client receives.
- if (iperf_recv(test) < 0)
+ if (iperf_recv(test) < 0) {
return (-1);
+ }
} else {
// Regular mode. Client sends.
- if (iperf_send(test) < 0)
+ if (iperf_send(test) < 0) {
return (-1);
+ }
}
/* Perform callbacks */
@@ -225,15 +231,17 @@ iperf_run_client(struct iperf_test * test)
test->stats_callback(test);
sec = (time_t) test->stats_interval;
usec = (test->stats_interval - sec) * SEC_TO_US;
- if (update_timer(test->stats_timer, sec, usec) < 0)
+ if (update_timer(test->stats_timer, sec, usec) < 0) {
return (-1);
+ }
}
if (timer_expired(test->reporter_timer)) {
test->reporter_callback(test);
sec = (time_t) test->reporter_interval;
usec = (test->reporter_interval - sec) * SEC_TO_US;
- if (update_timer(test->reporter_timer, sec, usec) < 0)
+ if (update_timer(test->reporter_timer, sec, usec) < 0) {
return (-1);
+ }
}
/* Send TEST_END if all data has been sent or timer expired */
diff --git a/src/iperf_client_api.h b/src/iperf_client_api.h
deleted file mode 100644
index c17c447..0000000
--- a/src/iperf_client_api.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2009-2011, 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.
- *
- * This code is distributed under a BSD style license, see the LICENSE file
- * for complete information.
- */
-
-#ifndef __IPERF_CLIENT_API_H
-#define __IPERF_CLIENT_API_H
-
-#include "iperf.h"
-
-int iperf_run_client(struct iperf_test *);
-
-int iperf_connect(struct iperf_test *);
-
-int iperf_create_streams(struct iperf_test *);
-
-int iperf_handle_message_client(struct iperf_test *);
-
-int iperf_client_end(struct iperf_test *);
-
-#endif
-
diff --git a/src/iperf_error.c b/src/iperf_error.c
index d097a92..1528c8b 100644
--- a/src/iperf_error.c
+++ b/src/iperf_error.c
@@ -12,7 +12,7 @@
#include <netdb.h>
#include <string.h>
#include "iperf.h"
-#include "iperf_error.h"
+#include "iperf_api.h"
int i_errno;
diff --git a/src/iperf_error.h b/src/iperf_error.h
deleted file mode 100644
index 1f5f834..0000000
--- a/src/iperf_error.h
+++ /dev/null
@@ -1,87 +0,0 @@
-/*
- * Copyright (c) 2009-2011, 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.
- *
- * This code is distributed under a BSD style license, see the LICENSE file
- * for complete information.
- */
-
-/* iperf_error.h
- *
- * Iperf error handling
- */
-
-#ifndef __IPERF_ERROR_H
-#define __IPERF_ERROR_H
-
-void iperf_error(char *);
-
-char *iperf_strerror(int);
-
-extern int i_errno;
-
-enum {
- IENONE = 0, // No error
-
- /* Parameter errors */
- IESERVCLIENT = 1, // Iperf cannot be both server and client
- IENOROLE = 2, // Iperf must either be a client (-c) or server (-s)
- IECLIENTONLY = 3, // This option is client only
- IEDURATION = 4, // test duration too long. Maximum value = %dMAX_TIME
- IENUMSTREAMS = 5, // Number of parallel streams too large. Maximum value = %dMAX_STREAMS
- IEBLOCKSIZE = 6, // Block size too large. Maximum value = %dMAX_BLOCKSIZE
- IEBUFSIZE = 7, // Socket buffer size too large. Maximum value = %dMAX_TCP_BUFFER
- IEINTERVAL = 8, // Report interval too large. Maxumum value = %dMAX_INTERVAL
- IEMSS = 9, // MSS too large. Maximum value = %dMAX_MSS
-
- /* Test errors */
- IENEWTEST = 10, // Unable to create a new test (check perror)
- IEINITTEST = 11, // Test initialization failed (check perror)
- IELISTEN = 12, // Unable to listen for connections (check perror)
- IECONNECT = 13, // Unable to connect to server (check herror/perror) [from netdial]
- IEACCEPT = 14, // Unable to accept connection from client (check herror/perror)
- IESENDCOOKIE = 15, // Unable to send cookie to server (check perror)
- IERECVCOOKIE = 16, // Unable to receive cookie from client (check perror)
- IECTRLWRITE = 17, // Unable to write to the control socket (check perror)
- IECTRLREAD = 18, // Unable to read from the control socket (check perror)
- IECTRLCLOSE = 19, // Control socket has closed unexpectedly
- IEMESSAGE = 20, // Received an unknown message
- IESENDMESSAGE = 21, // Unable to send control message to client/server (check perror)
- IERECVMESSAGE = 22, // Unable to receive control message from client/server (check perror)
- IESENDPARAMS = 23, // Unable to send parameters to server (check perror)
- IERECVPARAMS = 24, // Unable to receive parameters from client (check perror)
- IEPACKAGERESULTS = 25, // Unable to package results (check perror)
- IESENDRESULTS = 26, // Unable to send results to client/server (check perror)
- IERECVRESULTS = 27, // Unable to receive results from client/server (check perror)
- IESELECT = 28, // Select failed (check perror)
- IECLIENTTERM = 29, // The client has terminated
- IESERVERTERM = 30, // The server has terminated
- IEACCESSDENIED = 31, // The server is busy running a test. Try again later.
- IESETNODELAY = 32, // Unable to set TCP NODELAY (check perror)
- IESETMSS = 33, // Unable to set TCP MSS (check perror)
- IESETBUF = 34, // Unable to set socket buffer size (check perror)
- IESETTOS = 35, // Unable to set IP TOS (check perror)
- IESETCOS = 36, // Unable to set IPv6 traffic class (check perror)
- IEREUSEADDR = 37, // Unable to set reuse address on socket (check perror)
- IENONBLOCKING = 38, // Unable to set socket to non-blocking (check perror)
- IESETWINDOWSIZE = 39, // Unable to set socket window size (check perror)
- IEPROTOCOL = 40, // Protocol does not exist
-
- /* Stream errors */
- IECREATESTREAM = 41, // Unable to create a new stream (check herror/perror)
- IEINITSTREAM = 42, // Unable to initialize stream (check herror/perror)
- IESTREAMLISTEN = 43, // Unable to start stream listener (check perror)
- IESTREAMCONNECT = 44, // Unable to connect stream (check herror/perror)
- IESTREAMACCEPT = 45, // Unable to accepte stream connection (check perror)
- IESTREAMWRITE = 46, // Unable to write to stream socket (check perror)
- IESTREAMREAD = 47, // Unable to read from stream (check perror)
- IESTREAMCLOSE = 48, // Stream has closed unexpectedly
- IESTREAMID = 49, // Stream has invalid ID
-
- /* Timer errors */
- IENEWTIMER = 50, // Unable to create new timer (check perror)
- IEUPDATETIMER = 51, // Unable to update timer (check perror)
-};
-
-#endif
diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c
index fe0661d..0c73c9c 100644
--- a/src/iperf_server_api.c
+++ b/src/iperf_server_api.c
@@ -32,11 +32,9 @@
#include <setjmp.h>
#include "iperf.h"
-#include "iperf_server_api.h"
#include "iperf_api.h"
#include "iperf_udp.h"
#include "iperf_tcp.h"
-#include "iperf_error.h"
#include "iperf_util.h"
#include "timer.h"
#include "net.h"
@@ -49,9 +47,6 @@
int
iperf_server_listen(struct iperf_test *test)
{
- char ubuf[UNIT_LEN];
- int x;
-
if((test->listener = netannounce(test->settings->domain, Ptcp, test->bind_address, test->server_port)) < 0) {
i_errno = IELISTEN;
return (-1);
@@ -72,6 +67,9 @@ iperf_server_listen(struct iperf_test *test)
// XXX: This code needs to be moved to after parameter exhange
/*
+ char ubuf[UNIT_LEN];
+ int x;
+
if (test->protocol->id == Ptcp) {
if (test->settings->socket_bufsize > 0) {
unit_snprintf(ubuf, UNIT_LEN, (double) x, 'A');
@@ -402,4 +400,3 @@ iperf_run_server(struct iperf_test *test)
return (0);
}
-
diff --git a/src/iperf_server_api.h b/src/iperf_server_api.h
deleted file mode 100644
index 96f8fdb..0000000
--- a/src/iperf_server_api.h
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
- * Copyright (c) 2009-2011, 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.
- *
- * This code is distributed under a BSD style license, see the LICENSE file
- * for complete information.
- */
-
-#ifndef __IPERF_SERVER_API_H
-#define __IPERF_SERVER_API_H
-
-#include "iperf.h"
-
-int iperf_run_server(struct iperf_test *);
-
-int iperf_server_listen(struct iperf_test *);
-
-int iperf_accept(struct iperf_test *);
-
-int iperf_handle_message_server(struct iperf_test *);
-
-void iperf_test_reset(struct iperf_test *);
-
-#endif
-
diff --git a/src/iperf_tcp.c b/src/iperf_tcp.c
index 90333cc..891c989 100644
--- a/src/iperf_tcp.c
+++ b/src/iperf_tcp.c
@@ -23,7 +23,6 @@
#include "iperf.h"
#include "iperf_api.h"
#include "iperf_tcp.h"
-#include "iperf_error.h"
#include "net.h"
diff --git a/src/iperf_udp.c b/src/iperf_udp.c
index 06809a4..7a6e4d9 100644
--- a/src/iperf_udp.c
+++ b/src/iperf_udp.c
@@ -23,7 +23,6 @@
#include "iperf.h"
#include "iperf_api.h"
#include "iperf_udp.h"
-#include "iperf_error.h"
#include "timer.h"
#include "net.h"
diff --git a/src/iperf_util.c b/src/iperf_util.c
index e78edc0..01b7a3c 100644
--- a/src/iperf_util.c
+++ b/src/iperf_util.c
@@ -15,8 +15,12 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <string.h>
#include <sys/select.h>
+#include <sys/types.h>
+#include <sys/time.h>
+#include <time.h>
#include <errno.h>
#include "config.h"
@@ -44,7 +48,7 @@ make_cookie(char *cookie)
/* Generate a string based on hostname, time, randomness, and filler. */
(void) gethostname(hostname, sizeof(hostname));
(void) gettimeofday(&tv, 0);
- (void) snprintf(temp, sizeof(temp), "%s.%d.%06d.%08lx%08lx.%s", hostname, tv.tv_sec, tv.tv_usec, (unsigned long int) random(), (unsigned long int) random(), "1234567890123456789012345678901234567890");
+ (void) snprintf(temp, sizeof(temp), "%s.%ld.%06ld.%08lx%08lx.%s", hostname, tv.tv_sec, tv.tv_usec, (unsigned long int) random(), (unsigned long int) random(), "1234567890123456789012345678901234567890");
/* Now truncate it to 36 bytes and terminate. */
memcpy(cookie, temp, 36);
diff --git a/src/main.c b/src/main.c
index 9cc1641..808b1c9 100644
--- a/src/main.c
+++ b/src/main.c
@@ -25,11 +25,8 @@
#include "iperf.h"
#include "iperf_api.h"
-#include "iperf_client_api.h"
-#include "iperf_server_api.h"
#include "units.h"
#include "locale.h"
-#include "iperf_error.h"
#include "net.h"
diff --git a/src/t_timer.c b/src/t_timer.c
index 09d565e..47ca18b 100644
--- a/src/t_timer.c
+++ b/src/t_timer.c
@@ -9,6 +9,7 @@
#include <stdio.h>
#include <stdlib.h>
+#include <unistd.h>
#include <sys/time.h>
#include "timer.h"
diff --git a/src/tcp_info.c b/src/tcp_info.c
index 883d743..3252573 100644
--- a/src/tcp_info.c
+++ b/src/tcp_info.c
@@ -34,6 +34,7 @@
#include <string.h>
#include <netinet/in.h>
+#include "iperf.h"
#include "iperf_api.h"
#include "locale.h"
diff --git a/src/timer.c b/src/timer.c
index c89a60a..537bdb6 100644
--- a/src/timer.c
+++ b/src/timer.c
@@ -18,7 +18,7 @@
#include <time.h>
#include "timer.h"
-#include "iperf_error.h"
+#include "iperf_api.h"
double
timeval_to_double(struct timeval * tv)