forked from travelping/nattcp
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnattcp.c
8956 lines (8660 loc) · 247 KB
/
nattcp.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* N A T T C P . C v7.1.6
*
* Copyright(c) 2000 - 2010 Bill Fink. All rights reserved.
* Copyright(c) 2003 - 2010 Rob Scott. All rights reserved.
*
* nuttcp is free, opensource software. You can redistribute it and/or
* modify it under the terms of Version 2 of the GNU General Public
* License (GPL), as published by the GNU Project (http://www.gnu.org).
* A copy of the license can also be found in the LICENSE file.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
* for more details.
*
* Based on nttcp
* Developed by Bill Fink, [email protected]
* and Rob Scott, [email protected]
* Latest version available at:
* http://lcp.nrl.navy.mil/nuttcp/
*
* Test TCP connection. Makes a connection on port 5000(ctl)/5101(data)
* and transfers fabricated buffers or data copied from stdin.
*
* Run nuttcp with no arguments to get a usage statement
*
* Modified for operation under 4.2BSD, 18 Dec 84
* T.C. Slattery, USNA
* Minor improvements, Mike Muuss and Terry Slattery, 16-Oct-85.
*
* 7.1.3, Bill Fink, 1-Apr-10
* Fix compiler warnings generated by Ubuntu 9.x gcc 4.3.x/4.4.x versions
* (to see warnings compile with -DWANT_WUR)
* 7.1.2, Bill Fink, 23-Jan-10
* Updated Copyright notice
* Terminate non-sinkmode after specified file size with "-n" option
* Allow multilink aggregation with "-N##m" option to work for receive
* Add "-sz" zero copy option for non-sinkmode when input is a regular file
* Fix compiler warnings about strict-aliasing rules for variable group
* Remove "-Sf" forced server mode from Usage: statement
* Fix zeroing of clientaddr6 during server cleanup
* Fix freeaddrinfo() processing during cleanup
* Change manually started oneshot server to have parent process just exit
* Some minor whitespace cleanup
* 7.1.1, Bill Fink, 24-Dec-09
* Provide summary TCP retrans info for multi-stream TCP
* Fix bug with retrans interval info when -fparse
* Add "+stride" or "+n.n.n.n" syntax for multi-stream TCP (IPv4)
* Fix third party bug with "-xc" option adding extraneous 't' character
* Add optional client-side name resolution for third party host
* Add "-N##m" option for multilink aggregation for multiple streams
* Add "-xc#/#" and "-P#/#" options to Usage: statement
* Some minor whitespace cleanup
* 7.0.1, Bill Fink, 18-Sep-09
* Enable jitter measurements with "-j" option
* Enable one-way delay measurements with "-o" option
* Fix bug with RTT and -fparse
* 6.2.10, Bill Fink, 1-Aug-09
* Change ctl/data port checks to < 1024 instead of < 5000
* Fix "--idle-data-timeout" Usage: statement for new default minimum
* Improve transmit performance with "-i" by setting poll() timeout to 0
* Remove commented out code for unused normal_eod
* Don't output interval retrans info if non-sinkmode (for nuttscp)
* 6.2.9, Bill Fink, 24-Jun-09
* Make retrans info reporting work again on newer Linux distros
* Skip check for unACKed data at end of transfer if -DBROKEN_UNACKED
* 6.2.8, Bill Fink, 8-Jun-09
* Play nice with iperf (change default data port to 5101)
* Delay sending of server "OK" until after successful server bind()
* Client check for server errors before starting data transfer
* Continue checking for server output while draining client transmission
* Correct "server not ACKing data" error message (server -> receiver)
* Add "--packet-burst" option for Rob
* Fix "--idle-data-timeout" Usage: statement for client
* Improve accuracy of retrans info timing synchronization (client xmitter)
* Change reference to nuttcp repository from ftp:// to http://
* Fix bug affecting nuttscp introduced in 6.2.4 (not honoring oneshot)
* Whitespace cleanup: get rid of <tab><spaces><tab>, <tab>$, & <spaces>$
* Whitespace cleanup: convert 8 spaces to <tab> where appropriate
* 6.2.7, Bill Fink, 22-May-09
* Allow rate limit to be exceeded temporarily by n packets ("-Rixxx/n")
* Fix several reqval parameter settings
* 6.2.6, Bill Fink, 17-Apr-09
* Allow setting server CPU affinity from client via "-xcs" option
* Allow setting client & server CPU affinity via third party
* Fix bug with option processing when reqval is set
* 6.2.5, Bill Fink, 16-Apr-09
* Allow passing of third party control port via "-Pctlport/ctlport3"
* Up default idle data minimum to 15 sec to better handle net transients
* Don't reset nstream until after last use (fix getaddrinfo() memory leak)
* 6.2.4, Bill Fink, 10-Apr-09
* Fix bug with simultaneous server connections to manually started server
* 6.2.3, Bill Fink, 5-Apr-09
* Add "-xc" option to set CPU affinity (Linux only)
* Fix Usage: statement: "--idle-data-timeout" both server & client option
* Don't reset priority on server cleanup
* Fix priority output for "-fparse"
* 6.2.2, Bill Fink, 3-Apr-09
* Fix bad third party bug causing >= 1 minute transfers to silently fail
* Fix Usage: statement: "--idle-data-timeout" not just a server option
* 6.2.1, Rob Scott, 22-Mar-09
* Added IPv6 and SSM MC support
* Ported from Rob's 5.5.5 based code by Bill Fink
* 6.1.5, Bill Fink, 5-Mar-09
* Fix client lockup with third party when network problem (for scripts)
* 6.1.4, Bill Fink, 5-Jan-09
* Updated Copyright notice
* Bugfix: set chk_idle_data on client (now also checks no data received)
* Use argv[0] instead of "nuttcp" for third party
* Bugfix: give error message again on error starting server
* 6.1.3, Bill Fink, 17-Sep-08
* Timeout client accept() too and give nice error message (for scripts)
* 6.1.2, Bill Fink, 29-Aug-08
* Don't wait forever for unacked data at EOT (limit to 1 minute max)
* Extend no data received protection to client too (for scripts)
* Give nice error messages to client for above cases
* Don't hang getting server info if server exited (timeout reads)
* 6.1.1, Bill Fink, 26-Aug-08
* Remove beta designation
* Report RTT by default (use "-f-rtt" to suppress)
* Moved RTT info to "connect to" line
* Correct bogus IP frag warning for e.g. "-l1472" or "-l8972"
* Don't report interval host-retrans if no data rcvd (e.g. initial PMTU)
* Correct reporting of retrans info with "-fparse" option
* Correct reporting of RTT with "-F" flip option
* Report doubled send and receive window sizes (for Linux)
* Add report of available send and receive window sizes (for Linux)
* Touchup TODO list to remove some already completed items
* 6.0.7, Bill Fink, 19-Aug-08
* Add delay (default 0.5 sec) to "-a" option & change max retries to 10
* Updated Copyright notice
* 6.0.6, Bill Fink, 11-Aug-08
* Delay server forking until after listen() for better error status
* Above suggested by Hans Blom ([email protected])
* Make forced server mode the default behavior
* Check address family on getpeername() so "ssh host nuttcp -S" works
* Add setsid() call for manually started server to create new session
* Some minor code cleanup
* 6.0.5, Bill Fink, 10-Aug-08
* Allow "-s" from/to stdin/stdout with "-1" oneshot server mode
* Switch beta vers message to stderr to not interfere with "-s" option
* Don't set default timeout if "-s" specified
* Give error message for "-s" with "-S" (xinetd or manually started)
* 6.0.4, Bill Fink, 18-Jul-08
* Forgot about 3rd party support for RTT info - fix that
* 6.0.3, Bill Fink, 17-Jul-08
* A better (and accurate) way to get RTT info (and not just Linux)
* 6.0.2, Bill Fink, 16-Jul-08
* Add RTT info to brief output for Linux
* 6.0.1, Bill Fink, 17-Dec-07
* Add reporting of TCP retransmissions (interval reports on Linux TX only)
* Add reporting of data transfer RTT for verbose Linux output
* Add beta version messages and "-f-beta" option to suppress
* Automatically switch "classic" mode to oneshot server mode
* Fix UDP loss info bug not updating stream_idx when not need_swap
* Fix compiler warning doing sprintf of timeout
* Correct comment on NODROPS define
* 5.5.5, Bill Fink, 1-Feb-07
* Change default MC addr to be based on client addr instead of xmit addr
* 5.5.4, Bill Fink, 3-Nov-06
* Fix bug with negative loss causing huge drop counts on interval reports
* Updated Copyright notice and added GPL license notice
* 5.5.3, Bill Fink, 23-Oct-06
* Fix bug with "-Ri" instantaneous rate limiting not working properly
* 5.5.2, Bill Fink, 25-Jul-06
* Make manually started server multi-threaded
* Add "--single-threaded" server option to restore old behavior
* Add "-a" client option to retry a failed server connection "again"
* (for certain possibly transient errors)
* 5.5.1, Bill Fink, 22-Jul-06
* Fix bugs with nbuf_bytes and rate_pps used with 3rd party
* Pass "-D" option to server (and also make work for third party)
* Allow setting precedence with "-c##p"
* 5.4.3, Rob Scott & Bill Fink, 17-Jul-06
* Fix bug with buflen passed to server when no buflen option speicified
* (revert 5.3.2: Fix bug with default UDP buflen for 3rd party)
* Better way to fix bug with default UDP buflen for 3rd party
* Trim trailing '\n' character from err() calls
* Use fcntl() to set O_NONBLOCK instead of MSG_DONTWAIT to send() ABORT
* (and remove MSG_DONTWAIT from recv() because it's not needed)
* Don't re-initialize buflen at completion of server processing
* (non inetd: is needed to check for buffer memory allocation change,
* caused bug if smaller "-l" followed by larger default "-l")
* 5.4.2, Bill Fink, 1-Jul-06
* Fix bug with interrupted UDP receive reporting negative packet loss
* Make sure errors (or debug) from server are propagated to the client
* Make setsockopt SO_SNDBUF/SO_RCVBUF error not be fatal to server
* Don't send stderr to client if nofork is set (manually started server)
* 5.4.1, Bill Fink, 30-Jun-06
* Fix bug with UDP reporting > linerate because of bad correction
* Send 2nd UDP BOD packet in case 1st is lost, e.g. waiting for ARP reply
* (makes UDP BOD more robust for new separate control and data paths)
* Fix bug with interval reports after EOD for UDP with small interval
* Don't just exit inetd server on no data so can get partial results
* (keep an eye out that servers don't start hanging again)
* Make default idle data timeout 1/2 of timeout if interval not set
* (with a minimum of 5 seconds and a maximum of 60 seconds)
* Make server send abort via urgent TCP data if no UDP data received
* (non-interval only: so client won't keep transmitting for full period)
* Workaround for Windows not handling TCP_MAXSEG getsockopt()
* 5.3.4, Bill Fink, 21-Jun-06
* Add "--idle-data-timeout" server option
* (server ends transfer if no data received for the specified
* timeout interval, previously it was a fixed 60 second timeout)
* Shutdown client control connection for writing at end of UDP transfer
* (so server can cope better with loss of all EOD packets, which is
* mostly of benefit when using separate control and data paths)
* 5.3.3, Bill Fink & Mark S. Mathews, 18-Jun-06
* Add new capability for separate control and data paths
* (using syntax: nuttcp ctl_name_or_IP/data_name_or_IP)
* Extend new capability for multiple independent data paths
* (using syntax: nuttcp ctl/data1/data2/.../datan)
* Above only supported for transmit or flipped/reversed receive
* Fix -Wall compiler warnings on 64-bit systems
* Make manually started server also pass stderr to client
* (so client will get warning messages from server)
* 5.3.2, Bill Fink, 09-Jun-06
* Fix bug with default UDP buflen for 3rd party
* Fix compiler warnings with -Wall on FreeBSD
* Give warning that windows doesn't support TCP_MAXSEG
* 5.3.1, Rob Scott, 06-Jun-06
* Add "-c" COS option for setting DSCP/TOS setting
* Fix builds on latest MacOS X
* Fix bug with 3rd party unlimited rate UDP not working
* Change "-M" option to require a value
* Fix compiler warnings with -Wall (thanks to Daniel J Blueman)
* Remove 'v' from nuttcp version (simplify RPM packaging)
* V5.2.2, Bill Fink, 13-May-06
* Have client report server warnings even if not verbose
* V5.2.1, Bill Fink, 12-May-06
* Pass "-M" option to server so it also works for receives
* Make "-uu" be a shortcut for "-u -Ru"
* V5.1.14, Bill Fink, 11-May-06
* Fix cancellation of UDP receives to work properly
* Allow easy building without IPv6 support
* Set default UDP buflen to largest 2^n less than MSS of ctlconn
* Add /usr/local/sbin and /usr/etc to path
* Allow specifying rate in pps by using 'p' suffix
* Give warning if actual send/receive window size is less than requested
* Make UDP transfers have a default rate limit of 1 Mbps
* Allow setting MSS for client transmitter TCP transfers with "-M" option
* Give more precision on reporting small UDP percentage data loss
* Disallow UDP transfers in "classic" mode
* Notify when using "classic" mode
* V5.1.13, Bill Fink, 8-Apr-06
* Make "-Ri" instantaneous rate limit for very high rates more accurate
* (including compensating for microsecond gettimeofday() granularity)
* Fix bug giving bogus time/stats on UDP transmit side with "-Ri"
* Allow fractional rate limits (for 'm' and 'g' only)
* V5.1.12, Bill Fink & Rob Scott, 4-Oct-05
* Terminate server receiver if client control connection goes away
* or if no data received from client within CHECK_CLIENT_INTERVAL
* V5.1.11, Rob Scott, 25-Jun-04
* Add support for scoped ipv6 addresses
* V5.1.10, Bill Fink, 16-Jun-04
* Allow 'b' suffix on "-w" option to specify window size in bytes
* V5.1.9, Bill Fink, 23-May-04
* Fix bug with client error on "-d" option putting server into bad state
* Set server accept timeout (currently 5 seconds) to prevent stuck server
* Add nuttcp version info to error message from err() exit
* V5.1.8, Bill Fink, 22-May-04
* Allow 'd|D' suffix to "-T" option to specify days
* Fix compiler warning about unused variable cp in getoptvalp routine
* Interval value check against timeout value should be >=
* V5.1.7, Bill Fink, 29-Apr-04
* Drop "-nb" option in favor of "-n###[k|m|g|t|p]"
* V5.1.6, Bill Fink, 25-Apr-04
* Fix bug with using interval option without timeout
* V5.1.5, Bill Fink, 23-Apr-04
* Modification to allow space between option parameter and its value
* Permit 'k' or 'm' suffix on "-l" option
* Add "-nb" option to specify number of bytes to transfer
* Permit 'k', 'm', 'g', 't', or 'p' suffix on "-n" and "-nb" options
* V5.1.4, Bill Fink, 21-Apr-04
* Change usage statement to use standard out instead of standard error
* Fix bug with interval > timeout, give warning and ignore interval
* Fix bug with counting error value in nbytes on interrupted transfers
* Fix bug with TCP transmitted & received nbytes not matching
* Merge "-t" and "-r" options in Usage: statement
* V5.1.3, Bill Fink, 9-Apr-04
* Add "-Sf" force server mode (useful for starting server via rsh/ssh)
* Allow non-root user to find nuttcp binary in "."
* Fix bug with receives terminating early with manual server mode
* Fix bug with UDP receives not terminating with "-Ri" option
* Clean up output formatting of nbuf (from "%d" to "%llu")
* Add "-SP" to have 3rd party use same outgoing control port as incoming
* V5.1.2, Bill Fink & Rob Scott, 18-Mar-04
* Fix bug with nbuf wrapping on really long transfers (int -> uint64_t)
* Fix multicast address to be unsigned long to allow shift
* Add MacOS uint8_t definition for new use of uint8_t
* V5.1.1, Bill Fink, 8-Nov-03
* Add IPv4 multicast support
* Delay receiver EOD until EOD1 (for out of order last data packet)
* Above also drains UDP receive buffer (wait for fragmentation reassembly)
* V5.0.4, Bill Fink, 6-Nov-03
* Fix bug reporting 0 drops when negative loss percentage
* V5.0.3, Bill Fink, 6-Nov-03
* Kill server transmission if control connection goes away
* Kill 3rd party nuttcp if control connection goes away
* V5.0.2, Bill Fink, 4-Nov-03
* Fix bug: some dummy wasn't big enough :-)
* V5.0.1, Bill Fink, 3-Nov-03
* Add third party support
* Correct usage statement for "-xt" traceroute option
* Improved error messages on failed options requiring client/server mode
* V4.1.1, David Lapsley and Bill Fink, 24-Oct-03
* Added "-fparse" format option to generate key=value parsable output
* Fix bug: need to open data connection on abortconn to clear listen
* V4.0.3, Rob Scott, 13-Oct-03
* Minor tweaks to output format for alignment
* Interval option "-i" with no explicit value sets interval to 1.0
* V4.0.2, Bill Fink, 10-Oct-03
* Changed "-xt" option to do both forward and reverse traceroute
* Changed to use brief output by default ("-v" for old default behavior)
* V4.0.1, Rob Scott, 10-Oct-03
* Added IPv6 code
* Changed inet get functions to protocol independent versions
* Added fakepoll for hosts without poll() (macosx)
* Added ifdefs to only include setprio if os supports it (non-win)
* Added bits to handle systems without new inet functions (solaris < 2.8)
* Removed SYSV obsolete code
* Added ifdefs and code to handle cygwin and beginning of windows support
* Window size can now be in meg (m|M) and gig (g|G)
* Added additional directories to search for traceroute
* Changed default to transmit, time limit of 10 seconds, no buffer limit
* Added (h|H) as option to specify time in hours
* Added getservbyname calls for port, if all fails use old defaults
* Changed sockaddr to sockaddr_storage to handle v6 addresses
* v3.7.1, Bill Fink, 10-Aug-03
* Add "-fdebugpoll" option to help debug polling for interval reporting
* Fix Solaris compiler warning
* Use poll instead of separate process for interval reports
* v3.6.2, Rob Scott, 18-Mar-03
* Allow setting server window to use default value
* Cleaned out BSD42 old code
* Marked SYSV code for future removal as it no longer appears necessary
* Also set RCVBUF/SNDBUF for udp transfers
* Changed transmit SO_DEBUG code to be like receive
* Some code rearrangement for setting options before accept/connect
* v3.6.1, Bill Fink, 1-Mar-03
* Add -xP nuttcp process priority option
* Add instantaneous rate limit capability ("-Ri")
* Don't open data connection if server error or doing traceroute
* Better cleanup on server connection error (close open data connections)
* Don't give normal nuttcp output if server error requiring abort
* Implement -xt traceroute option
* v3.5.1, Bill Fink, 27-Feb-03
* Don't allow flip option to be used with UDP
* Fix bug with UDP and transmit interval option (set stdin unbuffered)
* Fix start of UDP timing to be when get BOD
* Fix UDP timing when don't get first EOD
* Fix ident option used with interval option
* Add "-f-percentloss" option to not give %loss info on brief output
* Add "-f-drops" option to not give packet drop info on brief output
* Add packet drop info to UDP brief output (interval report and final)
* Add "-frunningtotal" option to give cumulative stats for "-i"
* Add "-fdebuginterval" option to help debug interval reporting
* Add "-fxmitstats" option to give transmitter stats
* Change flip option from "-f" to "-F"
* Fix divide by zero bug with "-i" option and very low rate limit
* Fix to allow compiling with Irix native compiler
* Fix by Rob Scott to allow compiling on MacOS X
* v3.4.5, Bill Fink, 29-Jan-03
* Fix client/server endian issues with UDP loss info for interval option
* v3.4.4, Bill Fink, 29-Jan-03
* Remove some debug printout for interval option
* Fix bug when using interval option reporting 0.000 MB on final
* v3.4.3, Bill Fink, 24-Jan-03
* Added UDP approximate loss info for interval reporting
* Changed nbytes and pbytes from double to uint64_t
* Changed SIGUSR1 to SIGTERM to kill sleeping child when done
* v3.4.2, Bill Fink, 15-Jan-03
* Make <control-C> work right with receive too
* v3.4.1, Bill Fink, 13-Jan-03
* Fix bug interacting with old servers
* Add "-f" flip option to reverse direction of data connection open
* Fix bug by disabling interval timer when server done
* v3.3.2, Bill Fink, 11-Jan-03
* Make "-i" option work for client transmit too
* Fix bug which forced "-i" option to be at least 0.1 seconds
* v3.3.1, Bill Fink, 7-Jan-03
* Added -i option to set interval timer (client receive only)
* Fixed server bug not setting socket address family
* v3.2.1, Bill Fink, 25-Feb-02
* Fixed bug so second <control-C> will definitely kill nuttcp
* Changed default control port to 5000 (instead of data port - 1)
* Modified -T option to accept fractional seconds
* v3.1.10, Bill Fink, 6-Feb-02
* Added -I option to identify nuttcp output
* Made server always verbose (filtering is done by client)
* Update to usage statement
* Minor fix to "-b" output when "-D" option is used
* Fix bug with "-s" that appends nuttcp output to receiver data file
* Fix bug with "-b" that gave bogus CPU utilization on > 1 hour transfers
* v3.1.9, Bill Fink, 21-Dec-01
* Fix bug with "-b" option on SGI systems reporting 0% CPU utilization
* v3.1.8, Bill Fink, 21-Dec-01
* Minor change to brief output format to make it simpler to awk
* v3.1.7, Bill Fink, 20-Dec-01
* Implement "-b" option for brief output (old "-b" -> "-wb")
* Report udp loss percentage when using client/server mode
* Fix bug with nbytes on transmitter using timed transfer
* Combined send/receive window size printout onto a single line
* v3.1.6, Bill Fink, 11-Jun-01
* Fixed minor bug reporting error connecting to inetd server
* Previously, Bill Fink, 7-Jun-01
* Added -h (usage) and -V (version) options
* Fixed SGI compilation warnings
* Added reporting server version to client
* Added version info and changed ttcp prints to nuttcp
* Fixed bug with inetd server and client using -r option
* Added ability to run server from inetd
* Added udp capability to server option
* Added -T option to set timeout interval
* Added -ws option to set server window
* Added -S option to support running receiver as daemon
* Allow setting UDP buflen up to MAXUDPBUFLEN
* Provide -b option for braindead Solaris 2.8
* Added printing of transmit rate limit
* Added -w option to usage statement
* Added -N option to support multiple streams
* Added -R transmit rate limit option
* Fix setting of destination IP address on 64-bit Irix systems
* Only set window size in appropriate direction to save memory
* Fix throughput calculation for large transfers (>= 2 GB)
* Fix reporting of Mb/s to give actual millions of bits per second
* Fix setting of INET address family in local socket
* Fix setting of receiver window size
*
* TODO/Wish-List:
* Transmit interval marking option
* Allow at least some traceroute options
* Add "-ut" option to do both UDP and TCP simultaneously
* Default rate limit UDP if too much loss
* Ping option
* Other brief output formats
* Linux window size bug/feature note
* Network interface interrupts (for Linux only)
* netstat -i info
* Man page
* Forking for multiple streams
* Bidirectional option
* Graphical interface
* MTU info
* Warning for window size limiting throughput
* Auto window size optimization
* Transmitter profile and playback options
* Server side limitations (per client host/network)
* Server side logging
* Client/server security (password)
* nuttcp server registration
* nuttcp proxy support (firewalls)
* nuttcp network idle time
*
* Distribution Status -
* OpenSource(tm)
* Licensed under version 2 of the GNU GPL
* Please send source modifications back to the authors
* Derivative works should be redistributed with a modified
* source and executable name
*/
/*
#ifndef lint
static char RCSid[] = "@(#)$Revision: 1.2 $ (BRL)";
#endif
*/
#ifndef WANT_WUR
#undef _FORTIFY_SOURCE
#else
#define _FORTIFY_SOURCE 2
#endif
#define _FILE_OFFSET_BITS 64
#include <stdio.h>
#include <signal.h>
#include <ctype.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h> /* struct timeval */
#include <stdlib.h>
#ifndef _WIN32
#include <sys/socket.h>
#include <netinet/in.h>
#include <netinet/tcp.h>
#include <arpa/inet.h>
#include <netdb.h>
#include <sys/resource.h>
#include <pwd.h>
#else
#include "win32nuttcp.h" /* from win32 */
#endif /* _WIN32 */
#include <limits.h>
#include <string.h>
#include <fcntl.h>
#if defined(linux)
#include <sys/stat.h>
#include <sys/sendfile.h>
#endif
/* Let's try changing the previous unwieldy check */
/* #if defined(linux) || defined(__FreeBSD__) || defined (sgi) || (defined(__MACH__) && defined(_SOCKLEN_T)) || defined(sparc) || defined(__CYGWIN__) */
/* to the following (hopefully equivalent) simpler form like we use
* for HAVE_POLL */
#if !defined(_WIN32) && (!defined(__MACH__) || defined(_SOCKLEN_T))
#include <unistd.h>
#include <sys/wait.h>
#include <strings.h>
#endif
#ifndef ULLONG_MAX
#define ULLONG_MAX 18446744073709551615ULL
#endif
#define MAXRATE 0xffffffffUL
#if !defined(__CYGWIN__) && !defined(_WIN32)
#define HAVE_SETPRIO
#endif
#if defined(linux)
#define HAVE_SETAFFINITY
#define __USE_GNU
#endif
#if !defined(_WIN32) && (!defined(__MACH__) || defined(_SOCKLEN_T))
#define HAVE_POLL
#endif
#if defined(__APPLE__) && defined(__MACH__)
#define uint64_t u_int64_t
#define uint32_t u_int32_t
#define uint16_t u_int16_t
#define uint8_t u_int8_t
#endif
#ifdef HAVE_POLL
#include <sys/poll.h>
#else
#include "fakepoll.h" /* from missing */
#endif
#ifdef HAVE_SETAFFINITY
#include <sched.h>
#endif
#ifndef CPU_SETSIZE
#undef HAVE_SETAFFINITY
#endif
/*
* _SOCKLEN_T is now defined by apple when they typedef socklen_t
*
* EAI_NONAME has nothing to do with socklen, but on sparc without it tells
* us it's an old enough solaris to need the typedef
*/
#if (defined(__APPLE__) && defined(__MACH__)) && !defined(_SOCKLEN_T) || (defined(sparc) && !defined(EAI_NONAME))
typedef int socklen_t;
#endif
#if defined(sparc) && !defined(EAI_NONAME) /* old sparc */
#define sockaddr_storage sockaddr
#define ss_family sa_family
#endif /* old sparc */
#if defined(_AIX)
#define ss_family __ss_family
#endif
#if !defined(EAI_NONAME)
#include "addrinfo.h" /* from missing */
#endif
#define BETA_STR "-beta8"
#define BETA_FEATURES "jitter/owd"
union sockaddr_union {
struct sockaddr_storage ss;
struct sockaddr_in sin;
struct sockaddr_in6 sin6;
};
static struct timeval time0; /* Time at which timing started */
static struct timeval timepk; /* Time at which last packet sent */
static struct timeval timepkr; /* Time at which last packet received */
static struct timeval timepkri; /* timepkr for interval reports */
static struct timeval timep; /* Previous time - for interval reporting */
static struct timeval timetx; /* Transmitter timestamp */
static struct timeval timerx; /* Receive timestamp */
static struct rusage ru0; /* Resource utilization at the start */
static struct sigaction sigact; /* signal handler for alarm */
static struct sigaction savesigact;
#define PERF_FMT_OUT "%.4f MB in %.2f real seconds = %.2f KB/sec" \
" = %.4f Mbps\n"
#define PERF_FMT_BRIEF "%10.4f MB / %6.2f sec = %9.4f Mbps %d %%TX %d %%RX"
#define PERF_FMT_BRIEF2 "%10.4f MB / %6.2f sec = %9.4f Mbps %d %%%s"
#define PERF_FMT_BRIEF3 " Trans: %.4f MB"
#define PERF_FMT_INTERVAL "%10.4f MB / %6.2f sec = %9.4f Mbps"
#define PERF_FMT_INTERVAL2 " Tot: %10.4f MB / %6.2f sec = %9.4f Mbps"
#define PERF_FMT_INTERVAL3 " Trans: %10.4f MB"
#define PERF_FMT_INTERVAL4 " Tot: %10.4f MB"
#define PERF_FMT_IN "%lf MB in %lf real seconds = %lf KB/sec = %lf Mbps\n"
#define CPU_STATS_FMT_IN "%*fuser %*fsys %*d:%*dreal %d%%"
#define CPU_STATS_FMT_IN2 "%*fuser %*fsys %*d:%*d:%*dreal %d%%"
#define LOSS_FMT " %.2f%% data loss"
#define LOSS_FMT_BRIEF " %.2f %%loss"
#define LOSS_FMT_INTERVAL " %5.2f ~%%loss"
#define LOSS_FMT5 " %.5f%% data loss"
#define LOSS_FMT_BRIEF5 " %.5f %%loss"
#define LOSS_FMT_INTERVAL5 " %7.5f ~%%loss"
#define DROP_FMT " %lld / %lld drop/pkt"
#define DROP_FMT_BRIEF " %lld / %lld drop/pkt"
#define DROP_FMT_INTERVAL " %5lld / %5lld ~drop/pkt"
#define JITTER_MIN 1
#define JITTER_AVG 2
#define JITTER_MAX 4
#define JITTER_IGNORE_OOO 8
#define JITTER_FMT "min-jitter = %.4f ms, avg-jitter = %.4f ms, " \
"max-jitter = %.4f ms"
#define JITTER_MIN_FMT_BRIEF " %.4f msMinJitter"
#define JITTER_AVG_FMT_BRIEF " %.4f msAvgJitter"
#define JITTER_MAX_FMT_BRIEF " %.4f msMaxJitter"
#define JITTER_MIN_FMT_INTERVAL " %.4f msMinJitter"
#define JITTER_AVG_FMT_INTERVAL " %.4f msAvgJitter"
#define JITTER_MAX_FMT_INTERVAL " %.4f msMaxJitter"
#define JITTER_FMT_IN "jitter = %lf ms, avg-jitter = %lf ms, " \
"max-jitter = %lf ms"
#define OWD_MIN 1
#define OWD_AVG 2
#define OWD_MAX 4
#define OWD_FMT "min-OWD = %.4f ms, avg-OWD = %.4f ms, " \
"max-OWD = %.4f ms"
#define OWD_MIN_FMT_BRIEF " %.4f msMinOWD"
#define OWD_AVG_FMT_BRIEF " %.4f msAvgOWD"
#define OWD_MAX_FMT_BRIEF " %.4f msMaxOWD"
#define OWD_MIN_FMT_INTERVAL " %.4f msMinOWD"
#define OWD_AVG_FMT_INTERVAL " %.4f msAvgOWD"
#define OWD_MAX_FMT_INTERVAL " %.4f msMaxOWD"
#define OWD_FMT_IN "OWD = %lf ms, avg-OWD = %lf ms, max-OWD = %lf ms"
#define RETRANS_FMT "%sretrans = %d"
#define RETRANS_FMT_BRIEF " %d %sretrans"
#define RETRANS_FMT_BRIEF_STR1 " %d = %d"
#define RETRANS_FMT_BRIEF_STR2 " retrans"
#define RETRANS_FMT_INTERVAL " %5d %sretrans"
#define RETRANS_FMT_IN "retrans = %d"
#define RTT_FMT " RTT=%.3f ms"
#define RTT_FMT_BRIEF " %.2f msRTT"
#define RTT_FMT_IN "RTT=%lf"
#define RTT_FMT_INB "RTT = %lf"
#define SIZEOF_TCP_INFO_RETRANS 104
/* define NEW_TCP_INFO if struct tcp_info in /usr/include/netinet/tcp.h
* contains tcpi_total_retrans member
*
* tcpi_rcv_rtt, tcpi_rcv_space, & tcpi_total_retrans were added
* in glibc-headers-2.7 (Fedora 8) which fortunately also defined
* TCP_MD5SIG at the same time, so key off of that
*/
#if defined(linux) && defined(TCP_MD5SIG)
#define NEW_TCP_INFO
#endif
#ifndef NEW_TCP_INFO
#define OLD_TCP_INFO
#endif
/* Parsable output formats */
#define P_PERF_FMT_OUT "megabytes=%.4f real_seconds=%.2f " \
"rate_KBps=%.2f rate_Mbps=%.4f\n"
#define P_PERF_FMT_BRIEF "megabytes=%.4f real_seconds=%.2f rate_Mbps=%.4f " \
"tx_cpu=%d rx_cpu=%d"
#define P_PERF_FMT_BRIEF3 " tx_megabytes=%.4f"
#define P_PERF_FMT_INTERVAL "megabytes=%.4f real_sec=%.2f rate_Mbps=%.4f"
#define P_PERF_FMT_INTERVAL2 " total_megabytes=%.4f total_real_sec=%.2f" \
" total_rate_Mbps=%.4f"
#define P_PERF_FMT_INTERVAL3 " tx_megabytes=%.4f"
#define P_PERF_FMT_INTERVAL4 " tx_total_megabytes=%.4f"
#define P_PERF_FMT_IN "megabytes=%lf real_seconds=%lf rate_KBps=%lf " \
"rate_Mbps=%lf\n"
#define P_CPU_STATS_FMT_IN "user=%*f system=%*f elapsed=%*d:%*d cpu=%d%%"
#define P_CPU_STATS_FMT_IN2 "user=%*f system=%*f elapsed=%*d:%*d:%*d cpu=%d%%"
#define P_LOSS_FMT " data_loss=%.5f"
#define P_LOSS_FMT_BRIEF " data_loss=%.5f"
#define P_LOSS_FMT_INTERVAL " data_loss=%.5f"
#define P_DROP_FMT " drop=%lld pkt=%lld"
#define P_DROP_FMT_BRIEF " drop=%lld pkt=%lld"
#define P_DROP_FMT_INTERVAL " drop=%lld pkt=%lld"
#define P_JITTER_FMT "msminjitter=%.4f msavgjitter=%.4f " \
"msmaxjitter=%.4f"
#define P_JITTER_MIN_FMT_BRIEF " msminjitter=%.4f"
#define P_JITTER_AVG_FMT_BRIEF " msavgjitter=%.4f"
#define P_JITTER_MAX_FMT_BRIEF " msmaxjitter=%.4f"
#define P_JITTER_MIN_FMT_INTERVAL " msminjitter=%.4f"
#define P_JITTER_AVG_FMT_INTERVAL " msavgjitter=%.4f"
#define P_JITTER_MAX_FMT_INTERVAL " msmaxjitter=%.4f"
#define P_JITTER_FMT_IN "jitter=%lf msavgjitter=%lf msmaxjitter=%lf"
#define P_OWD_FMT "msminOWD=%.4f msavgOWD=%.4f msmaxOWD=%.4f"
#define P_OWD_MIN_FMT_BRIEF " msminOWD=%.4f"
#define P_OWD_AVG_FMT_BRIEF " msavgOWD=%.4f"
#define P_OWD_MAX_FMT_BRIEF " msmaxOWD=%.4f"
#define P_OWD_MIN_FMT_INTERVAL " msminOWD=%.4f"
#define P_OWD_AVG_FMT_INTERVAL " msavgOWD=%.4f"
#define P_OWD_MAX_FMT_INTERVAL " msmaxOWD=%.4f"
#define P_OWD_FMT_IN "OWD=%lf msavgOWD=%lf msmaxOWD=%lf"
#define P_RETRANS_FMT "%sretrans=%d"
#define P_RETRANS_FMT_STREAMS " retrans_by_stream=%d"
#define P_RETRANS_FMT_BRIEF " %sretrans=%d"
#define P_RETRANS_FMT_INTERVAL " %sretrans=%d"
#define P_RETRANS_FMT_IN "retrans=%d"
#define P_RTT_FMT " rtt_ms=%.3f"
#define P_RTT_FMT_BRIEF " rtt_ms=%.2f"
#define P_RTT_FMT_IN "rtt_ms=%lf"
#define HELO_FMT "HELO nuttcp v%d.%d.%d\n"
#ifndef MAXSTREAM
#define MAXSTREAM 128
#endif
#define DEFAULT_NBUF 2048
#define DEFAULT_NBYTES 134217728 /* 128 MB */
#define DEFAULT_TIMEOUT 10.0
#define DEFAULT_UDP_RATE 1000
#define DEFAULTUDPBUFLEN 8192
#define DEFAULT_MC_UDPBUFLEN 1024
#define MAXUDPBUFLEN 65507
#define LOW_RATE_HOST3 1000
#define MINMALLOC 1024
#define HI_MC 231ul
#define HI_MC_SSM 232ul
/* locally defined global scope IPv6 multicast, FF3E::8000:0-FF3E::FFFF:FFFF */
#define HI_MC6 "FF3E::8000:0000"
#define HI_MC6_LEN 13
#ifndef LISTEN_BACKLOG
#define LISTEN_BACKLOG 64
#endif
#define ACCEPT_TIMEOUT 5
#ifndef MAX_CONNECT_TRIES
#define MAX_CONNECT_TRIES 10 /* maximum server connect attempts */
#endif
#ifndef SERVER_RETRY_USEC
#define SERVER_RETRY_USEC 500000 /* server retry time in usec */
#endif
#define MAX_EOT_WAIT_SEC 60.0 /* max wait for unacked data at EOT */
#define SRVR_INFO_TIMEOUT 60 /* timeout for reading server info */
#define IDLE_DATA_MIN 15.0 /* minimum value for chk_idle_data */
#define DEFAULT_IDLE_DATA 30.0 /* default value for chk_idle_data */
#define IDLE_DATA_MAX 60.0 /* maximum value for chk_idle_data */
#define NON_JUMBO_ETHER_MSS 1448 /* 1500 - 20:IP - 20:TCP -12:TCPOPTS */
#define TCP_UDP_HDRLEN_DELTA 12 /* difference in tcp & udp hdr sizes */
#if defined(linux)
#define TCP_ADV_WIN_SCALE "/proc/sys/net/ipv4/tcp_adv_win_scale"
#endif
#define BRIEF_RETRANS_STREAMS 0x2 /* brief per stream retrans info */
#define XMITSTATS 0x1 /* also give transmitter stats (MB) */
#define DEBUGINTERVAL 0x2 /* add info to assist with
* debugging interval reports */
#define RUNNINGTOTAL 0x4 /* give cumulative stats for "-i" */
#define NODROPS 0x8 /* no packet drop stats for "-i" */
#define NOPERCENTLOSS 0x10 /* don't give percent loss for "-i" */
#define DEBUGPOLL 0x20 /* add info to assist with debugging
* polling for interval reports */
#define PARSE 0x40 /* generate key=value parsable output */
#define DEBUGMTU 0x80 /* debug info for MTU/MSS code */
#define NORETRANS 0x100 /* no retrans stats for "-i" */
#define DEBUGRETRANS 0x200 /* output info for debugging collection
* of TCP retransmission info */
#define NOBETAMSG 0x400 /* suppress beta version message */
#define WANTRTT 0x800 /* output RTT info (default) */
#define DEBUGJITTER 0x1000 /* debugging info for jitter option */
#ifdef NO_IPV6 /* Build without IPv6 support */
#undef AF_INET6
#undef IPV6_V6ONLY
#endif
void sigpipe( int signum );
void sigint( int signum );
void ignore_alarm( int signum );
void sigalarm( int signum );
static void err( char *s );
static void mes( char *s );
static void errmes( char *s );
void pattern( char *cp, int cnt );
void prep_timer();
double read_timer( char *str, int len );
static void prusage( struct rusage *r0, struct rusage *r1, struct timeval *e, struct timeval *b, char *outp );
static void tvadd( struct timeval *tsum, struct timeval *t0, struct timeval *t1 );
static void tvsub( struct timeval *tdiff, struct timeval *t1, struct timeval *t0 );
static void psecs( long l, char *cp );
int Nread( int fd, char *buf, int count );
int Nwrite( int fd, char *buf, int count );
int delay( int us );
int mread( int fd, char *bufp, unsigned n);
char *getoptvalp( char **argv, int index, int reqval, int *skiparg );
int get_retrans( int sockfd );
#if defined(linux) && defined(TCPI_OPT_TIMESTAMPS)
void print_tcpinfo();
#endif
#ifdef SSL_AUTH
/*
* SSL handshake interface, provided by library-specific compilation units
*/
int ctl_init_ssl_client(int, const char *, const char *, const char *,
const char *, const char *);
int ctl_init_ssl_server(int, const char *, const char *, const char *,
const char *);
#define DEFAULT_SSL_CERT "cert.pem"
#define DEFAULT_SSL_KEY "key.pem"
int ssl_enabled = 0;
const char *ssl_cert = DEFAULT_SSL_CERT;
const char *ssl_key = DEFAULT_SSL_KEY;
const char *ssl_ca = NULL; /* default: chain from ssl_cert */
#endif
int vers_major = 7;
int vers_minor = 1;
int vers_delta = 6;
int ivers;
int rvers_major = 0;
int rvers_minor = 0;
int rvers_delta = 0;
int irvers;
int beta = 0;
struct sockaddr_in sinme[MAXSTREAM + 1];
struct sockaddr_in sinhim[MAXSTREAM + 1];
struct sockaddr_in save_sinhim, save_mc;
#ifdef AF_INET6
struct sockaddr_in6 sinme6[MAXSTREAM + 1];
struct sockaddr_in6 sinhim6[MAXSTREAM + 1];
struct sockaddr_in6 save_sinhim6, save_mc6;
struct in6_addr hi_mc6;
#endif
struct sockaddr_storage frominet;
int domain = PF_UNSPEC;
int af = AF_UNSPEC;
int explicitaf = 0; /* address family explicit specified (-4|-6) */
int fd[MAXSTREAM + 1]; /* fd array of network sockets */
int nfd; /* fd for accept call */
struct pollfd pollfds[MAXSTREAM + 4]; /* used for reading interval reports */
socklen_t fromlen;
int buflen = 64 * 1024; /* length of buffer */
int nbuflen;
int mallocsize;
char *buf; /* ptr to dynamic buffer */
unsigned long long nbuf = 0; /* number of buffers to send in sinkmode */
int nbuf_bytes = 0; /* set to 1 if nbuf is actually bytes */
/* nick code */
int sendwin=0, sendwinval=0, origsendwin=0;
socklen_t optlen;
int rcvwin=0, rcvwinval=0, origrcvwin=0;
int srvrwin=0;
/* end nick code */
#if defined(linux)
int sendwinavail=0, rcvwinavail=0, winadjust=0;
#endif
#if defined(linux) && defined(TCPI_OPT_TIMESTAMPS)
#ifdef OLD_TCP_INFO
struct tcpinfo { /* for collecting TCP retransmission info */
struct tcp_info _tcpinf;
/* add missing structure elements */
u_int32_t tcpi_rcv_rtt;
u_int32_t tcpi_rcv_space;
u_int32_t tcpi_total_retrans;
} tcpinf;
#define tcpinfo_state _tcpinf.tcpi_state
#define tcpinfo_ca_state _tcpinf.tcpi_ca_state
#define tcpinfo_retransmits _tcpinf.tcpi_retransmits
#define tcpinfo_unacked _tcpinf.tcpi_unacked
#define tcpinfo_sacked _tcpinf.tcpi_sacked
#define tcpinfo_lost _tcpinf.tcpi_lost
#define tcpinfo_retrans _tcpinf.tcpi_retrans
#define tcpinfo_fackets _tcpinf.tcpi_fackets
#define tcpinfo_rtt _tcpinf.tcpi_rtt
#define tcpinfo_rttvar _tcpinf.tcpi_rttvar
#define tcpinfo_snd_ssthresh _tcpinf.tcpi_snd_ssthresh
#define tcpinfo_snd_cwnd _tcpinf.tcpi_snd_cwnd
#else
struct tcp_info tcpinf;
#define tcpinfo_state tcpi_state
#define tcpinfo_ca_state tcpi_ca_state
#define tcpinfo_retransmits tcpi_retransmits
#define tcpinfo_unacked tcpi_unacked
#define tcpinfo_sacked tcpi_sacked
#define tcpinfo_lost tcpi_lost
#define tcpinfo_retrans tcpi_retrans
#define tcpinfo_fackets tcpi_fackets
#define tcpinfo_rtt tcpi_rtt
#define tcpinfo_rttvar tcpi_rttvar
#define tcpinfo_snd_ssthresh tcpi_snd_ssthresh
#define tcpinfo_snd_cwnd tcpi_snd_cwnd
#endif
#endif
int udp = 0; /* 0 = tcp, !0 = udp */
int udplossinfo = 0; /* set to 1 to give UDP loss info for
* interval reporting */
int do_jitter = 0; /* set to 1 to enable jitter measurements */
int do_owd = 0; /* set to 1 to enable one-way delay reports */
int retransinfo = 0; /* set to 1 to give TCP retransmission info
* for interval reporting */
int force_retrans = 0; /* set to force sending retrans info */
int send_retrans = 1; /* set to 0 if no need to send retrans info */
int do_retrans = 0; /* set to 1 for client transmitter */
int read_retrans = 1; /* set to 0 if no need to read retrans info */
int got_0retrans = 0; /* set to 1 by client transmitter after
* processing initial server output
* having "0 retrans" */
int need_swap; /* client and server are different endian */
int options = 0; /* socket options */
int one = 1; /* for 4.3 BSD style setsockopt() */
/* default port numbers if command arg or getserv doesn't get a port # */
#define DEFAULT_PORT 5101
#define DEFAULT_CTLPORT 5000
#define IPERF_PORT 5001
unsigned short port = 0; /* TCP port number */
unsigned short ctlport = 0; /* control port for server connection */
unsigned short ctlport3 = 0; /* control port for 3rd party server conn */
int tmpport;
char *host; /* ptr to name of host */
char *stride = NULL; /* ptr to address stride for multi-stream */
char *host3 = NULL; /* ptr to 3rd party host */
int thirdparty = 0; /* set to 1 indicates doing 3rd party nuttcp */
int no3rd = 0; /* set to 1 by server to disallow 3rd party */
int forked = 0; /* set to 1 after server has forked */
int pass_ctlport = 0; /* set to 1 to use same outgoing control port
as incoming with 3rd party usage */
char *nut_cmd; /* command used to invoke nuttcp */
char *cmdargs[50]; /* command arguments array */
char tmpargs[50][40];
#ifndef AF_INET6
#define ADDRSTRLEN 16
#else
#define ADDRSTRLEN INET6_ADDRSTRLEN
int v4mapped = 0; /* set to 1 to enable v4 mapping in v6 server */
#endif
#define HOSTNAMELEN 80
#define HOST3BUFLEN HOSTNAMELEN + 2 + ADDRSTRLEN + 1 + ADDRSTRLEN
/* host3=[=]host3addr[+host3stride] */
char hostbuf[ADDRSTRLEN]; /* buffer to hold text of address */
char host3addr[ADDRSTRLEN]; /* buffer to hold text of 3rd party address */
char host3buf[HOST3BUFLEN + 1]; /* buffer to hold 3rd party name or address */
char clientbuf[NI_MAXHOST]; /* buffer to hold client's resolved hostname */
int trans = 1; /* 0=receive, !0=transmit mode */
int sinkmode = 1; /* 0=normal I/O, !0=sink/source mode */
#if defined(linux)
int zerocopy = 0; /* set to enable zero copy via sendfile() */
#endif
int nofork = 0; /* set to 1 to not fork server */
int verbose = 0; /* 0=print basic info, 1=print cpu rate, proc
* resource usage. */
int nodelay = 0; /* set TCP_NODELAY socket option */
unsigned long rate = MAXRATE; /* transmit rate limit in Kbps */
int maxburst = 1; /* number of packets allowed to exceed rate */
int nburst = 1; /* number of packets currently exceeding rate */
int irate = -1; /* instantaneous rate limit if set */
double pkt_time; /* packet transmission time in seconds */
double pkt_time_ms; /* packet transmission time in milliseconds */
uint64_t irate_pk_usec; /* packet transmission time in microseconds */
double irate_pk_nsec; /* nanosecond portion of pkt xmit time */
double irate_cum_nsec = 0.0; /* cumulative nanaseconds over several pkts */
int rate_pps = 0; /* set to 1 if rate is given as pps */
double timeout = 0.0; /* timeout interval in seconds */
double interval = 0.0; /* interval timer in seconds */
double chk_idle_data = 0.0; /* server receiver checks this often */
/* for client having gone away */
double chk_interval = 0.0; /* timer (in seconds) for checking client */
int ctlconnmss; /* control connection maximum segment size */
int datamss = 0; /* data connection maximum segment size */