aboutsummaryrefslogtreecommitdiff
path: root/examples
diff options
context:
space:
mode:
authorJef Poskanzer <jef@mail.acme.com>2013-03-11 22:03:36 -0700
committerJef Poskanzer <jef@mail.acme.com>2013-03-11 22:03:36 -0700
commit3e58754281ea8c5b83e242d2d539afb3bfed5e69 (patch)
tree55a1d95b1a364e6c2d58668b49d4338fdcf36f9e /examples
parente96ab740935b0cb9701c09f8826d48ff99b02a91 (diff)
downloadiperf3-3e58754281ea8c5b83e242d2d539afb3bfed5e69.tar.gz
Added library man page and examples subdir.
Diffstat (limited to 'examples')
-rw-r--r--examples/Makefile18
-rw-r--r--examples/mic.c48
-rw-r--r--examples/mis.c46
3 files changed, 112 insertions, 0 deletions
diff --git a/examples/Makefile b/examples/Makefile
new file mode 100644
index 0000000..c9990a9
--- /dev/null
+++ b/examples/Makefile
@@ -0,0 +1,18 @@
+IPERFDIR = ..
+
+CC = gcc
+
+CFLAGS = -I$(IPERFDIR)/src
+LDFLAGS = -L$(IPERFDIR)/src
+LIBS = -liperf
+
+all: mic mis
+
+mic: mic.c $(IPERFDIR)/src/iperf_api.h $(IPERFDIR)/src/libiperf.a
+ $(CC) $(CFLAGS) mic.c $(LDFLAGS) $(LIBS) -o mic
+
+mis: mis.c $(IPERFDIR)/src/iperf_api.h $(IPERFDIR)/src/libiperf.a
+ $(CC) $(CFLAGS) mis.c $(LDFLAGS) $(LIBS) -o mis
+
+clean:
+ -rm -f mic mis *.o *.a a.out core core.* *.core
diff --git a/examples/mic.c b/examples/mic.c
new file mode 100644
index 0000000..a1195d7
--- /dev/null
+++ b/examples/mic.c
@@ -0,0 +1,48 @@
+#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;
+ char* host;
+ int port;
+ struct iperf_test *test;
+
+ argv0 = strrchr( argv[0], '/' );
+ if ( argv0 != (char*) 0 )
+ ++argv0;
+ else
+ argv0 = argv[0];
+
+ if ( argc != 3 ) {
+ fprintf( stderr, "usage: %s [host] [port]\n", argv0 );
+ exit( EXIT_FAILURE );
+ }
+ host = argv[1];
+ port = atoi( argv[2] );
+
+ test = iperf_new_test();
+ if ( test == NULL ) {
+ fprintf( stderr, "%s: failed to create test\n", argv0 );
+ exit( EXIT_FAILURE );
+ }
+ iperf_defaults( test );
+ iperf_set_test_role( test, 'c' );
+ iperf_set_test_server_hostname( test, host );
+ iperf_set_test_server_port( test, port );
+
+ if ( iperf_run_client( test ) < 0 ) {
+ fprintf( stderr, "%s: error - %s\n", argv0, iperf_strerror( i_errno ) );
+ exit( EXIT_FAILURE );
+ }
+
+ iperf_free_test( test );
+ exit( EXIT_SUCCESS );
+}
diff --git a/examples/mis.c b/examples/mis.c
new file mode 100644
index 0000000..211682d
--- /dev/null
+++ b/examples/mis.c
@@ -0,0 +1,46 @@
+#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;
+
+ 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 );
+ iperf_set_test_role( test, 's' );
+ iperf_set_test_server_port( test, port );
+
+ for (;;) {
+ if ( iperf_run_server( test ) < 0 )
+ fprintf( stderr, "%s: error - %s\n\n", argv0, iperf_strerror( i_errno ) );
+ iperf_reset_test( test );
+ }
+
+ iperf_free_test( test );
+ exit( EXIT_SUCCESS );
+}