2013-03-12 05:03:36 +00:00
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#include <unistd.h>
|
|
|
|
#include <string.h>
|
|
|
|
#include <sysexits.h>
|
|
|
|
#include <stdint.h>
|
|
|
|
|
|
|
|
#include <iperf_api.h>
|
|
|
|
|
|
|
|
int
|
|
|
|
main( int argc, char** argv )
|
|
|
|
{
|
|
|
|
char* argv0;
|
|
|
|
int port;
|
|
|
|
struct iperf_test *test;
|
2013-06-07 22:28:05 +00:00
|
|
|
int consecutive_errors;
|
2013-03-12 05:03:36 +00:00
|
|
|
|
|
|
|
argv0 = strrchr( argv[0], '/' );
|
|
|
|
if ( argv0 != (char*) 0 )
|
|
|
|
++argv0;
|
|
|
|
else
|
|
|
|
argv0 = argv[0];
|
|
|
|
|
|
|
|
if ( argc != 2 ) {
|
|
|
|
fprintf( stderr, "usage: %s [port]\n", argv0 );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
port = atoi( argv[1] );
|
|
|
|
|
|
|
|
test = iperf_new_test();
|
|
|
|
if ( test == NULL ) {
|
|
|
|
fprintf( stderr, "%s: failed to create test\n", argv0 );
|
|
|
|
exit( EXIT_FAILURE );
|
|
|
|
}
|
|
|
|
iperf_defaults( test );
|
2013-08-29 18:38:20 +00:00
|
|
|
iperf_set_verbose( test, 1 );
|
2013-03-12 05:03:36 +00:00
|
|
|
iperf_set_test_role( test, 's' );
|
|
|
|
iperf_set_test_server_port( test, port );
|
|
|
|
|
2013-06-07 22:28:05 +00:00
|
|
|
consecutive_errors = 0;
|
2013-03-12 05:03:36 +00:00
|
|
|
for (;;) {
|
2013-06-07 22:28:05 +00:00
|
|
|
if ( iperf_run_server( test ) < 0 ) {
|
2013-03-12 05:03:36 +00:00
|
|
|
fprintf( stderr, "%s: error - %s\n\n", argv0, iperf_strerror( i_errno ) );
|
2013-06-07 22:28:05 +00:00
|
|
|
++consecutive_errors;
|
|
|
|
if (consecutive_errors >= 5) {
|
2014-01-03 19:24:06 +00:00
|
|
|
fprintf(stderr, "%s: too many errors, exiting\n", argv0);
|
2013-06-07 22:28:05 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
} else
|
|
|
|
consecutive_errors = 0;
|
2013-03-12 05:03:36 +00:00
|
|
|
iperf_reset_test( test );
|
|
|
|
}
|
|
|
|
|
|
|
|
iperf_free_test( test );
|
|
|
|
exit( EXIT_SUCCESS );
|
|
|
|
}
|