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