1 #include "iperf_config.h"
2 
3 #include <stdio.h>
4 #include <stdlib.h>
5 #include <unistd.h>
6 #include <string.h>
7 #ifdef HAVE_STDINT_H
8 #include <stdint.h>
9 #endif
10 
11 #include <iperf_api.h>
12 
13 int
main(int argc,char ** argv)14 main( int argc, char** argv )
15 {
16     char* argv0;
17     int port;
18     struct iperf_test *test;
19     int consecutive_errors;
20 
21     argv0 = strrchr( argv[0], '/' );
22     if ( argv0 != (char*) 0 )
23 	++argv0;
24     else
25 	argv0 = argv[0];
26 
27     if ( argc != 2 ) {
28 	fprintf( stderr, "usage: %s [port]\n", argv0 );
29 	exit( EXIT_FAILURE );
30     }
31     port = atoi( argv[1] );
32 
33     test = iperf_new_test();
34     if ( test == NULL ) {
35 	fprintf( stderr, "%s: failed to create test\n", argv0 );
36 	exit( EXIT_FAILURE );
37     }
38     iperf_defaults( test );
39     iperf_set_verbose( test, 1 );
40     iperf_set_test_role( test, 's' );
41     iperf_set_test_server_port( test, port );
42 
43     consecutive_errors = 0;
44     for (;;) {
45 	if ( iperf_run_server( test ) < 0 ) {
46 	    fprintf( stderr, "%s: error - %s\n\n", argv0, iperf_strerror( i_errno ) );
47 	    ++consecutive_errors;
48 	    if (consecutive_errors >= 5) {
49 	        fprintf(stderr, "%s: too many errors, exiting\n", argv0);
50 		break;
51 	    }
52 	} else
53 	    consecutive_errors = 0;
54 	iperf_reset_test( test );
55     }
56 
57     iperf_free_test( test );
58     exit( EXIT_SUCCESS );
59 }
60