1 /*---------------------------------------------------------------
2 * Copyright (c) 1999,2000,2001,2002,2003
3 * The Board of Trustees of the University of Illinois
5 *---------------------------------------------------------------
6 * Permission is hereby granted, free of charge, to any person
7 * obtaining a copy of this software (Iperf) and associated
8 * documentation files (the "Software"), to deal in the Software
9 * without restriction, including without limitation the
10 * rights to use, copy, modify, merge, publish, distribute,
11 * sublicense, and/or sell copies of the Software, and to permit
12 * persons to whom the Software is furnished to do
13 * so, subject to the following conditions:
16 * Redistributions of source code must retain the above
17 * copyright notice, this list of conditions and
18 * the following disclaimers.
21 * Redistributions in binary form must reproduce the above
22 * copyright notice, this list of conditions and the following
23 * disclaimers in the documentation and/or other materials
24 * provided with the distribution.
27 * Neither the names of the University of Illinois, NCSA,
28 * nor the names of its contributors may be used to endorse
29 * or promote products derived from this Software without
30 * specific prior written permission.
32 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
33 * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
34 * OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
35 * NONINFRINGEMENT. IN NO EVENT SHALL THE CONTIBUTORS OR COPYRIGHT
36 * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
37 * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
38 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE
39 * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
40 * ________________________________________________________________
41 * National Laboratory for Applied Network Research
42 * National Center for Supercomputing Applications
43 * University of Illinois at Urbana-Champaign
44 * http://www.ncsa.uiuc.edu
45 * ________________________________________________________________
48 * by Mark Gates <mgates@nlanr.net>
49 * & Ajay Tirumala <tirumala@ncsa.uiuc.edu>
50 * -------------------------------------------------------------------
51 * Stores and parses the initial values for all the global variables.
52 * -------------------------------------------------------------------
60 * ------------------------------------------------------------------- */
66 #include "Settings.hpp"
68 #include "SocketAddr.h"
72 #include "gnu_getopt.h"
74 void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings );
76 /* -------------------------------------------------------------------
77 * command line options
79 * The option struct essentially maps a long option name (--foobar)
80 * or environment variable ($FOOBAR) to its short option char (f).
81 * ------------------------------------------------------------------- */
82 #define LONG_OPTIONS()
84 const struct option long_options[] =
86 {"singleclient", no_argument, NULL, '1'},
87 {"dualtest", no_argument, NULL, '2'},
88 {"bandwidth", required_argument, NULL, 'b'},
89 {"client", required_argument, NULL, 'c'},
90 {"dccp", no_argument, NULL, 'd'},
91 {"format", required_argument, NULL, 'f'},
92 {"help", no_argument, NULL, 'h'},
93 {"interval", required_argument, NULL, 'i'},
94 {"mcast_iface",required_argument, NULL, 'j'},
95 {"len", required_argument, NULL, 'l'},
96 {"print_mss", no_argument, NULL, 'm'},
97 {"num", required_argument, NULL, 'n'},
98 {"output", required_argument, NULL, 'o'},
99 {"port", required_argument, NULL, 'p'},
100 {"tradeoff", no_argument, NULL, 'r'},
101 {"server", no_argument, NULL, 's'},
102 {"time", required_argument, NULL, 't'},
103 {"udp", no_argument, NULL, 'u'},
104 {"udplite", required_argument, NULL, 'u'},
105 {"version", no_argument, NULL, 'v'},
106 {"window", required_argument, NULL, 'w'},
107 {"reportexclude", required_argument, NULL, 'x'},
108 {"reportstyle",required_argument, NULL, 'y'},
110 // more esoteric options
111 {"algorithm", required_argument, NULL, 'A'},
112 {"bind", required_argument, NULL, 'B'},
113 {"compatibility", no_argument, NULL, 'C'},
114 {"daemon", no_argument, NULL, 'D'},
115 {"file_input", required_argument, NULL, 'F'},
116 {"stdin_input", no_argument, NULL, 'I'},
117 {"mss", required_argument, NULL, 'M'},
118 {"nodelay", no_argument, NULL, 'N'},
119 {"listenport", required_argument, NULL, 'L'},
120 {"parallel", required_argument, NULL, 'P'},
121 {"remove", no_argument, NULL, 'R'},
122 {"dscp", required_argument, NULL, 'S'},
123 {"ttl", required_argument, NULL, 'T'},
124 {"single_udp", no_argument, NULL, 'U'},
125 {"ipv6_domian", no_argument, NULL, 'V'},
126 {"suggest_win_size", no_argument, NULL, 'W'},
130 #define ENV_OPTIONS()
132 const struct option env_options[] =
134 {"IPERF_SINGLECLIENT", no_argument, NULL, '1'},
135 {"IPERF_DUALTEST", no_argument, NULL, '2'},
136 {"IPERF_BANDWIDTH", required_argument, NULL, 'b'},
137 {"IPERF_CLIENT", required_argument, NULL, 'c'},
138 {"IPERF_DCCP", no_argument, NULL, 'd'},
139 {"IPERF_FORMAT", required_argument, NULL, 'f'},
141 {"IPERF_INTERVAL", required_argument, NULL, 'i'},
142 {"IPERF_MCASTIFACE", required_argument, NULL, 'j'},
143 {"IPERF_LEN", required_argument, NULL, 'l'},
144 {"IPERF_PRINT_MSS", no_argument, NULL, 'm'},
145 {"IPERF_NUM", required_argument, NULL, 'n'},
146 {"IPERF_PORT", required_argument, NULL, 'p'},
147 {"IPERF_TRADEOFF", no_argument, NULL, 'r'},
148 {"IPERF_SERVER", no_argument, NULL, 's'},
149 {"IPERF_TIME", required_argument, NULL, 't'},
150 {"IPERF_UDP", no_argument, NULL, 'u'},
152 {"TCP_WINDOW_SIZE", required_argument, NULL, 'w'},
153 {"IPERF_REPORTEXCLUDE", required_argument, NULL, 'x'},
154 {"IPERF_REPORTSTYLE",required_argument, NULL, 'y'},
156 // more esoteric options
157 {"IPERF_CC", required_argument, NULL, 'A'},
158 {"IPERF_BIND", required_argument, NULL, 'B'},
159 {"IPERF_COMPAT", no_argument, NULL, 'C'},
160 {"IPERF_DAEMON", no_argument, NULL, 'D'},
161 {"IPERF_FILE_INPUT", required_argument, NULL, 'F'},
162 {"IPERF_STDIN_INPUT", no_argument, NULL, 'I'},
163 {"IPERF_MSS", required_argument, NULL, 'M'},
164 {"IPERF_NODELAY", no_argument, NULL, 'N'},
165 {"IPERF_LISTENPORT", required_argument, NULL, 'L'},
166 {"IPERF_PARALLEL", required_argument, NULL, 'P'},
167 {"IPERF_DSCP", required_argument, NULL, 'S'},
168 {"IPERF_TTL", required_argument, NULL, 'T'},
169 {"IPERF_SINGLE_UDP", no_argument, NULL, 'U'},
170 {"IPERF_IPV6_DOMAIN", no_argument, NULL, 'V'},
171 {"IPERF_SUGGEST_WIN_SIZE", required_argument, NULL, 'W'},
175 #define SHORT_OPTIONS()
177 const char short_options[] =
178 "12b::c:df:hi:j:l:mn:o:p:rst:u::vw:x:y:A:B:CDF:IJ:L:M:NP:RS:T:UV:W";
180 /* -------------------------------------------------------------------
182 * ------------------------------------------------------------------- */
185 const long kDefault_DgramRate = 1024 * 1024; // -u if set, 1 Mbit/sec
186 const int kDefault_UDPBufLen = 1470; // -u if set, read/write 1470 bytes
187 // 1470 bytes is small enough to be sending one packet per datagram on ethernet
189 // 1450 bytes is small enough to be sending one packet per datagram on ethernet
190 // **** with IPv6 ****
191 const int kDefault_DCCPBufLen = 1420; // -d
192 // old DCCPv4: MPS=1424; new DCCPv4: MPS=1440; new DCCPv6: MPS=1420 (above)
194 /* -------------------------------------------------------------------
195 * Initialize all settings to defaults.
196 * ------------------------------------------------------------------- */
198 void Settings_Initialize( thread_Settings *main ) {
199 // Everything defaults to zero or NULL with
200 // this memset. Only need to set non-zero values
202 memset( main, 0, sizeof(thread_Settings) );
203 main->mSock = INVALID_SOCKET;
204 //main->mSockAF = AF_UNSPEC
205 main->mReportMode = kReport_Default;
207 main->flags = FLAG_MODETIME | FLAG_STDOUT; // Default time and stdout
208 //main->mDgramRate = 0; // -b, ie. TCP mode
209 main->mProtocol = kProto_TCP; // -u / -d
210 //main->mHost = NULL; // -c, none, required for client
211 main->mMode = kTest_Normal; // -2, mMode == kTest_DualTest
212 main->mFormat = 'a'; // -f, adaptive bits
214 //main->mBufLenSet = false; // -l,
215 main->mBufLen = 8 * 1024; // -l, 8 Kbyte
216 //main->mInterval = 0; // -i, ie. no periodic bw reports
217 //main->mPrintMSS = false; // -m, don't print MSS
218 // mAmount is time also // -n, N/A
219 //main->mOutputFileName = NULL; // -o, filename
220 main->mPort = 5001; // -p, ttcp port
221 // mMode = kTest_Normal; // -r, mMode == kTest_TradeOff
222 main->mThreadMode = kMode_Unknown; // -s, or -c, none
223 main->mAmount = 1000; // -t, 10 seconds
224 // mDgramRate // -u, N/A, see kDefault_DgramRate
225 // skip version // -v,
226 //main->mWinSize = 0; // -w, ie. don't set window
228 // more esoteric options
229 //main->mLocalhost = NULL; // -B, bind address - none
230 //main->mCompat = false; // -C, run in Compatibility mode
231 //main->mDaemon = false; // -D, run as a daemon
232 //main->mFileInput = false; // -F,
233 //main->mFileName = NULL; // -F, filename
234 //main->mStdin = false; // -I, default not stdin
235 //main->mMcastIface = 0; // -J, default: host chooses interface
236 //main->mListenPort = 0; // -L, listen port
237 //main->mMSS = 0; // -M, ie. don't set MSS
238 //main->mNodelay = false; // -N, don't set nodelay
239 //main->mThreads = 0; // -P,
240 //main->mRemoveService = false; // -R,
241 //main->mTOS = 0; // -S, ie. don't set type of service
242 main->mTTL = 1; // -T, link-local TTL
243 //main->mDomain = kMode_IPv4; // -V,
244 //main->mSuggestWin = false; // -W, Suggest the window size.
248 void Settings_Copy( thread_Settings *from, thread_Settings **into ) {
249 *into = new thread_Settings;
250 memcpy( *into, from, sizeof(thread_Settings) );
251 if ( from->mHost != NULL ) {
252 (*into)->mHost = new char[ strlen(from->mHost) + 1];
253 strcpy( (*into)->mHost, from->mHost );
255 if ( from->mOutputFileName != NULL ) {
256 (*into)->mOutputFileName = new char[ strlen(from->mOutputFileName) + 1];
257 strcpy( (*into)->mOutputFileName, from->mOutputFileName );
259 if ( from->mLocalhost != NULL ) {
260 (*into)->mLocalhost = new char[ strlen(from->mLocalhost) + 1];
261 strcpy( (*into)->mLocalhost, from->mLocalhost );
263 if ( from->mFileName != NULL ) {
264 (*into)->mFileName = new char[ strlen(from->mFileName) + 1];
265 strcpy( (*into)->mFileName, from->mFileName );
267 // Zero out certain entries
268 (*into)->mTID = thread_zeroid();
269 (*into)->runNext = NULL;
270 (*into)->runNow = NULL;
273 /* -------------------------------------------------------------------
274 * Delete memory: Does not clean up open file pointers or ptr_parents
275 * ------------------------------------------------------------------- */
277 void Settings_Destroy( thread_Settings *mSettings) {
278 DELETE_ARRAY( mSettings->mHost );
279 DELETE_ARRAY( mSettings->mLocalhost );
280 DELETE_ARRAY( mSettings->mFileName );
281 DELETE_ARRAY( mSettings->mOutputFileName );
282 DELETE_PTR( mSettings );
285 /* -------------------------------------------------------------------
286 * Parses settings from user's environment variables.
287 * ------------------------------------------------------------------- */
288 void Settings_ParseEnvironment( thread_Settings *mSettings ) {
292 while ( env_options[i].name != NULL ) {
293 theVariable = getenv( env_options[i].name );
294 if ( theVariable != NULL ) {
295 Settings_Interpret( env_options[i].val, theVariable, mSettings );
299 } // end ParseEnvironment
301 /* -------------------------------------------------------------------
302 * Parse settings from app's command line.
303 * ------------------------------------------------------------------- */
305 void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings ) {
308 gnu_getopt_long( argc, argv, short_options,
309 long_options, NULL )) != EOF ) {
310 Settings_Interpret( option, gnu_optarg, mSettings );
313 for ( int i = gnu_optind; i < argc; i++ ) {
314 fprintf( stderr, "%s: ignoring extra argument -- %s\n", argv[0], argv[i] );
316 } // end ParseCommandLine
318 /* -------------------------------------------------------------------
319 * Interpret individual options, either from the command line
320 * or from environment variables.
321 * ------------------------------------------------------------------- */
323 void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings ) {
327 case '1': // Single Client
328 setSingleClient( mExtSettings );
331 case '2': // Dual-test Mode
332 if ( mExtSettings->mThreadMode != kMode_Client ) {
333 fprintf( stderr, warn_invalid_server_option, option );
336 if ( isCompat( mExtSettings ) ) {
337 fprintf( stderr, warn_invalid_compatibility_option, option );
340 mExtSettings->mMode = kTest_DualTest;
342 fprintf( stderr, warn_invalid_single_threaded, option );
343 mExtSettings->mMode = kTest_TradeOff;
348 // This sets packet-oriented mode. The optional
349 // argument sets datagram bandwidth (as before).
350 // If not given, a default bandwith is used.
351 setPacketOriented(mExtSettings);
354 Settings_GetLowerCaseArg(optarg, outarg);
355 mExtSettings->mDgramRate = byte_atoi(outarg);
357 mExtSettings->mDgramRate = kDefault_DgramRate;
360 case 'c': // client mode w/ server host to connect to
361 mExtSettings->mHost = new char[ strlen( optarg ) + 1 ];
362 strcpy( mExtSettings->mHost, optarg );
364 if ( mExtSettings->mThreadMode == kMode_Unknown ) {
365 mExtSettings->mThreadMode = kMode_Client;
366 mExtSettings->mThreads = 1;
370 case 'd': // DCCP as transport
371 mExtSettings->mProtocol = kProto_DCCP;
373 // if -l has already been processed, mBufLenSet is true
374 // so don't overwrite that value.
375 if ( !isBuflenSet( mExtSettings ) )
376 mExtSettings->mBufLen = kDefault_DCCPBufLen;
380 case 'f': // format to print in
381 mExtSettings->mFormat = (*optarg);
384 case 'h': // print help and exit
387 case 'i': // specify interval between periodic bw reports
388 mExtSettings->mInterval = atof( optarg );
389 if ( mExtSettings->mInterval < 0.5 ) {
390 fprintf (stderr, report_interval_small, mExtSettings->mInterval);
391 mExtSettings->mInterval = 0.5;
396 case 'J': // multicast interface to join multicast address on
397 mExtSettings->mMcastIface = if_nametoindex(optarg);
398 if (!mExtSettings->mMcastIface)
399 die("Interface \"%s\" does not work for -j/-J.", optarg);
402 case 'l': // length of each buffer
403 Settings_GetUpperCaseArg(optarg,outarg);
404 mExtSettings->mBufLen = byte_atoi( outarg );
405 setBuflenSet( mExtSettings );
407 if ( !isPacketOriented( mExtSettings ) ) {
408 if ( mExtSettings->mBufLen < (int) sizeof( client_hdr ) &&
409 !isCompat( mExtSettings ) ) {
410 setCompat( mExtSettings );
411 fprintf( stderr, warn_implied_compatibility, option );
414 if ( mExtSettings->mBufLen < (int) sizeof( dgram_record ) ) {
415 mExtSettings->mBufLen = sizeof( dgram_record );
416 fprintf( stderr, warn_buffer_too_small, mExtSettings->mBufLen );
418 if ( !isCompat( mExtSettings ) &&
419 mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
420 + sizeof( client_hdr ) ) ) {
421 setCompat( mExtSettings );
422 fprintf( stderr, warn_implied_compatibility, option );
428 case 'm': // print TCP MSS
429 setPrintMSS( mExtSettings );
432 case 'n': // bytes of data
433 // amount mode (instead of time mode)
434 unsetModeTime( mExtSettings );
435 Settings_GetUpperCaseArg(optarg,outarg);
436 mExtSettings->mAmount = byte_atoi( outarg );
439 case 'o' : // output the report and other messages into the file
440 unsetSTDOUT( mExtSettings );
441 mExtSettings->mOutputFileName = new char[strlen(optarg)+1];
442 strcpy( mExtSettings->mOutputFileName, optarg);
445 case 'p': // server port
446 mExtSettings->mPort = atoi( optarg );
449 case 'r': // test mode tradeoff
450 if ( mExtSettings->mThreadMode != kMode_Client ) {
451 fprintf( stderr, warn_invalid_server_option, option );
454 if ( isCompat( mExtSettings ) ) {
455 fprintf( stderr, warn_invalid_compatibility_option, option );
458 mExtSettings->mMode = kTest_TradeOff;
461 case 's': // server mode
462 if ( mExtSettings->mThreadMode != kMode_Unknown ) {
463 fprintf( stderr, warn_invalid_client_option, option );
467 mExtSettings->mThreadMode = kMode_Listener;
470 case 't': // seconds to write for
471 // time mode (instead of amount mode)
472 setModeTime( mExtSettings );
473 mExtSettings->mAmount = (int) (atof( optarg ) * 100.0);
476 case 'u': // UDP(-Lite) instead of TCP
478 mExtSettings->mProtocol = kProto_UDPLITE;
479 // Set partial checksum coverage:
480 // - 0 means entire datagram,
481 // - 1..7 is illegal and will be rounded up to 8;
482 // - 8 and greater mean genuine partial coverage.
483 mExtSettings->cscov = atoi(optarg);
485 mExtSettings->mProtocol = kProto_UDP;
487 setPacketOriented(mExtSettings);
488 // if -b has already been processed, UDP rate will
489 // already be non-zero, so don't overwrite that value
490 if ( mExtSettings->mDgramRate == 0 )
491 mExtSettings->mDgramRate = kDefault_DgramRate;
493 // if -l has already been processed, mBufLenSet is true
494 // so don't overwrite that value.
495 if ( !isBuflenSet( mExtSettings ) ) {
496 mExtSettings->mBufLen = kDefault_UDPBufLen;
497 } else if ( mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
498 + sizeof( client_hdr ) ) &&
499 !isCompat( mExtSettings ) ) {
500 setCompat( mExtSettings );
501 fprintf( stderr, warn_implied_compatibility, option );
505 case 'v': // print version and exit
508 case 'w': // TCP window size or socket send-buffer size (UDP/DCCP)
509 Settings_GetUpperCaseArg(optarg,outarg);
510 mExtSettings->mWinSize = byte_atoi(outarg);
513 case 'x': // Limit Reports
514 while ( *optarg != '\0' ) {
518 setNoSettReport( mExtSettings );
522 setNoConnReport( mExtSettings );
526 setNoDataReport( mExtSettings );
530 setNoServReport( mExtSettings );
534 setNoMultReport( mExtSettings );
537 fprintf(stderr, warn_invalid_report, *optarg);
543 case 'y': // Reporting Style
547 mExtSettings->mReportMode = kReport_CSV;
550 fprintf( stderr, warn_invalid_report_style, optarg );
555 // more esoteric options
556 case 'A': // set TCP congestion control algorithm
557 mExtSettings->congAlgo = new char[ strlen( optarg ) + 1 ];
558 strcpy( mExtSettings->congAlgo, optarg );
561 case 'B': // specify bind address
562 mExtSettings->mLocalhost = new char[ strlen( optarg ) + 1 ];
563 strcpy( mExtSettings->mLocalhost, optarg );
566 case 'C': // Run in Compatibility Mode
567 setCompat( mExtSettings );
568 if ( mExtSettings->mMode != kTest_Normal ) {
569 fprintf( stderr, warn_invalid_compatibility_option,
570 ( mExtSettings->mMode == kTest_DualTest ?
572 mExtSettings->mMode = kTest_Normal;
576 case 'D': // Run as a daemon
577 setDaemon( mExtSettings );
580 case 'F' : // Get the input for the data stream from a file
581 if ( mExtSettings->mThreadMode != kMode_Client ) {
582 fprintf( stderr, warn_invalid_server_option, option );
586 setFileInput( mExtSettings );
587 mExtSettings->mFileName = new char[strlen(optarg)+1];
588 strcpy( mExtSettings->mFileName, optarg);
591 case 'I' : // Set the stdin as the input source
592 if ( mExtSettings->mThreadMode != kMode_Client ) {
593 fprintf( stderr, warn_invalid_server_option, option );
597 setFileInput( mExtSettings );
598 setSTDIN( mExtSettings );
599 mExtSettings->mFileName = new char[strlen("<stdin>")+1];
600 strcpy( mExtSettings->mFileName,"<stdin>");
603 case 'L': // Listen Port (bidirectional testing client-side)
604 if ( mExtSettings->mThreadMode != kMode_Client ) {
605 fprintf( stderr, warn_invalid_server_option, option );
609 mExtSettings->mListenPort = atoi( optarg );
612 case 'M': // specify TCP MSS (maximum segment size)
613 Settings_GetUpperCaseArg(optarg,outarg);
615 mExtSettings->mMSS = byte_atoi( outarg );
618 case 'N': // specify TCP nodelay option (disable Jacobson's Algorithm)
619 setNoDelay( mExtSettings );
622 case 'P': // number of client threads
624 mExtSettings->mThreads = atoi( optarg );
626 if ( mExtSettings->mThreadMode != kMode_Server ) {
627 fprintf( stderr, warn_invalid_single_threaded, option );
629 mExtSettings->mThreads = atoi( optarg );
635 setRemoveService( mExtSettings );
639 // Convert into IPv4/v6 6-bit DiffServ codepoint. If string
640 // - consists of six 0/1 digits, it is seen as binary number;
641 // - is preceded by `0x', it is interpreted as hex number;
642 // - is preceded by `0', it is interpreted as octal number;
643 // - otherwise it is interpreted as decimal number.
644 // The maximum possible 6-bit value is 252 (0xfc).
645 if ( strspn(optarg, "01") == 6 )
646 mExtSettings->mTOS = strtol(optarg, NULL, 2);
648 mExtSettings->mTOS = strtol(optarg, NULL, 0);
649 if ( mExtSettings->mTOS < 0 || mExtSettings->mTOS > 0xfc )
650 die("Invalid DiffServ codepoint %s", optarg);
651 mExtSettings->mTOS <<= 2;
654 case 'T': // time-to-live for multicast
655 mExtSettings->mTTL = atoi( optarg );
658 case 'V': // IP Domain: the optional ar
659 mExtSettings->mSockAF = AF_INET6;
660 if ( optarg && optarg[0] == '4' )
661 mExtSettings->mSockAF = AF_INET;
663 case 'U': // single threaded UDP server
664 setSingleUDP( mExtSettings );
668 setSuggestWin( mExtSettings );
669 fprintf( stderr, "The -W option is not available in this release\n");
672 default: // ignore unknown
677 void Settings_GetUpperCaseArg(const char *inarg, char *outarg) {
679 int len = strlen(inarg);
680 strcpy(outarg,inarg);
682 if ( (len > 0) && (inarg[len-1] >='a')
683 && (inarg[len-1] <= 'z') )
684 outarg[len-1]= outarg[len-1]+'A'-'a';
687 void Settings_GetLowerCaseArg(const char *inarg, char *outarg) {
689 int len = strlen(inarg);
690 strcpy(outarg,inarg);
692 if ( (len > 0) && (inarg[len-1] >='A')
693 && (inarg[len-1] <= 'Z') )
694 outarg[len-1]= outarg[len-1]-'A'+'a';
698 * Settings_GenerateListenerSettings
699 * Called to generate the settings to be passed to the Listener
700 * instance that will handle dual testings from the client side
701 * this should only return an instance if it was called on
702 * the thread_Settings instance generated from the command line
703 * for client side execution
705 void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener ) {
706 if ( !isCompat( client ) &&
707 (client->mMode == kTest_DualTest || client->mMode == kTest_TradeOff) ) {
708 *listener = new thread_Settings;
709 memcpy(*listener, client, sizeof( thread_Settings ));
710 setCompat( (*listener) );
711 unsetDaemon( (*listener) );
712 if ( client->mListenPort != 0 ) {
713 (*listener)->mPort = client->mListenPort;
715 (*listener)->mPort = client->mPort;
717 (*listener)->mFileName = NULL;
718 (*listener)->mHost = NULL;
719 (*listener)->mLocalhost = NULL;
720 (*listener)->mOutputFileName = NULL;
721 (*listener)->mMode = kTest_Normal;
722 (*listener)->mThreadMode = kMode_Listener;
723 if ( client->mHost != NULL ) {
724 (*listener)->mHost = new char[strlen( client->mHost ) + 1];
725 strcpy( (*listener)->mHost, client->mHost );
727 if ( client->mLocalhost != NULL ) {
728 (*listener)->mLocalhost = new char[strlen( client->mLocalhost ) + 1];
729 strcpy( (*listener)->mLocalhost, client->mLocalhost );
737 * Settings_GenerateSpeakerSettings
738 * Called to generate the settings to be passed to the Speaker
739 * instance that will handle dual testings from the server side
740 * this should only return an instance if it was called on
741 * the thread_Settings instance generated from the command line
742 * for server side execution. This should be an inverse operation
743 * of GenerateClientHdr.
745 void Settings_GenerateClientSettings( thread_Settings *server,
746 thread_Settings **client,
748 int flags = ntohl(hdr->flags);
749 if ( (flags & HEADER_VERSION1) != 0 ) {
750 *client = new thread_Settings;
751 memcpy(*client, server, sizeof( thread_Settings ));
752 setCompat( (*client) );
753 (*client)->mTID = thread_zeroid();
754 (*client)->mPort = (unsigned short) ntohl(hdr->mPort);
755 (*client)->mThreads = ntohl(hdr->numThreads);
756 if ( hdr->bufferlen != 0 ) {
757 (*client)->mBufLen = ntohl(hdr->bufferlen);
759 if ( hdr->mWinBand != 0 ) {
760 if ( isPacketOriented( server ) ) {
761 (*client)->mDgramRate = ntohl(hdr->mWinBand);
763 (*client)->mWinSize = ntohl(hdr->mWinBand);
766 (*client)->mAmount = ntohl(hdr->mAmount);
767 if ( ((*client)->mAmount & 0x80000000) > 0 ) {
768 setModeTime( (*client) );
769 (*client)->mAmount |= 0xFFFFFFFF00000000LL;
770 (*client)->mAmount = -(*client)->mAmount;
772 (*client)->mFileName = NULL;
773 (*client)->mHost = NULL;
774 (*client)->mLocalhost = NULL;
775 (*client)->mOutputFileName = NULL;
776 (*client)->mMode = ((flags & RUN_NOW) == 0 ?
777 kTest_TradeOff : kTest_DualTest);
778 (*client)->mThreadMode = kMode_Client;
779 if ( server->mLocalhost != NULL ) {
780 (*client)->mLocalhost = new char[strlen( server->mLocalhost ) + 1];
781 strcpy( (*client)->mLocalhost, server->mLocalhost );
783 (*client)->mHost = new char[REPORT_ADDRLEN];
784 SockAddr_name(&server->peer, (*client)->mHost, REPORT_ADDRLEN);
791 * Settings_GenerateClientHdr
792 * Called to generate the client header to be passed to the
793 * server that will handle dual testings from the server side
794 * This should be an inverse operation of GenerateSpeakerSettings
796 void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr ) {
797 if ( client->mMode != kTest_Normal ) {
798 hdr->flags = htonl(HEADER_VERSION1);
802 if ( isBuflenSet( client ) ) {
803 hdr->bufferlen = htonl(client->mBufLen);
807 if ( isPacketOriented( client ) ) {
808 hdr->mWinBand = htonl(client->mDgramRate);
810 hdr->mWinBand = htonl(client->mWinSize);
812 if ( client->mListenPort != 0 ) {
813 hdr->mPort = htonl(client->mListenPort);
815 hdr->mPort = htonl(client->mPort);
817 hdr->numThreads = htonl(client->mThreads);
818 if ( isModeTime( client ) ) {
819 hdr->mAmount = htonl(-(long)client->mAmount);
821 hdr->mAmount = htonl((long)client->mAmount);
822 hdr->mAmount &= htonl( 0x7FFFFFFF );
824 if ( client->mMode == kTest_DualTest ) {
825 hdr->flags |= htonl(RUN_NOW);