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 {"version", no_argument, NULL, 'v'},
105 {"window", required_argument, NULL, 'w'},
106 {"reportexclude", required_argument, NULL, 'x'},
107 {"reportstyle",required_argument, NULL, 'y'},
109 // more esoteric options
110 {"bind", required_argument, NULL, 'B'},
111 {"compatibility", no_argument, NULL, 'C'},
112 {"daemon", no_argument, NULL, 'D'},
113 {"file_input", required_argument, NULL, 'F'},
114 {"stdin_input", no_argument, NULL, 'I'},
115 {"mss", required_argument, NULL, 'M'},
116 {"nodelay", no_argument, NULL, 'N'},
117 {"listenport", required_argument, NULL, 'L'},
118 {"parallel", required_argument, NULL, 'P'},
119 {"remove", no_argument, NULL, 'R'},
120 {"tos", required_argument, NULL, 'S'},
121 {"ttl", required_argument, NULL, 'T'},
122 {"single_udp", no_argument, NULL, 'U'},
123 {"ipv6_domian", no_argument, NULL, 'V'},
124 {"suggest_win_size", no_argument, NULL, 'W'},
128 #define ENV_OPTIONS()
130 const struct option env_options[] =
132 {"IPERF_SINGLECLIENT", no_argument, NULL, '1'},
133 {"IPERF_DUALTEST", no_argument, NULL, '2'},
134 {"IPERF_BANDWIDTH", required_argument, NULL, 'b'},
135 {"IPERF_CLIENT", required_argument, NULL, 'c'},
136 {"IPERF_DCCP", no_argument, NULL, 'd'},
137 {"IPERF_FORMAT", required_argument, NULL, 'f'},
139 {"IPERF_INTERVAL", required_argument, NULL, 'i'},
140 {"IPERF_MCASTIFACE", required_argument, NULL, 'j'},
141 {"IPERF_LEN", required_argument, NULL, 'l'},
142 {"IPERF_PRINT_MSS", no_argument, NULL, 'm'},
143 {"IPERF_NUM", required_argument, NULL, 'n'},
144 {"IPERF_PORT", required_argument, NULL, 'p'},
145 {"IPERF_TRADEOFF", no_argument, NULL, 'r'},
146 {"IPERF_SERVER", no_argument, NULL, 's'},
147 {"IPERF_TIME", required_argument, NULL, 't'},
148 {"IPERF_UDP", no_argument, NULL, 'u'},
150 {"TCP_WINDOW_SIZE", required_argument, NULL, 'w'},
151 {"IPERF_REPORTEXCLUDE", required_argument, NULL, 'x'},
152 {"IPERF_REPORTSTYLE",required_argument, NULL, 'y'},
154 // more esoteric options
155 {"IPERF_BIND", required_argument, NULL, 'B'},
156 {"IPERF_COMPAT", no_argument, NULL, 'C'},
157 {"IPERF_DAEMON", no_argument, NULL, 'D'},
158 {"IPERF_FILE_INPUT", required_argument, NULL, 'F'},
159 {"IPERF_STDIN_INPUT", no_argument, NULL, 'I'},
160 {"IPERF_MSS", required_argument, NULL, 'M'},
161 {"IPERF_NODELAY", no_argument, NULL, 'N'},
162 {"IPERF_LISTENPORT", required_argument, NULL, 'L'},
163 {"IPERF_PARALLEL", required_argument, NULL, 'P'},
164 {"IPERF_TOS", required_argument, NULL, 'S'},
165 {"IPERF_TTL", required_argument, NULL, 'T'},
166 {"IPERF_SINGLE_UDP", no_argument, NULL, 'U'},
167 {"IPERF_IPV6_DOMAIN", no_argument, NULL, 'V'},
168 {"IPERF_SUGGEST_WIN_SIZE", required_argument, NULL, 'W'},
172 #define SHORT_OPTIONS()
174 const char short_options[] =
175 "12b::c:df:hi:j:l:mn:o:p:rst:uvw:x:y:B:CDF:IJ:L:M:NP:RS:T:UV:W";
177 /* -------------------------------------------------------------------
179 * ------------------------------------------------------------------- */
182 const long kDefault_DgramRate = 1024 * 1024; // -u if set, 1 Mbit/sec
183 const int kDefault_UDPBufLen = 1470; // -u if set, read/write 1470 bytes
184 // 1470 bytes is small enough to be sending one packet per datagram on ethernet
186 // 1450 bytes is small enough to be sending one packet per datagram on ethernet
187 // **** with IPv6 ****
188 const int kDefault_DCCPBufLen = 1420; // -d
189 // old DCCPv4: MPS=1424; new DCCPv4: MPS=1440; new DCCPv6: MPS=1420 (above)
191 /* -------------------------------------------------------------------
192 * Initialize all settings to defaults.
193 * ------------------------------------------------------------------- */
195 void Settings_Initialize( thread_Settings *main ) {
196 // Everything defaults to zero or NULL with
197 // this memset. Only need to set non-zero values
199 memset( main, 0, sizeof(thread_Settings) );
200 main->mSock = INVALID_SOCKET;
201 //main->mSockAF = AF_UNSPEC
202 main->mReportMode = kReport_Default;
204 main->flags = FLAG_MODETIME | FLAG_STDOUT; // Default time and stdout
205 //main->mDgramRate = 0; // -b, ie. TCP mode
206 main->mProtocol = kProto_TCP; // -u / -d
207 //main->mHost = NULL; // -c, none, required for client
208 main->mMode = kTest_Normal; // -2, mMode == kTest_DualTest
209 main->mFormat = 'a'; // -f, adaptive bits
211 //main->mBufLenSet = false; // -l,
212 main->mBufLen = 8 * 1024; // -l, 8 Kbyte
213 //main->mInterval = 0; // -i, ie. no periodic bw reports
214 //main->mPrintMSS = false; // -m, don't print MSS
215 // mAmount is time also // -n, N/A
216 //main->mOutputFileName = NULL; // -o, filename
217 main->mPort = 5001; // -p, ttcp port
218 // mMode = kTest_Normal; // -r, mMode == kTest_TradeOff
219 main->mThreadMode = kMode_Unknown; // -s, or -c, none
220 main->mAmount = 1000; // -t, 10 seconds
221 // mDgramRate // -u, N/A, see kDefault_DgramRate
222 // skip version // -v,
223 //main->mWinSize = 0; // -w, ie. don't set window
225 // more esoteric options
226 //main->mLocalhost = NULL; // -B, bind address - none
227 //main->mCompat = false; // -C, run in Compatibility mode
228 //main->mDaemon = false; // -D, run as a daemon
229 //main->mFileInput = false; // -F,
230 //main->mFileName = NULL; // -F, filename
231 //main->mStdin = false; // -I, default not stdin
232 //main->mMcastIface = 0; // -J, default: host chooses interface
233 //main->mListenPort = 0; // -L, listen port
234 //main->mMSS = 0; // -M, ie. don't set MSS
235 //main->mNodelay = false; // -N, don't set nodelay
236 //main->mThreads = 0; // -P,
237 //main->mRemoveService = false; // -R,
238 //main->mTOS = 0; // -S, ie. don't set type of service
239 main->mTTL = 1; // -T, link-local TTL
240 //main->mDomain = kMode_IPv4; // -V,
241 //main->mSuggestWin = false; // -W, Suggest the window size.
245 void Settings_Copy( thread_Settings *from, thread_Settings **into ) {
246 *into = new thread_Settings;
247 memcpy( *into, from, sizeof(thread_Settings) );
248 if ( from->mHost != NULL ) {
249 (*into)->mHost = new char[ strlen(from->mHost) + 1];
250 strcpy( (*into)->mHost, from->mHost );
252 if ( from->mOutputFileName != NULL ) {
253 (*into)->mOutputFileName = new char[ strlen(from->mOutputFileName) + 1];
254 strcpy( (*into)->mOutputFileName, from->mOutputFileName );
256 if ( from->mLocalhost != NULL ) {
257 (*into)->mLocalhost = new char[ strlen(from->mLocalhost) + 1];
258 strcpy( (*into)->mLocalhost, from->mLocalhost );
260 if ( from->mFileName != NULL ) {
261 (*into)->mFileName = new char[ strlen(from->mFileName) + 1];
262 strcpy( (*into)->mFileName, from->mFileName );
264 // Zero out certain entries
265 (*into)->mTID = thread_zeroid();
266 (*into)->runNext = NULL;
267 (*into)->runNow = NULL;
270 /* -------------------------------------------------------------------
271 * Delete memory: Does not clean up open file pointers or ptr_parents
272 * ------------------------------------------------------------------- */
274 void Settings_Destroy( thread_Settings *mSettings) {
275 DELETE_ARRAY( mSettings->mHost );
276 DELETE_ARRAY( mSettings->mLocalhost );
277 DELETE_ARRAY( mSettings->mFileName );
278 DELETE_ARRAY( mSettings->mOutputFileName );
279 DELETE_PTR( mSettings );
282 /* -------------------------------------------------------------------
283 * Parses settings from user's environment variables.
284 * ------------------------------------------------------------------- */
285 void Settings_ParseEnvironment( thread_Settings *mSettings ) {
289 while ( env_options[i].name != NULL ) {
290 theVariable = getenv( env_options[i].name );
291 if ( theVariable != NULL ) {
292 Settings_Interpret( env_options[i].val, theVariable, mSettings );
296 } // end ParseEnvironment
298 /* -------------------------------------------------------------------
299 * Parse settings from app's command line.
300 * ------------------------------------------------------------------- */
302 void Settings_ParseCommandLine( int argc, char **argv, thread_Settings *mSettings ) {
305 gnu_getopt_long( argc, argv, short_options,
306 long_options, NULL )) != EOF ) {
307 Settings_Interpret( option, gnu_optarg, mSettings );
310 for ( int i = gnu_optind; i < argc; i++ ) {
311 fprintf( stderr, "%s: ignoring extra argument -- %s\n", argv[0], argv[i] );
313 } // end ParseCommandLine
315 /* -------------------------------------------------------------------
316 * Interpret individual options, either from the command line
317 * or from environment variables.
318 * ------------------------------------------------------------------- */
320 void Settings_Interpret( char option, const char *optarg, thread_Settings *mExtSettings ) {
324 case '1': // Single Client
325 setSingleClient( mExtSettings );
328 case '2': // Dual-test Mode
329 if ( mExtSettings->mThreadMode != kMode_Client ) {
330 fprintf( stderr, warn_invalid_server_option, option );
333 if ( isCompat( mExtSettings ) ) {
334 fprintf( stderr, warn_invalid_compatibility_option, option );
337 mExtSettings->mMode = kTest_DualTest;
339 fprintf( stderr, warn_invalid_single_threaded, option );
340 mExtSettings->mMode = kTest_TradeOff;
345 // This sets packet-oriented mode. The optional
346 // argument sets datagram bandwidth (as before).
347 // If not given, a default bandwith is used.
348 setPacketOriented(mExtSettings);
351 Settings_GetLowerCaseArg(optarg, outarg);
352 mExtSettings->mDgramRate = byte_atoi(outarg);
354 mExtSettings->mDgramRate = kDefault_DgramRate;
357 case 'c': // client mode w/ server host to connect to
358 mExtSettings->mHost = new char[ strlen( optarg ) + 1 ];
359 strcpy( mExtSettings->mHost, optarg );
361 if ( mExtSettings->mThreadMode == kMode_Unknown ) {
362 mExtSettings->mThreadMode = kMode_Client;
363 mExtSettings->mThreads = 1;
367 case 'd': // DCCP as transport
368 mExtSettings->mProtocol = kProto_DCCP;
370 // if -l has already been processed, mBufLenSet is true
371 // so don't overwrite that value.
372 if ( !isBuflenSet( mExtSettings ) )
373 mExtSettings->mBufLen = kDefault_DCCPBufLen;
377 case 'f': // format to print in
378 mExtSettings->mFormat = (*optarg);
381 case 'h': // print help and exit
384 case 'i': // specify interval between periodic bw reports
385 mExtSettings->mInterval = atof( optarg );
386 if ( mExtSettings->mInterval < 0.5 ) {
387 fprintf (stderr, report_interval_small, mExtSettings->mInterval);
388 mExtSettings->mInterval = 0.5;
393 case 'J': // multicast interface to join multicast address on
394 mExtSettings->mMcastIface = if_nametoindex(optarg);
395 if (!mExtSettings->mMcastIface)
396 die("Interface \"%s\" does not work for -j/-J.", optarg);
399 case 'l': // length of each buffer
400 Settings_GetUpperCaseArg(optarg,outarg);
401 mExtSettings->mBufLen = byte_atoi( outarg );
402 setBuflenSet( mExtSettings );
404 if ( !isPacketOriented( mExtSettings ) ) {
405 if ( mExtSettings->mBufLen < (int) sizeof( client_hdr ) &&
406 !isCompat( mExtSettings ) ) {
407 setCompat( mExtSettings );
408 fprintf( stderr, warn_implied_compatibility, option );
411 if ( mExtSettings->mBufLen < (int) sizeof( dgram_record ) ) {
412 mExtSettings->mBufLen = sizeof( dgram_record );
413 fprintf( stderr, warn_buffer_too_small, mExtSettings->mBufLen );
415 if ( !isCompat( mExtSettings ) &&
416 mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
417 + sizeof( client_hdr ) ) ) {
418 setCompat( mExtSettings );
419 fprintf( stderr, warn_implied_compatibility, option );
425 case 'm': // print TCP MSS
426 setPrintMSS( mExtSettings );
429 case 'n': // bytes of data
430 // amount mode (instead of time mode)
431 unsetModeTime( mExtSettings );
432 Settings_GetUpperCaseArg(optarg,outarg);
433 mExtSettings->mAmount = byte_atoi( outarg );
436 case 'o' : // output the report and other messages into the file
437 unsetSTDOUT( mExtSettings );
438 mExtSettings->mOutputFileName = new char[strlen(optarg)+1];
439 strcpy( mExtSettings->mOutputFileName, optarg);
442 case 'p': // server port
443 mExtSettings->mPort = atoi( optarg );
446 case 'r': // test mode tradeoff
447 if ( mExtSettings->mThreadMode != kMode_Client ) {
448 fprintf( stderr, warn_invalid_server_option, option );
451 if ( isCompat( mExtSettings ) ) {
452 fprintf( stderr, warn_invalid_compatibility_option, option );
455 mExtSettings->mMode = kTest_TradeOff;
458 case 's': // server mode
459 if ( mExtSettings->mThreadMode != kMode_Unknown ) {
460 fprintf( stderr, warn_invalid_client_option, option );
464 mExtSettings->mThreadMode = kMode_Listener;
467 case 't': // seconds to write for
468 // time mode (instead of amount mode)
469 setModeTime( mExtSettings );
470 mExtSettings->mAmount = (int) (atof( optarg ) * 100.0);
473 case 'u': // UDP instead of TCP
474 mExtSettings->mProtocol = kProto_UDP;
476 setPacketOriented(mExtSettings);
477 // if -b has already been processed, UDP rate will
478 // already be non-zero, so don't overwrite that value
479 if ( mExtSettings->mDgramRate == 0 )
480 mExtSettings->mDgramRate = kDefault_DgramRate;
482 // if -l has already been processed, mBufLenSet is true
483 // so don't overwrite that value.
484 if ( !isBuflenSet( mExtSettings ) ) {
485 mExtSettings->mBufLen = kDefault_UDPBufLen;
486 } else if ( mExtSettings->mBufLen < (int) ( sizeof( dgram_record )
487 + sizeof( client_hdr ) ) &&
488 !isCompat( mExtSettings ) ) {
489 setCompat( mExtSettings );
490 fprintf( stderr, warn_implied_compatibility, option );
494 case 'v': // print version and exit
497 case 'w': // TCP window size or socket send-buffer size (UDP/DCCP)
498 Settings_GetUpperCaseArg(optarg,outarg);
499 mExtSettings->mWinSize = byte_atoi(outarg);
502 case 'x': // Limit Reports
503 while ( *optarg != '\0' ) {
507 setNoSettReport( mExtSettings );
511 setNoConnReport( mExtSettings );
515 setNoDataReport( mExtSettings );
519 setNoServReport( mExtSettings );
523 setNoMultReport( mExtSettings );
526 fprintf(stderr, warn_invalid_report, *optarg);
532 case 'y': // Reporting Style
536 mExtSettings->mReportMode = kReport_CSV;
539 fprintf( stderr, warn_invalid_report_style, optarg );
544 // more esoteric options
545 case 'B': // specify bind address
546 mExtSettings->mLocalhost = new char[ strlen( optarg ) + 1 ];
547 strcpy( mExtSettings->mLocalhost, optarg );
550 case 'C': // Run in Compatibility Mode
551 setCompat( mExtSettings );
552 if ( mExtSettings->mMode != kTest_Normal ) {
553 fprintf( stderr, warn_invalid_compatibility_option,
554 ( mExtSettings->mMode == kTest_DualTest ?
556 mExtSettings->mMode = kTest_Normal;
560 case 'D': // Run as a daemon
561 setDaemon( mExtSettings );
564 case 'F' : // Get the input for the data stream from a file
565 if ( mExtSettings->mThreadMode != kMode_Client ) {
566 fprintf( stderr, warn_invalid_server_option, option );
570 setFileInput( mExtSettings );
571 mExtSettings->mFileName = new char[strlen(optarg)+1];
572 strcpy( mExtSettings->mFileName, optarg);
575 case 'I' : // Set the stdin as the input source
576 if ( mExtSettings->mThreadMode != kMode_Client ) {
577 fprintf( stderr, warn_invalid_server_option, option );
581 setFileInput( mExtSettings );
582 setSTDIN( mExtSettings );
583 mExtSettings->mFileName = new char[strlen("<stdin>")+1];
584 strcpy( mExtSettings->mFileName,"<stdin>");
587 case 'L': // Listen Port (bidirectional testing client-side)
588 if ( mExtSettings->mThreadMode != kMode_Client ) {
589 fprintf( stderr, warn_invalid_server_option, option );
593 mExtSettings->mListenPort = atoi( optarg );
596 case 'M': // specify TCP MSS (maximum segment size)
597 Settings_GetUpperCaseArg(optarg,outarg);
599 mExtSettings->mMSS = byte_atoi( outarg );
602 case 'N': // specify TCP nodelay option (disable Jacobson's Algorithm)
603 setNoDelay( mExtSettings );
606 case 'P': // number of client threads
608 mExtSettings->mThreads = atoi( optarg );
610 if ( mExtSettings->mThreadMode != kMode_Server ) {
611 fprintf( stderr, warn_invalid_single_threaded, option );
613 mExtSettings->mThreads = atoi( optarg );
619 setRemoveService( mExtSettings );
622 case 'S': // IP type-of-service
623 // TODO use a function that understands base-2
624 // the zero base here allows the user to specify
625 // "0x#" hex, "0#" octal, and "#" decimal numbers
626 mExtSettings->mTOS = strtol( optarg, NULL, 0 );
629 case 'T': // time-to-live for multicast
630 mExtSettings->mTTL = atoi( optarg );
633 case 'V': // IP Domain: the optional ar
634 mExtSettings->mSockAF = AF_INET6;
635 if ( optarg && optarg[0] == '4' )
636 mExtSettings->mSockAF = AF_INET;
638 case 'U': // single threaded UDP server
639 setSingleUDP( mExtSettings );
643 setSuggestWin( mExtSettings );
644 fprintf( stderr, "The -W option is not available in this release\n");
647 default: // ignore unknown
652 void Settings_GetUpperCaseArg(const char *inarg, char *outarg) {
654 int len = strlen(inarg);
655 strcpy(outarg,inarg);
657 if ( (len > 0) && (inarg[len-1] >='a')
658 && (inarg[len-1] <= 'z') )
659 outarg[len-1]= outarg[len-1]+'A'-'a';
662 void Settings_GetLowerCaseArg(const char *inarg, char *outarg) {
664 int len = strlen(inarg);
665 strcpy(outarg,inarg);
667 if ( (len > 0) && (inarg[len-1] >='A')
668 && (inarg[len-1] <= 'Z') )
669 outarg[len-1]= outarg[len-1]-'A'+'a';
673 * Settings_GenerateListenerSettings
674 * Called to generate the settings to be passed to the Listener
675 * instance that will handle dual testings from the client side
676 * this should only return an instance if it was called on
677 * the thread_Settings instance generated from the command line
678 * for client side execution
680 void Settings_GenerateListenerSettings( thread_Settings *client, thread_Settings **listener ) {
681 if ( !isCompat( client ) &&
682 (client->mMode == kTest_DualTest || client->mMode == kTest_TradeOff) ) {
683 *listener = new thread_Settings;
684 memcpy(*listener, client, sizeof( thread_Settings ));
685 setCompat( (*listener) );
686 unsetDaemon( (*listener) );
687 if ( client->mListenPort != 0 ) {
688 (*listener)->mPort = client->mListenPort;
690 (*listener)->mPort = client->mPort;
692 (*listener)->mFileName = NULL;
693 (*listener)->mHost = NULL;
694 (*listener)->mLocalhost = NULL;
695 (*listener)->mOutputFileName = NULL;
696 (*listener)->mMode = kTest_Normal;
697 (*listener)->mThreadMode = kMode_Listener;
698 if ( client->mHost != NULL ) {
699 (*listener)->mHost = new char[strlen( client->mHost ) + 1];
700 strcpy( (*listener)->mHost, client->mHost );
702 if ( client->mLocalhost != NULL ) {
703 (*listener)->mLocalhost = new char[strlen( client->mLocalhost ) + 1];
704 strcpy( (*listener)->mLocalhost, client->mLocalhost );
712 * Settings_GenerateSpeakerSettings
713 * Called to generate the settings to be passed to the Speaker
714 * instance that will handle dual testings from the server side
715 * this should only return an instance if it was called on
716 * the thread_Settings instance generated from the command line
717 * for server side execution. This should be an inverse operation
718 * of GenerateClientHdr.
720 void Settings_GenerateClientSettings( thread_Settings *server,
721 thread_Settings **client,
723 int flags = ntohl(hdr->flags);
724 if ( (flags & HEADER_VERSION1) != 0 ) {
725 *client = new thread_Settings;
726 memcpy(*client, server, sizeof( thread_Settings ));
727 setCompat( (*client) );
728 (*client)->mTID = thread_zeroid();
729 (*client)->mPort = (unsigned short) ntohl(hdr->mPort);
730 (*client)->mThreads = ntohl(hdr->numThreads);
731 if ( hdr->bufferlen != 0 ) {
732 (*client)->mBufLen = ntohl(hdr->bufferlen);
734 if ( hdr->mWinBand != 0 ) {
735 if ( isPacketOriented( server ) ) {
736 (*client)->mDgramRate = ntohl(hdr->mWinBand);
738 (*client)->mWinSize = ntohl(hdr->mWinBand);
741 (*client)->mAmount = ntohl(hdr->mAmount);
742 if ( ((*client)->mAmount & 0x80000000) > 0 ) {
743 setModeTime( (*client) );
744 (*client)->mAmount |= 0xFFFFFFFF00000000LL;
745 (*client)->mAmount = -(*client)->mAmount;
747 (*client)->mFileName = NULL;
748 (*client)->mHost = NULL;
749 (*client)->mLocalhost = NULL;
750 (*client)->mOutputFileName = NULL;
751 (*client)->mMode = ((flags & RUN_NOW) == 0 ?
752 kTest_TradeOff : kTest_DualTest);
753 (*client)->mThreadMode = kMode_Client;
754 if ( server->mLocalhost != NULL ) {
755 (*client)->mLocalhost = new char[strlen( server->mLocalhost ) + 1];
756 strcpy( (*client)->mLocalhost, server->mLocalhost );
758 (*client)->mHost = new char[REPORT_ADDRLEN];
759 SockAddr_name(&server->peer, (*client)->mHost, REPORT_ADDRLEN);
766 * Settings_GenerateClientHdr
767 * Called to generate the client header to be passed to the
768 * server that will handle dual testings from the server side
769 * This should be an inverse operation of GenerateSpeakerSettings
771 void Settings_GenerateClientHdr( thread_Settings *client, client_hdr *hdr ) {
772 if ( client->mMode != kTest_Normal ) {
773 hdr->flags = htonl(HEADER_VERSION1);
777 if ( isBuflenSet( client ) ) {
778 hdr->bufferlen = htonl(client->mBufLen);
782 if ( isPacketOriented( client ) ) {
783 hdr->mWinBand = htonl(client->mDgramRate);
785 hdr->mWinBand = htonl(client->mWinSize);
787 if ( client->mListenPort != 0 ) {
788 hdr->mPort = htonl(client->mListenPort);
790 hdr->mPort = htonl(client->mPort);
792 hdr->numThreads = htonl(client->mThreads);
793 if ( isModeTime( client ) ) {
794 hdr->mAmount = htonl(-(long)client->mAmount);
796 hdr->mAmount = htonl((long)client->mAmount);
797 hdr->mAmount &= htonl( 0x7FFFFFFF );
799 if ( client->mMode == kTest_DualTest ) {
800 hdr->flags |= htonl(RUN_NOW);