From 1c9c053c6caedc5c130f9310158ddf0c05eff930 Mon Sep 17 00:00:00 2001 From: sethdelliott Date: Fri, 25 Jun 2010 00:31:15 +0000 Subject: [PATCH] Updated code to make '-s' parameter a requirement while running server. Also added usage() and usage_long() functions for printing out iperf usage messages. --- src/iperf_api.c | 17 +++++--- src/iperf_api.h | 1 + src/iperf_server_api.c | 1 - src/locale.c | 91 +++++++++++++++++++----------------------- src/main.c | 32 ++++++--------- 5 files changed, 68 insertions(+), 74 deletions(-) diff --git a/src/iperf_api.c b/src/iperf_api.c index e2f0d27..a2ab5c2 100644 --- a/src/iperf_api.c +++ b/src/iperf_api.c @@ -43,10 +43,18 @@ jmp_buf env; /* to handle longjmp on signal */ /*************************************************************/ -/* - * check to see if client has sent the requested number of bytes to the - * server yet - */ +void +usage() +{ + fprintf(stderr, usage_short); +} + +void +usage_long() +{ + fprintf(stderr, usage_long1); + fprintf(stderr, usage_long2); +} /* * XXX: should probably just compute this as we go and store it in the @@ -536,7 +544,6 @@ void iperf_defaults(struct iperf_test * testp) { testp->protocol = Ptcp; - testp->role = 's'; testp->duration = DURATION; testp->server_port = PORT; testp->ctrl_sck = -1; diff --git a/src/iperf_api.h b/src/iperf_api.h index a7ea09e..600b403 100644 --- a/src/iperf_api.h +++ b/src/iperf_api.h @@ -136,6 +136,7 @@ int iperf_client_end(struct iperf_test *); int iperf_send(struct iperf_test *); int iperf_recv(struct iperf_test *); void sig_handler(int); +void usage(); #endif diff --git a/src/iperf_server_api.c b/src/iperf_server_api.c index 0ee470a..25c4c43 100644 --- a/src/iperf_server_api.c +++ b/src/iperf_server_api.c @@ -80,7 +80,6 @@ iperf_server_listen(struct iperf_test *test) perror("netannounce test->listener"); return -1; } - setnonblocking(test->listener); printf("-----------------------------------------------------------\n"); printf("Server listening on %d\n", test->server_port); diff --git a/src/locale.c b/src/locale.c index 174da8f..fa4bd14 100644 --- a/src/locale.c +++ b/src/locale.c @@ -59,67 +59,60 @@ * usage * ------------------------------------------------------------------- */ -const char usage_short[] = "\ -Usage: %s [-s|-c host] [options]\n\ -Try `%s --help' for more information.\n"; +const char usage_short[] = "Usage: iperf [-s|-c host] [options]\n" + "Try `iperf --help' for more information.\n"; -const char usage_long1[] = "\ -Usage: iperf [-s|-c host] [options]\n\ - iperf [-h|--help] [-v|--version]\n\ -\n\ -Client/Server:\n\ - -f, --format [kmgKMG] format to report: Kbits, Mbits, KBytes, MBytes\n\ - -i, --interval # seconds between periodic bandwidth reports\n\ - -l, --len #[KMG] length of buffer to read or write (default 8 KB)\n\ - -m, --print_mss print TCP maximum segment size (MTU - TCP/IP header)\n\ - -p, --port # server port to listen on/connect to\n\ - -u, --udp use UDP rather than TCP\n\ - -w, --window #[KMG] TCP window size (socket buffer size)\n\ - -M, --mss # set TCP maximum segment size (MTU - 40 bytes)\n\ - -N, --nodelay set TCP no delay, disabling Nagle's Algorithm\n\ - -T, --tcpinfo Output detailed TCP info\n\ - -v, --version print version information and quit\n\ - -V, --verbose more verbose output \n\ - -d, --debug debug mode \n\ -Server specific:\n\ - -s, --server run in server mode" -; +const char usage_long1[] = "Usage: iperf [-s|-c host] [options]\n" + " iperf [-h|--help] [-v|--version]\n\n" + "Client/Server:\n" + " -f, --format [kmgKMG] format to report: Kbits, Mbits, KBytes, MBytes\n" + " -i, --interval # seconds between periodic bandwidth reports\n" + " -l, --len #[KMG] length of buffer to read or write (default 8 KB)\n" + " -m, --print_mss print TCP maximum segment size (MTU - TCP/IP header)\n" + " -p, --port # server port to listen on/connect to\n" + " -u, --udp use UDP rather than TCP\n" + " -w, --window #[KMG] TCP window size (socket buffer size)\n" + " -M, --mss # set TCP maximum segment size (MTU - 40 bytes)\n" + " -N, --nodelay set TCP no delay, disabling Nagle's Algorithm\n" + " -T, --tcpinfo Output detailed TCP info\n" + " -v, --version print version information and quit\n" + " -V, --verbose more verbose output\n" + " -d, --debug debug mode\n" + "Server specific:\n" + " -s, --server run in server mode\n" #ifdef NOT_YET_SUPPORTED /* still working on these */ - -S, --tos N set IP 'Type of Service' bit \n\ - -Z, --linux-congestion set TCP congestion control algorithm (Linux only)\n\ - -D, --daemon run the server as a daemon\n\n - -6, --IPv6Version Set the domain to IPv6\n\ + " -S, --tos N set IP 'Type of Service' bit\n" + " -Z, --linux-congestion set TCP congestion control algorithm (Linux only)\n" + " -D, --daemon run the server as a daemon\n" + " -6, --IPv6Version Set the domain to IPv6\n" #endif #ifdef OBSOLETE /* no current plan to support */ - -o, --output output the report or error message to this specified file\n\ - -B, --bind bind to , an interface or multicast address\n\ - -C, --compatibility for use with older versions does not sent extra msgs + " -o, --output output the report or error message to this specified file\n" + " -B, --bind bind to , an interface or multicast address\n" + " -C, --compatibility for use with older versions does not sent extra msgs\n" #ifdef WIN32 -" -R, --remove remove service in win32\n" + " -R, --remove remove service in win32\n" #endif #endif +; -const char usage_long2[] = "\ -\n\ -Client specific:\n\ - -b, --bandwidth #[KMG] for UDP, bandwidth to send at in bits/sec\n\ - (default 1 Mbit/sec, implies -u)\n\ - -c, --client run in client mode, connecting to \n\ - -n, --num #[KMG] number of bytes to transmit (instead of -t)\n\ - -t, --time # time in seconds to transmit for (default 10 secs)\n\ - -P, --parallel # number of parallel client threads to run\n\ - -T, --tcpinfo Output detailed TCP info (Linux and FreeBSD only)\n\ -\n\ -Miscellaneous:\n\ - -h, --help print this message and quit\n\ -\n\ -[KMG] Indicates options that support a K,M, or G suffix for kilo-, mega-, or giga- \n\ -\n\ -Report bugs to \n"; + +const char usage_long2[] = "Client specific:\n" + " -b, --bandwidth #[KMG] for UDP, bandwidth to send at in bits/sec\n" + " (default 1 Mbit/sec, implies -u)\n" + " -c, --client run in client mode, connecting to \n" + " -n, --num #[KMG] number of bytes to transmit (instead of -t)\n" + " -t, --time # time in seconds to transmit for (default 10 secs)\n" + " -P, --parallel # number of parallel client threads to run\n" + " -T, --tcpinfo Output detailed TCP info (Linux and FreeBSD only)\n\n" + "Miscellaneous:\n" + " -h, --help print this message and quit\n\n" + "[KMG] Indicates options that support a K,M, or G suffix for kilo-, mega-, or giga-\n\n" + "Report bugs to \n"; #ifdef OBSOLETE /* from old iperf: no longer supported. Add some of these back someday */ -d, --dualtest Do a bidirectional test simultaneously\n\ diff --git a/src/main.c b/src/main.c index a6cb899..37b83b8 100644 --- a/src/main.c +++ b/src/main.c @@ -132,8 +132,7 @@ main(int argc, char **argv) test->duration = atoi(optarg); if (test->duration > MAX_TIME) { fprintf(stderr, "\n Error: test duration too long. Maximum value = %d \n\n", (int)MAX_TIME); - fprintf(stderr, usage_long1); - fprintf(stderr, usage_long2); + usage_long(); exit(1); } break; @@ -146,8 +145,7 @@ main(int argc, char **argv) test->num_streams = atoi(optarg); if (test->num_streams > MAX_STREAMS) { fprintf(stderr, "\n Error: Number of parallel streams too large. Maximum value = %d \n\n", MAX_STREAMS); - fprintf(stderr, usage_long1); - fprintf(stderr, usage_long2); + usage_long(); exit(1); } break; @@ -158,8 +156,7 @@ main(int argc, char **argv) test->default_settings->blksize = unit_atoi(optarg); if (test->default_settings->blksize > MAX_BLOCKSIZE) { fprintf(stderr, "\n Error: Block size too large. Maximum value = %d \n\n", MAX_BLOCKSIZE); - fprintf(stderr, usage_long1); - fprintf(stderr, usage_long2); + usage_long(); exit(1); } break; @@ -167,8 +164,7 @@ main(int argc, char **argv) test->default_settings->socket_bufsize = unit_atof(optarg); if (test->default_settings->socket_bufsize > MAX_TCP_BUFFER) { fprintf(stderr, "\n Error: TCP buffer too large. Maximum value = %d \n\n", MAX_TCP_BUFFER); - fprintf(stderr, usage_long1); - fprintf(stderr, usage_long2); + usage_long(); exit(1); } break; @@ -179,8 +175,7 @@ main(int argc, char **argv) test->reporter_interval = atoi(optarg); if (test->stats_interval > MAX_INTERVAL) { fprintf(stderr, "\n Error: Report interval too large. Maximum value = %d \n\n", MAX_INTERVAL); - fprintf(stderr, usage_long1); - fprintf(stderr, usage_long2); + usage_long(); exit(1); } break; @@ -198,8 +193,7 @@ main(int argc, char **argv) test->default_settings->mss = atoi(optarg); if (test->default_settings->mss > MAX_MSS) { fprintf(stderr, "\n Error: MSS too large. Maximum value = %d \n\n", MAX_MSS); - fprintf(stderr, usage_long1); - fprintf(stderr, usage_long2); + usage_long(); exit(1); } break; @@ -212,19 +206,18 @@ main(int argc, char **argv) case 'V': test->verbose = 1; break; - case 'd': + case 'd': test->debug = 1; break; case 'R': test->reverse = 1; break; - case 'v': // print version and exit - fprintf( stderr, version ); - exit(1); + case 'v': + printf(version); + exit(0); case 'h': default: - fprintf(stderr, usage_long1); - fprintf(stderr, usage_long2); + usage_long(); exit(1); } } @@ -263,7 +256,8 @@ iperf_run(struct iperf_test * test) case 'c': return iperf_run_client(test); default: - return -1; + usage(); + return 0; } }