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     char* host;
18     int port;
19     struct iperf_test *test;
20 
21     argv0 = strrchr( argv[0], '/' );
22     if ( argv0 != (char*) 0 )
23 	++argv0;
24     else
25 	argv0 = argv[0];
26 
27     if ( argc != 3 ) {
28 	fprintf( stderr, "usage: %s [host] [port]\n", argv0 );
29 	exit( EXIT_FAILURE );
30     }
31     host = argv[1];
32     port = atoi( argv[2] );
33 
34     test = iperf_new_test();
35     if ( test == NULL ) {
36 	fprintf( stderr, "%s: failed to create test\n", argv0 );
37 	exit( EXIT_FAILURE );
38     }
39     iperf_defaults( test );
40     iperf_set_verbose( test, 1 );
41 
42     iperf_set_test_role( test, 'c' );
43     iperf_set_test_server_hostname( test, host );
44     iperf_set_test_server_port( test, port );
45     /* iperf_set_test_reverse( test, 1 ); */
46     iperf_set_test_omit( test, 3 );
47     iperf_set_test_duration( test, 5 );
48     iperf_set_test_reporter_interval( test, 1 );
49     iperf_set_test_stats_interval( test, 1 );
50     /* iperf_set_test_json_output( test, 1 ); */
51 
52     if ( iperf_run_client( test ) < 0 ) {
53 	fprintf( stderr, "%s: error - %s\n", argv0, iperf_strerror( i_errno ) );
54 	exit( EXIT_FAILURE );
55     }
56 
57     if (iperf_get_test_json_output_string(test)) {
58 	fprintf(iperf_get_test_outfile(test), "%zd bytes of JSON emitted\n",
59 		strlen(iperf_get_test_json_output_string(test)));
60     }
61 
62     iperf_free_test( test );
63     exit( EXIT_SUCCESS );
64 }
65