4 * Copyright (C) 2009, Broadcom Corporation
7 * THIS SOFTWARE IS OFFERED "AS IS", AND BROADCOM GRANTS NO WARRANTIES OF ANY
8 * KIND, EXPRESS OR IMPLIED, BY STATUTE, COMMUNICATION OR OTHERWISE. BROADCOM
9 * SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS
10 * FOR A SPECIFIC PURPOSE OR NONINFRINGEMENT CONCERNING THIS SOFTWARE.
12 * $Id: epi_ttcp.c,v 7.41 2008/10/08 02:34:37 Exp $
18 * Test TCP connection. Makes a connection on port 5010
19 * and transfers fabricated buffers or data copied from stdin.
21 * Usable on 4.2, 4.3, and 4.1a systems by defining one of
22 * BSD42 BSD43 (BSD41a)
23 * Machines using System V with BSD sockets should define SYSV.
25 * Modified for operation under 4.2BSD, 18 Dec 84
27 * Minor improvements, Mike Muuss and Terry Slattery, 16-Oct-85.
28 * Modified in 1989 at Silicon Graphics, Inc.
29 * catch SIGPIPE to be able to print stats when receiver has died
30 * for tcp, don't look for sentinel during reads to allow small transfers
31 * increased default buffer size to 8K, nbuf to 2K to transfer 16MB
32 * moved default port to 5001, beyond IPPORT_USERRESERVED
33 * make sinkmode default because it is more popular,
34 * -s now means don't sink/source
35 * count number of read/write system calls to see effects of
36 * blocking from full socket buffers
37 * for tcp, -D option turns off buffered writes (sets TCP_NODELAY sockopt)
38 * buffer alignment options, -A and -O
39 * print stats in a format that's a bit easier to use with grep & awk
40 * for SYSV, mimic BSD routines to use most of the existing timing code
41 * Modified by Steve Miller of the University of Maryland, College Park
42 * -b sets the socket buffer size (SO_SNDBUF/SO_RCVBUF)
43 * Modified Sept. 1989 at Silicon Graphics, Inc.
44 * restored -s sense at request of tcs@brl
45 * Modified Oct. 1991 at Silicon Graphics, Inc.
46 * use getopt(3) for option processing, add -f and -T options.
47 * SGI IRIX 3.3 and 4.0 releases don't need #define SYSV.
49 * Modified --> Nov 1996 at CERN (Daniel DAVIDS)
50 * printout of the Socket-Buffer-Sizes
51 * configured for HP-UX 9000 OS
52 * configured for Windows NT OS
53 * Modified Dec 1996 at CERN (Jacques ROCHEZ)
55 * addaptation to the gcc compiler (ANSI)
56 * configured for Lynx OS
57 * automatic format for the rate display (G/M/K/)bytes/sec
58 * added log (L) and more help (h) options.
59 * Modified May 1997 at CERN (Jacques ROCHEZ)
60 * removed the mes() function following err() function.
61 * changed the default port to 5010
62 * Modified jul 1997 at CERN (Jacques ROCHEZ)
63 * adapted the timing calculation in microseconds
64 * addapted the code for Vsisual C++ under NT4.0
65 * Modified aug 1997 at CERN (Jacques ROCHEZ)
66 * initialise to 0 the variables nbytes, numcalls
67 * moved the buffer pre-load outside the measured timed area
68 * Distribution Status -
69 * Public Domain. Distribution Unlimited.
70 * Modified jun 1998 at Epigram
71 * - print hash marks to indicate prograss on transmitting side
72 * - sleep between bursts of buffers
73 * - set number of buffers/burst
74 * Modified jul 1998 at Epigram
75 * - send random size buffers
76 * Modified jan 1999 at Epigram (WES)
77 * - added start and end patterns to UDP start and end packets
78 * - added handling of missed start, end, or data packets for UDP tests
79 * Modified oct 2007 at Broadcom
80 * - print hash marks on receive also
81 * - improve legibility
84 static char RCSid
[] = "ttcp.c $- CERN Revision: 3.8 (dev level) -$";
87 static char VersDate
[] = "Epigram 15-jul-98";
89 /* system dependent setting
90 * ------------------------
91 * uname -a,gcc -v a.c are the tools used
93 * Platform/OS #define MACRO predefined
94 * ----------- ------- ---------------------------------------------------
95 * SunOS OS BSD43 __unix__ __sun__ __sparc__
96 * SUN Solaris SYSV __unix__ __sun__ __sparc__ __svr4__
97 * SGI-IRIX < 3.3 SYSV set as #define sgi
98 * HP-UX 9000 SYSV __unix__ __hpux__ __hp9k8__
99 * OSF/1 V3.2 SYSV __unix__ __osf__ __alpha__
100 * OSF/1 V4.0 SYSV __unix__ __osf__ __alpha__ _CFE
101 * LynxOS SYSV __unix__ __lynx__ __powerpc__
102 * Windows NT SYSV __WINNT__ __i386__ __M_COFF__
103 * AIX SYSV _AIX _AIX32 _POWER _IBMR2 _ARCH_PWR
106 * Micosoft Visual C++ compiler under WindowNT 4.0
107 * Windows NT _WINDOWS WIN32
109 * Unix BSD 41a BSD41a
113 * Machines using System V with BSD sockets should define SYSV.
117 * LynxOS : gcc -c ttcp.c -o ttcp.o | gcc -o ttcp -O ttcp.o -lnetinet -lc_p -lc
120 /* -------------attempt to set an automatic UNIX OS family detection -------*/
122 #if defined(__hp9k8__) || defined(__osf__) || defined(__srv4__)
125 #if defined(__lynx__)
128 /* for solaris (__srv4__) the parameters SYSV is already set */
130 /* version A.09.01 'key words' differs from A.09.05 A */
135 #if defined(__sun__)&&!defined(__srv4__)
136 #define BSD43 /* changed by BSD42 if necessary */
139 #if defined(_WIN32) /* Window NT 4.0 compiled with VisualC++ 4 */
145 #if defined(__FreeBSD__)
149 #if defined(__NetBSD__)
153 #if defined(__linux__)
157 #if defined(__CYGWIN__)
161 /*--------------------------------------------------------------------------*/
163 #if !defined(UNDER_CE)
167 #include <sys/types.h>
173 #include <sys/socket.h>
174 #include <netinet/in.h>
175 #include <netinet/tcp.h>
176 #include <arpa/inet.h>
178 #include <sys/time.h> /* struct timeval */
179 #include <sys/resource.h> /* definition of struct rusage */
181 #else /* else of __osf__ */
182 #if defined(__NTVIS__)
183 #include <winsock2.h>
184 #include <windows.h> /* required for all Windows applications */
185 #include <ws2tcpip.h>
189 #if !defined(UNDER_CE)
190 #include <sys\timeb.h>
194 struct rusage
{ struct timeval ru_utime
, ru_stime
; };
195 #define RUSAGE_SELF 0
196 #else /* else of __NTVIS__ */
197 #if defined(__lynx__)
198 #include <socket.h> /* located in /usr/include/..... */
199 #include <netinet/in.h>
200 #include <netinet/tcp.h>
201 #include <arpa/inet.h>
204 #include <resource.h> /* definition of struct rusage */
205 #include <sys/times.h>
206 #define RUSAGE_SELF 0
207 #include <conf.h> /* definition of TICKSPERSEC (HZ) */
208 #include <sys/param.h>
210 #else /* else of __Lynx__ */
211 #if defined(__svr4__)
212 #include <sys/socket.h>
214 #include <netinet/in.h>
215 #include <netinet/tcp.h>
216 #include <arpa/inet.h>
218 #include <sys/time.h> /* struct timeval */
219 #include <sys/resource.h> /* definition of struct rusage */
220 #include <sys/times.h>
221 #define RUSAGE_SELF 0
222 #include <sys/param.h>
224 #else /* else of __svr4__ all SYSV cases except those mentionned before */
225 #include <sys/socket.h>
226 #include <netinet/in.h>
227 #include <netinet/tcp.h>
228 #include <arpa/inet.h>
230 #include <sys/time.h> /* struct timeval */
231 #include <sys/resource.h> /* definition of struct rusage */
232 #include <sys/times.h>
233 #define RUSAGE_SELF 0
234 #include <sys/param.h>
236 #endif /* __svr4__ */
237 #endif /* __lynx__ */
238 #endif /* __NTVIS__ */
241 #else /* else of SYSV it is a BSD OS */
244 #include <sys/socket.h>
245 #include <netinet/in.h>
246 #include <netinet/tcp.h>
247 #include <arpa/inet.h>
249 #if defined(__linux__)
250 #include <time.h> /* struct tm */
251 #include <sys/time.h> /* struct timeval */
254 #include <sys/time.h> /* struct timeval */
256 #include <sys/resource.h> /* definition of struct rusage */
257 #include <unistd.h> /* for usleep() - henry */
258 #define SOCKET_ERROR -1
262 #if defined(__NTVIS__)
263 #if defined(_DEBUG) /* usual debug symbol for VC++ */
267 void usleep(unsigned int microseconds
);
269 #define bcopy(a,b,n) memcpy((b), (a), (n))
270 #define bzero(a,n) memset((a), 0, (n))
274 int getopt(int argc
, char **argv
, char *optstring
);
276 extern char *optarg
; // returned arg to go with this option
277 extern int optind
; // index to next argv element to process
278 extern int opterr
; // should error messages be printed?
279 extern int optopt
; //
284 /* get option letter from argument vector */
285 int opterr
= 1, // should error messages be printed?
286 optind
= 1, // index into parent argv vector
287 optopt
; // character checked for validity
288 char *optarg
; // argument associated with option
291 char *progname
; // may also be defined elsewhere
294 /* sockaddr_in == file server address structure
296 * Socket address, internet style. declared in : /netinet/in.h
297 * struct sockaddr_in {short sin_family;
299 * struct in_addr sin_addr;
303 * Structure used by kernel to store most addresses. declared in ./sys/socket.h
304 * struct sockaddr{u_short sa_family; address family
305 * char sa_data[14]; up to 14 bytes of direct address
307 * PS : sin stand for "socket internet number"
314 #if defined(__SOCKADDR_ARG)
315 #define SOCKADDR_CAST (__SOCKADDR_ARG)
316 #elif defined(__lynx__) || defined(__sun__) || defined(_AIX) || defined(__FreeBSD__) \
317 || defined(__NTVIS__) || defined(__NetBSD__) || defined(__CYGWIN__)
318 #define SOCKADDR_CAST (struct sockaddr FAR *)
320 #define SOCKADDR_CAST
324 struct sockaddr_in sockaddr
; /* done in ./X11/Xdmcp.h */
327 struct sockaddr_in sinme
; /* is the socket struct. in the local host */
328 struct sockaddr_in sinhim
; /* is the socket struc. in the remote host */
330 #if defined(__lynx__) || defined(__svr4__) || defined(_AIX)
331 struct sockaddr frominet
;
333 struct sockaddr_in frominet
;
334 #endif /* __lynx__ */
338 #if !defined(__NTVIS__)
340 #endif /* __NTVIS__ */
341 SOCKET fd
; /* fd of network socket */
343 #if !defined(__lynx__)
349 FILE *fplog
= NULL
; /* file pointer for the log file */
350 char logfile
[100]; /* file name for the log */
351 static char logfile_head
[] ="ttcp_log"; /* header name for the log */
352 int buflen
= 8 * 1024; /* length of buffer */
353 char *buf
; /* ptr to dynamic buffer */
354 int nbuf
= 2 * 1024; /* number of buffers to send in sinkmode */
356 #define START_PKT_LEN 4
357 #define START_PATTERN_LEN 4
358 #define END_PKT_LEN 8
359 #define END_PATTERN_LEN 4
360 #define MIN_UDP_LEN 5
362 char start_pattern
[START_PATTERN_LEN
] = {1, 2, 3, 4};
363 char end_pattern
[END_PATTERN_LEN
] = {2, 2, 2, 2};
365 int bufoffset
= 0; /* align buffer to this */
366 int bufalign
= 16*1024; /* modulo this */
368 int udp
= 0; /* 0 = tcp, !0 = udp */
369 int options
= 0; /* socket options */
370 int one
= 1; /* for 4.3 BSD style setsockopt() */
371 short port
= 5010; /* TCP port number */
372 char *host
; /* ptr to name of host */
373 int rndm
= 0; /* 0="normal", !0=random data */
374 int trans
; /* 0=receive, !0=transmit mode */
375 int timeout
; /* read timeout in millisec */
376 int debug
= 0; /* 0=No-Debug, 1=Debug-Set-On */
377 int sinkmode
= 0; /* 0=normal I/O, !0=sink/source mode */
378 int verbose
= 0; /* 0=print basic info, 1=print cpu rate,
379 * proc resource usage. */
380 int nodelay
= 0; /* set TCP_NODELAY socket option */
381 int pri
= 0; /* link layer priority */
382 int b_flag
= 0; /* use mread() */
383 int log_cnt
= 0; /* append result to a log */
384 int sockbufsize
= 0; /* socket buffer size to use */
385 char fmt
= 'A'; /* output format:
386 * b = bits, B = bytes,
387 * k = kilobits, K = kilobytes,
388 * m = megabits, M = megabytes,
389 * g = gigabits, G = gigabytes,
390 * A = automatic Xbytes (default) */
391 int touchdata
= 0; /* access data after reading */
392 int seq_info
= 0; /* report out of order seq nums */
394 int hash
= 0; /* print hash marks for each buffer */
395 int bufsleep
= 0; /* sleep in between buffers */
396 int burstn
= 1; /* number of buffers per burst */
397 int bufmin
= -1; /* minimum buffer size to use when
398 sending random-size buffers */
399 unsigned int seed
= 1; /* seed for random number generator
400 used for random buffer lengths */
401 int no_start
= 0; /* skip the start frames for UDP */
402 int no_data
= 0; /* skip all data frames for UDP */
403 int no_end
= 0; /* skip the end frames for UDP */
405 double nbytes
; /* bytes on net */
406 unsigned long numCalls
; /* # of I/O system calls */
408 struct hostent
*addr
;
412 #if defined(UNDER_CE)
414 static char *weekday
[] ={"Sun", "Mon","Tues", "Wed", "Thurs", "Fri", "Sat"};
415 static char *month
[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sep", "Oct", "Nov", "Dec"};
416 #define perror printf
419 /*--------------------------------------------------------------------------*/
420 static struct timeval time0
; /* Time at which timing started */
421 static struct timeval time1
;
422 static struct rusage ru0
; /* Resource utilization at the start */
423 static struct rusage ru1
;
424 static struct tm
*tms
; /* system time structure */
427 /*-----------Prototype functions definitions -------------------------------*/
428 /*--------------------------------------------------------------------------*/
430 /* ANSI input/output functions (stdio.h) */
432 #if defined(__lynx__)
433 int getopt(int, char**, char*);
434 int gettimeofday(struct timeval
*tp
, struct timezone
*tzp
);
437 #if defined(__svr4__)
443 #if defined(__hpux__)
445 #if defined(__NTVIS__)
447 #if defined(BSD42) || defined(BSD43)
450 int printf( char*, ...);
451 int fprintf(FILE*,char*, ...);
453 int getopt(int, char**, char*);
454 int gettimeofday(struct timeval
*tp
, struct timezone
*tzp
);
455 #endif /* BSD42 || BSD43 */
456 #endif /* __NTVIS__ */
457 #endif /* __hpux__ */
459 #endif /* __svr4__ */
460 #endif /* __lynx__ */
462 int main(int argc
, char* argv
[]);
463 #if ( (!(defined(BSD42))) && (!(defined(BSD43))) && (!(defined(__NTVIS__))) )
464 int read(int, char*, int);
465 int write(int, char*, int);
467 #endif /* !(BSD42) && !(BSD43) */
468 int fclose(FILE *stream
);
470 #if !defined(BSD43) && !defined(__NTVIS__)
471 void bzero(char*,int);
472 void bcopy(char*, char*, int);
473 char strncpy(char *s1
,char *s2
,size_t n
);
479 /* ANSI socket functions prototype /sys/socket.h */
480 #if defined(__lynx__)
481 int select(int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*);
484 #if defined(__svr4__) && !defined(sparc)
486 /* informations in : /usr/include/sys/socket.h */
487 int socket(int, int, int);
488 int connect(int, struct sockaddr
*, int);
489 int bind(int, struct sockaddr
*, int);
490 int listen(int, int);
491 int accept(int, struct sockaddr
*, int *);
492 int sendto(int, const char *, int, int, const struct sockaddr
*, int);
493 int recvfrom(int, char *, int, int, struct sockaddr
*, int *);
494 int getpeername(int, struct sockaddr
*, int *);
495 int getsockopt(int, int, int, char *, int *);
496 int select(int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*);
500 int select(unsigned long, void *, void *, void *, struct timeval
*);
503 #if defined(__hpux__)
504 int getrusage(int who
,struct rusage
*rusage
);
507 #if defined(__NTVIS__)
510 #if defined(BSD42) || defined(BSD43)
514 int socket(int, int, int);
515 int connect(int s
,struct sockaddr_in
*name
, int namelen
);
516 int bind(int s
,struct sockaddr
*name
,int namelen
);
517 int listen(int, int);
518 int accept(int, struct sockaddr_in
*, int *);
519 int sendto(int, char *, int, int, struct sockaddr_in
*, int);
520 int recvfrom(int, char *, int, int, struct sockaddr_in
*, int *);
521 int getpeername(int, struct sockaddr
*, int *);
522 int setsockopt(int, int, int, char *, int);
524 int getsockopt(int, int, int, char*, int*);
525 int select(int, fd_set
*, fd_set
*, fd_set
*, struct timeval
*);
527 #endif /* BSD42 || BSD43 */
528 #endif /* __hpux__ */
530 #endif /* __svr4__ */
531 #endif /* __lynx__ */
532 #endif /* __NTVIS__ */
534 /* ttcp prototype functions */
535 void udp_rcv_test(void);
536 double calc_cpu_time(struct rusage
*r0
, struct rusage
*r1
);
537 double calc_real_time(struct timeval
*t0
, struct timeval
*t1
);
538 int getrusage(int who
,struct rusage
*rusage
);
539 void sockets_err(char*);
542 void pattern(char *, int);
543 int Nread(SOCKET
, void *, int);
544 int Nwrite(int, void *, int);
546 int mread(int, char *,unsigned);
547 char *outfmt(char format
, double b
);
548 void prep_timer(void);
549 void read_timer(void);
550 void result_summary(void);
551 void prusage(struct rusage
*, struct rusage
*,
552 struct timeval
*, struct timeval
*);
553 void tvadd(struct timeval
*tsum
, struct timeval
*t0
,struct timeval
*t1
);
554 void tvsub(struct timeval
*tdiff
, struct timeval
*t1
, struct timeval
*t0
);
557 void close_log(void);
560 void hash_print(void);
561 void hash_done(void);
563 /*--------------------------------------------------------------------------*/
564 #if !defined(__NTVIS__)
568 fprintf(stderr
, "SIGPIPE\n");
571 /*--------------------------------------------------------------------------*/
572 /*--------------------------------------------------------------------------*/
574 main(int argc
, char **argv
)
576 unsigned long addr_tmp
;
578 int sockbufsndsize
,sockbufrcvsize
;
580 struct sockaddr_in peer
;
581 int peerlen
= sizeof(peer
);
583 #if defined(__NTVIS__)
586 WSAStartup(MAKEWORD(1,1), &WSAData
);
587 #endif /* __NTVIS__ */
595 while ((c
=getopt(argc
, argv
, "hidrstuvxHVBDTLb:f:l:n:p:A:O:S:N:P:R:I:w:#:")) != -1) {
598 timeout
= atoi(optarg
);
604 burstn
= atoi(optarg
);
607 #if defined(__linux__)
611 fprintf(stderr
, "ttcp: -P option not supported on this OS\n");
615 bufmin
= atoi(optarg
);
618 bufsleep
= atoi(optarg
);
619 if (bufsleep
< 0) bufsleep
= 0;
620 /* convert msec arg to usec for bufsleep, minimum 10ms */
621 bufsleep
= bufsleep
* 1000;
626 case '#': /* does not work on Linux */
630 fprintf(stdout
,"%s %s\n" , RCSid
, VersDate
);
659 "ttcp: -D option ignored: TCP_NODELAY socket option not supported\n");
666 buflen
= atoi(optarg
);
669 sinkmode
= !sinkmode
;
681 bufalign
= atoi(optarg
);
684 bufoffset
= atoi(optarg
);
687 #if defined(SO_SNDBUF) || defined(SO_RCVBUF)
688 sockbufsize
= atoi(optarg
);
691 "ttcp: -b option ignored: "
692 "SO_SNDBUF/SO_RCVBUF socket options not supported\n");
709 }/* while getopt() */
715 /* check for '--' args */
718 break; /* while (1) */
720 } else if (!strcmp(argv
[0], "--nostart")) {
723 } else if (!strcmp(argv
[0], "--nodata")) {
726 } else if (!strcmp(argv
[0], "--noend")) {
729 } else if (!strcmp(argv
[0], "--debug")) {
733 } else if (!strncmp(argv
[0], "--", 2)) {
734 fprintf(stderr
, "ttcp: illegal option: %s\n", argv
[0]);
738 /* the arg was not a '--' arg */
739 break; /* while (1) */
744 /* ----------------------- main part ----------------------- */
746 #if defined(__NTVIS__) && !defined(UNDER_CE)
747 /* Set "stdin" to have binary mode: */
748 if (_setmode(_fileno(stdin
), _O_BINARY
) == -1)
749 perror("%s: Error setting stdin to binary mode");
750 /* Set "stdout" to have binary mode: */
751 if (_setmode(_fileno(stdout
), _O_BINARY
) == -1)
752 perror("%s: Error setting stdout to binary mode");
753 #endif /* __NTVIS__ */
758 /* input error checking */
760 fprintf(stderr
, "ttcp: buffers per burst must be less than or equal to "
761 "total number of buffers\n");
765 fprintf(stderr
, "ttcp: minimum buffer size specified with -R option must "
766 "be non-negative\n");
769 if (buflen
> 65535) {
770 fprintf(stderr
, "ttcp: maximum buffer size specified with -l option must "
774 if (bufmin
> buflen
) {
775 fprintf(stderr
, "ttcp: minimum buffer size specified with -R option must "
776 "be less than or equal to (maximum) buffer size specified with -l\n");
780 /* buffer allocation */
782 if (udp
&& buflen
< MIN_UDP_LEN
)
783 buflen
= MIN_UDP_LEN
; /* send more than the sentinel size */
785 if ( (buf
= (char *)malloc(buflen
+bufalign
)) == (char *)NULL
)
788 buf
+= (bufalign
- ((unsigned long)buf
% bufalign
) + bufoffset
) % bufalign
;
790 fprintf(stderr
,"ttcp%s: buflen=%d, nbuf=%d, align=%d/%d, port=%d\n",
791 trans
?"-t":"-r",buflen
, nbuf
, bufalign
, bufoffset
, port
);
793 fprintf(fplog
," %6d %6d %6d %6d %4d",
794 buflen
, nbuf
, bufalign
, bufoffset
, port
);
796 /* preload the buffer for the transmit condition */
797 pattern( buf
, buflen
);
799 /* seed the random number generator */
800 if ((bufmin
!= -1) || (rndm
!= 0)) {
801 #if defined(__NTVIS__)
803 #else /* ! __NTVIS__ */
805 #endif /* __NTVIS__ */
808 if(trans
) {/* xmitr */
810 fprintf(stderr
, "ttcp: missing destination host arg\n");
815 bzero((char *)&sinhim
, sizeof(sinhim
));
817 if (atoi(host
) > 0 ) {/* Numeric */
818 sinhim
.sin_family
= AF_INET
;
819 sinhim
.sin_addr
.s_addr
= inet_addr(host
);
821 if ((addr
=gethostbyname(host
)) == NULL
)
822 sockets_err("bad hostname");
823 sinhim
.sin_family
= addr
->h_addrtype
;
824 bcopy(addr
->h_addr
,(char*)&addr_tmp
, addr
->h_length
);
825 sinhim
.sin_addr
.s_addr
= addr_tmp
;
827 sinhim
.sin_port
= htons(port
);
828 sinme
.sin_port
= 0; /* free choice */
829 sinme
.sin_addr
.s_addr
= htonl(INADDR_ANY
);
830 sinme
.sin_family
= AF_INET
;
832 sinme
.sin_port
= htons(port
);
833 sinme
.sin_addr
.s_addr
= htonl(INADDR_ANY
);
834 sinme
.sin_family
= AF_INET
;
837 sinme
.sin_family
= AF_INET
;
840 fd
= socket(AF_INET
, udp
?SOCK_DGRAM
:SOCK_STREAM
, 0);
842 #if defined(__NTVIS__)
843 if (fd
== INVALID_SOCKET
)
844 sockets_err("socket");
847 sockets_err("socket");
851 char *label
= trans
?"ttcp-t":"ttcp-r";
852 #if defined(UNDER_CE)
853 SYSTEMTIME SystemTime
;
856 GetLocalTime(&SystemTime
);
857 sprintf(time_str
, "%s %s %d %02d:%02d:%02d %d\n",
858 weekday
[SystemTime
.wDayOfWeek
], month
[SystemTime
.wMonth
- 1],
859 SystemTime
.wDay
, SystemTime
.wHour
, SystemTime
.wMinute
,
860 SystemTime
.wSecond
, SystemTime
.wYear
);
866 time_str
= ctime(&now
);
868 fprintf(stdout
,"%s: start time %s", label
, time_str
);
869 fprintf(stdout
,"%s: File-Descriptor 0x%x Opened\n", label
, fd
);
872 #if defined(__NTVIS__)
873 if (bind(fd
, (struct sockaddr FAR
*)&sinme
, sizeof(sinme
)) == SOCKET_ERROR
)
876 if (bind(fd
, SOCKADDR_CAST
&sinme
, sizeof(sinme
)) < 0)
878 #endif /* __NTVIS__ */
881 #if defined(SO_SNDBUF) || defined(SO_RCVBUF)
883 #if defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
885 if (setsockopt(fd
, SOL_SOCKET
, SO_SNDBUF
, (char *)&sockbufsize
,
886 sizeof sockbufsize
) < 0)
887 sockets_err("setsockopt: sndbuf");
889 if (setsockopt(fd
, SOL_SOCKET
, SO_RCVBUF
, (char *)&sockbufsize
,
890 sizeof sockbufsize
) < 0)
891 sockets_err("setsockopt: rcvbuf");
896 if (setsockopt(fd
, SOL_SOCKET
, SO_SNDBUF
, &sockbufsize
,
897 sizeof sockbufsize
) < 0)
898 sockets_err("setsockopt: sndbuf");
900 if (setsockopt(fd
, SOL_SOCKET
, SO_RCVBUF
, &sockbufsize
,
901 sizeof sockbufsize
) < 0)
902 sockets_err("setsockopt: rcvbuf");
904 #endif /* __lynx__ __sun__ __NTVIS__ */
907 ** Added by Daniel Davids to Know Socket-Buffer-Sizes
909 sockbuflen
= sizeof sockbufsndsize
;
910 #if defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
911 getsockopt(fd
, SOL_SOCKET
, SO_SNDBUF
, (char *)&sockbufsndsize
,
913 sockbuflen
= sizeof sockbufrcvsize
;
914 getsockopt(fd
, SOL_SOCKET
, SO_RCVBUF
, (char *)&sockbufrcvsize
,
917 getsockopt(fd
, SOL_SOCKET
, SO_SNDBUF
, &sockbufsndsize
, &sockbuflen
);
918 sockbuflen
= sizeof sockbufrcvsize
;
919 getsockopt(fd
, SOL_SOCKET
, SO_RCVBUF
, &sockbufrcvsize
, &sockbuflen
);
920 #endif /* __lynx__ __sun__ __NTVIS__ */
921 sockbufsize
= ( sockbufsndsize
+ sockbufrcvsize
) / 2;
923 if ( sockbufsndsize
!= sockbufrcvsize
) {
924 fprintf(stderr
, "sockbufsndsize=%d, ", sockbufsndsize
);
925 fprintf(stderr
, "sockbufrcvsize=%d, ", sockbufrcvsize
);
928 #endif /* defined(SO_SNDBUF) || defined(SO_RCVBUF) */
931 fprintf(stderr
, "sockbufsize=%d, \n", sockbufsize
);
935 fprintf(fplog
," %6d",sockbufsize
);
940 #if defined(__linux__)
941 if (setsockopt(fd
, SOL_SOCKET
, SO_PRIORITY
, (char *)&pri
, sizeof pri
) < 0)
942 sockets_err("setsockopt: priority");
947 fprintf(stderr
, "# %s sender -> %s #\n", udp
?"udp":"tcp", host
);
949 fprintf(stderr
, "# %s receiver #\n", udp
?"udp":"tcp");
952 #if !defined(__NTVIS__)
953 signal(SIGPIPE
, sigpipe
);
954 #endif /* !__NTVIS__ */
956 if (trans
) {/* We are the client if transmitting */
959 if( setsockopt(fd
, SOL_SOCKET
, options
, 0, 0) < 0)
961 if( setsockopt(fd
, SOL_SOCKET
, options
, (char *)&one
, sizeof(one
)) < 0)
963 sockets_err("setsockopt");
968 p
= getprotobyname("tcp");
969 #if defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
970 if( p
&& setsockopt(fd
, p
->p_proto
, TCP_NODELAY
,
971 (char *) &one
, sizeof(one
)) < 0)
973 if( p
&& setsockopt(fd
, p
->p_proto
, TCP_NODELAY
,
974 &one
, sizeof(one
)) < 0)
975 #endif /* __lynx__ __sun__ __NTVIS__ */
976 sockets_err("setsockopt: nodelay");
978 #endif /* TCP_NODELAY */
981 struct timeval ConnectTimeout
;
985 oldval
= fcntl(fd
, F_GETFL
, 0);
987 fcntl(fd
,F_SETFL
, oldval
| O_NONBLOCK
);
993 ConnectTimeout
.tv_sec
= timeout
/1000;
995 ConnectTimeout
.tv_usec
= (timeout
%1000)*1000;
997 connect(fd
, SOCKADDR_CAST
&sinhim
, sizeof(sinhim
));
999 ret
= select(fd
+1, (fd_set
*) 0, &wset
, (fd_set
*) 0, &ConnectTimeout
);
1002 /* Select timed out */
1003 sockets_err("connect");
1005 fcntl(fd
,F_SETFL
, oldval
);
1008 if (connect(fd
, SOCKADDR_CAST
&sinhim
, sizeof(sinhim
) ) < 0)
1009 sockets_err("connect");
1012 if (connect(fd
, SOCKADDR_CAST
&sinhim
, sizeof(sinhim
) ) < 0)
1013 sockets_err("connect");
1015 } else {/* otherwise, we are the server and should listen for connections */
1018 #if defined(sgi) || ( defined(__osf__) && !defined(_CFE) )
1019 if( listen(fd
,1) <0 )
1021 if( listen(fd
,0) <0 ) /* allow a queue of 0 */
1023 sockets_err("listen");
1028 err
= setsockopt(fd
, SOL_SOCKET
, options
, 0, 0);
1029 #elif defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
1030 err
= setsockopt(fd
, SOL_SOCKET
, options
, (char *) &one
, sizeof(one
));
1032 err
= setsockopt(fd
, SOL_SOCKET
, options
, &one
, sizeof(one
));
1035 sockets_err("setsockopt");
1037 fromlen
= sizeof(frominet
);
1040 fd_set readfds
, exceptfds
;
1041 struct timeval tv_timeout
;
1044 tv_timeout
.tv_sec
= timeout
/1000;
1045 tv_timeout
.tv_usec
= (timeout
%1000)*1000;
1048 FD_ZERO(&exceptfds
);
1049 FD_SET(fd
, &readfds
);
1050 FD_SET(fd
, &exceptfds
);
1052 n
= select( fd
+1, &readfds
, NULL
, &exceptfds
, &tv_timeout
);
1053 if (n
== 0 || n
== SOCKET_ERROR
) {
1054 sockets_err("select listen");
1058 if((fd
=accept(fd
, SOCKADDR_CAST
&frominet
, &fromlen
) ) < 0)
1059 sockets_err("accept");
1061 if (getpeername(fd
, SOCKADDR_CAST
&peer
, &peerlen
) < 0)
1062 sockets_err("getpeername");
1064 fprintf(stderr
,"ttcp-r: accept from %s\n",inet_ntoa(peer
.sin_addr
));
1066 } /* otherwise we are ... */
1075 register int cnt
,multi
;
1078 unsigned long rbuflen
= 0;
1082 #if !defined(BSD43) && !defined(UNDER_CE)
1085 int nochecksum_opt
= 0;
1086 err
= setsockopt(fd
, IPPROTO_UDP
, UDP_NOCHECKSUM
,
1087 (char *)&nochecksum_opt
, sizeof(nochecksum_opt
));
1089 sockets_err("setsockopt");
1093 if(udp
&& !no_start
) {
1094 int start_count
= 4;
1095 char start_pkt
[START_PKT_LEN
];
1096 memset(start_pkt
, 0, START_PKT_LEN
);
1097 memcpy(start_pkt
, start_pattern
, START_PATTERN_LEN
);
1099 while (start_count
-- > 0) {
1100 (void)Nwrite( fd
, start_pkt
, START_PKT_LEN
); /* rcvr start */
1103 /* clear errno (see man page for errno(3), definition of
1104 EINTR. usleep() uses SIGCONT? ) */
1105 #if defined(UNDER_CE)
1106 errno
= WSAGetLastError();
1107 if (errno
== WSAEINTR
)
1117 /* initial sequence num for UDP */
1123 while (multi
-- > 0 && !no_data
) {
1128 /* set rbuflen to a random value evenly distributed in
1129 [bufmin, buflen]. As long as buflen is < 2^16, we can
1130 fit the calculation in 32 bits */
1131 #if defined(__NTVIS__)
1132 rbuflen
= (( (unsigned long)rand() *
1133 ((unsigned long)(buflen
-bufmin
+1)) ) >> 15) + bufmin
;
1134 #else /* ! __NTVIS__ */
1135 rbuflen
= (( ((unsigned long)random() >> 15) *
1136 ((unsigned long)(buflen
-bufmin
+1)) ) >> 16) + bufmin
;
1137 #endif /* __NTVIS__ */
1141 unsigned int i
, j
, l
;
1149 for (i
= l
; i
< rbuflen
; /* null */) {
1150 #if defined(__NTVIS__)
1151 data
= (unsigned long)rand();
1152 #else /* ! __NTVIS__ */
1153 data
= (unsigned long)random();
1154 #endif /* __NTVIS__ */
1155 /*fprintf(stderr, "%08x\n",data);*/ /* DEBUG */
1156 /* The NT rand() function returns only 16 useful bits! */
1157 for (j
= 0; (j
< 2/*4*/) && (i
< rbuflen
) ; j
++) {
1158 buf
[i
++] = (unsigned char)(data
& 0xff);
1164 if ((cnt
=Nwrite(fd
,buf
,rbuflen
)) != (int)rbuflen
)
1165 sockets_err("error from the socket write");
1166 /* increment sequence num if UDP */
1168 buf
[0] = (char)(((unsigned char)(buf
[0])+1) & 0xFF);
1171 fprintf(stdout
,"ttcp-t: %5d | %d Bytes Written in %d write commands \n",
1177 /* Check for the end of a burst */
1181 /* sleep to avoid overrunning slower receivers - henry */
1184 /* clear errno (see man page for errno(3), definition of
1185 EINTR. usleep() uses SIGCONT? ) */
1186 #if defined(UNDER_CE)
1187 errno
= WSAGetLastError();
1188 if (errno
== WSAEINTR
)
1199 } else { /* !sinkmode */
1205 /* set rbuflen to a random value evenly distributed in
1206 [bufmin, buflen]. As long as buflen is < 2^16, we can
1207 fit the calculation in 32 bits */
1208 #if defined(__NTVIS__)
1209 rbuflen
= (( (unsigned long)rand() *
1210 ((unsigned long)(buflen
-bufmin
+1)) ) >> 15) + bufmin
;
1211 #else /* ! __NTVIS__ */
1212 rbuflen
= (( ((unsigned long)random() >> 15) *
1213 ((unsigned long)(buflen
-bufmin
+1)) ) >> 16) + bufmin
;
1214 #endif /* __NTVIS__ */
1222 #if !defined(__NTVIS__) /* else case specific to WINNT */
1223 while((cnt
=read(0,pb
,rbuflen
)) > 0)
1224 #else /* __NTVIS__ */
1225 while((cnt
=(int)fread(pb
,1,rbuflen
,stdin
)) > 0)
1226 #endif /* __NTVIS__ */
1229 multi
= cnt
+1; /* don't include seq. num. in count of data */
1232 if ((cnt
=Nwrite(fd
,buf
,multi
)) != (int)multi
)
1233 sockets_err("error from the socket write");
1234 /* increment seqence num if UDP */
1236 buf
[0] = (char)(((unsigned char)(buf
[0])+1) & 0xFF);
1240 fprintf(stdout
,"ttcp-t: %5d | %d Bytes Written in %d write commands \n",
1246 /* Check for the end of a burst */
1252 /* clear errno (see man page for errno(3), definition of
1253 EINTR. usleep() uses SIGCONT? ) */
1254 #if defined(UNDER_CE)
1255 errno
= WSAGetLastError();
1256 if (errno
== WSAEINTR
)
1268 /* set rbuflen to a random value evenly distributed in
1269 [bufmin, buflen]. As long as buflen is < 2^16, we can
1270 fit the calculation in 32 bits */
1271 #if defined(__NTVIS__)
1272 rbuflen
= (( (unsigned long)rand() *
1273 ((unsigned long)(buflen
-bufmin
+1)) ) >> 15) + bufmin
;
1274 #else /* ! __NTVIS__ */
1275 rbuflen
= (( ((unsigned long)random() >> 15) *
1276 ((unsigned long)(buflen
-bufmin
+1)) ) >> 16) + bufmin
;
1277 #endif /* __NTVIS__ */
1283 } /* if (sinkmode) */
1285 #if defined(UNDER_CE)
1286 errno
= WSAGetLastError();
1290 if(udp
&& !no_end
) {
1292 int data_count
= nbuf
;
1293 char end_pkt
[END_PKT_LEN
];
1294 unsigned char* net_byte
= &end_pkt
[END_PATTERN_LEN
];
1295 memset(end_pkt
, 0, END_PKT_LEN
);
1296 memcpy(end_pkt
, end_pattern
, END_PATTERN_LEN
);
1297 net_byte
[3] = data_count
& 0xFF; data_count
>>= 8;
1298 net_byte
[2] = data_count
& 0xFF; data_count
>>= 8;
1299 net_byte
[1] = data_count
& 0xFF; data_count
>>= 8;
1300 net_byte
[0] = data_count
& 0xFF;
1302 while (end_count
-- > 0) {
1303 Nwrite( fd
, end_pkt
, END_PKT_LEN
); /* rcvr end */
1304 if (bufsleep
&& end_count
>0)
1314 while ((cnt
=Nread(fd
,buf
,buflen
)) > 0) {
1317 "ttcp%s: %5d | %d Bytes Read\n",
1318 trans
?"-t":"-r", ++nb
, cnt
);
1322 #if !defined(__NTVIS__) /* else case specific to WINNT */
1323 if (write(1,buf
,cnt
) != cnt
)
1325 #else /* __NTVIS__ */
1326 if ((int)fwrite(buf
,1,cnt
,stdout
) != cnt
)
1328 #endif /* __NTVIS__ */
1332 #if defined(UNDER_CE)
1333 errno
= WSAGetLastError();
1346 #if defined(__NTVIS__)
1350 #endif /* __NTVIS__ */
1353 fprintf(stdout
,"ttcp%s: File-Descriptor fd 0x%x Closed\n" ,
1354 trans
?"-t":"-r", fd
);
1359 fprintf(stderr
,"ttcp done.\n");
1364 /*--------------------------------------------------------------------------*/
1368 enum {START_WAIT
, DATA_WAIT
, DATA_RCV
, END_TEST
} rcv_state
;
1369 enum {START_PKT_TYPE
, END_PKT_TYPE
, DATA_PKT_TYPE
} pkt_type
;
1372 unsigned int start_pkt_cnt
= 0;
1373 unsigned int end_pkt_cnt
= 0;
1374 unsigned int data_pkt_cnt
= 0;
1375 unsigned int expected_pkt_cnt
= 0;
1376 unsigned char seq
= 0;
1377 unsigned char buf_seq
;
1379 rcv_state
= START_WAIT
;
1380 while (rcv_state
!= END_TEST
&& (cnt
=Nread(fd
,buf
,buflen
)) > 0) {
1381 /* Determine the type of packet received */
1382 if (!memcmp(buf
, start_pattern
, START_PATTERN_LEN
)) {
1383 pkt_type
= START_PKT_TYPE
;
1385 } else if (!memcmp(buf
, end_pattern
, END_PATTERN_LEN
)) {
1386 /* read the expected data packet count from the end packet */
1387 unsigned char* net_byte
= buf
;
1388 net_byte
+= END_PATTERN_LEN
;
1389 expected_pkt_cnt
= ((net_byte
[0] << 24) + (net_byte
[1] << 16) +
1390 (net_byte
[2] << 8) + net_byte
[3]);
1391 pkt_type
= END_PKT_TYPE
;
1395 pkt_type
= DATA_PKT_TYPE
;
1398 if (rcv_state
== START_WAIT
) {
1399 /* Wait until we see a vaild start packet */
1400 if (pkt_type
== START_PKT_TYPE
) {
1402 rcv_state
= DATA_WAIT
;
1403 } else if (pkt_type
== DATA_PKT_TYPE
) {
1404 fprintf(stderr
, "ERROR: Missed UDP start packet.\n");
1406 rcv_state
= DATA_RCV
;
1407 } else if (pkt_type
== END_PKT_TYPE
) {
1408 fprintf(stderr
, "ERROR: Found UDP end packet before start packet or data.\n");
1409 rcv_state
= END_TEST
;
1411 } else if (rcv_state
== DATA_WAIT
) {
1412 /* Skip any extra start packets until we see data */
1413 if (pkt_type
== START_PKT_TYPE
) {
1415 } else if (pkt_type
== DATA_PKT_TYPE
) {
1416 rcv_state
= DATA_RCV
;
1417 } else if (pkt_type
== END_PKT_TYPE
) {
1418 fprintf(stderr
, "ERROR: Found UDP end packet without receiving "
1419 "any data packets.\n");
1420 rcv_state
= END_TEST
;
1422 } else { /* DATA_RCV */
1423 /* Collect data packets until we see a vaild end packet */
1424 if (pkt_type
== START_PKT_TYPE
) {
1425 /* We missed the end packets and now a new test is
1426 * starting. Report the results of this test then start
1430 fprintf(stderr
, "ERROR: Found UDP start packet while receiving data.\n"
1431 "ERROR: Expected more data packets or an end packet.\n");
1436 rcv_state
= DATA_WAIT
;
1437 } else if (pkt_type
== DATA_PKT_TYPE
) {
1438 /* loop in this state */
1439 } else if (pkt_type
== END_PKT_TYPE
) {
1440 /* we used to print results here but now we do when the loop ends */
1441 rcv_state
= END_TEST
;
1445 /* tally data packets the same way from whatever state we are in */
1446 if (pkt_type
== DATA_PKT_TYPE
) {
1448 fprintf(stderr
, "ttcp-r: %5d | %d Bytes Read\n", ++nbuffers
, cnt
);
1451 /* check sequence num */
1452 buf_seq
= (unsigned char)(buf
[0]);
1453 if (buf_seq
!= seq
) {
1454 fprintf(stderr
, "ERROR: Out of sequence. "
1455 "Buffer %u, seq %u, expected %u\n",
1456 data_pkt_cnt
, buf_seq
, seq
);
1463 #if !defined(__NTVIS__) /* else case specific to WINNT */
1464 if (write(1,&(buf
[1]),cnt
-1) != cnt
-1)
1466 #else /* __NTVIS__ */
1467 if ((int)fwrite(&(buf
[1]),1,cnt
-1,stdout
) != cnt
-1)
1469 #endif /* __NTVIS__ */
1476 /* normal end of test */
1479 fprintf(stderr
, "ttcp-r: packets %u data, %u start, %u end\n",
1480 data_pkt_cnt
, start_pkt_cnt
, end_pkt_cnt
);
1481 if (expected_pkt_cnt
!= 0) {
1482 int lost_cnt
= expected_pkt_cnt
- data_pkt_cnt
;
1484 fprintf(stderr
, "ttcp-r: %g%% (%u/%u) packet loss\n",
1485 100.0 * (double)lost_cnt
/(double)expected_pkt_cnt
,
1486 lost_cnt
, expected_pkt_cnt
);
1490 /*--------------------------------------------------------------------------*/
1491 /* calc_cpu_time(): Time difference, in usecs, of the combined user and
1492 * sys times of the given start and end usage info */
1494 calc_cpu_time(struct rusage
*r0
,
1499 struct timeval tdiff
, tend
, tstart
;
1501 /* total user delta time + total system delta time */
1502 tvadd( &tend
, &r1
->ru_utime
, &r1
->ru_stime
); /* user + sys time @ end */
1503 tvadd( &tstart
, &r0
->ru_utime
, &r0
->ru_stime
); /* user + sys time @ start*/
1504 tvsub( &tdiff
, &tend
, &tstart
);
1507 time
= ((double)tdiff
.tv_sec
)*1e6
+ (double)tdiff
.tv_usec
;
1509 /* debug mseconds */
1510 ms
= tdiff
.tv_sec
*(time_t)1000 + tdiff
.tv_usec
/(time_t)1000;
1511 if (ms
!= (time_t)(time
/1000.0)) {
1512 fprintf(stderr
, "ERROR: time calc mismatch of msec (%d) to usec (%f)\n",
1513 (int)ms
, time
/1000.0);
1519 /*--------------------------------------------------------------------------*/
1520 /* calc_real_time(): Time difference in usecs of the given times */
1522 calc_real_time(struct timeval
*t0
,
1527 struct timeval tdiff
;
1529 tvsub(&tdiff
, t1
,t0
);
1532 time
= ((double)tdiff
.tv_sec
)*1e6
+ (double)tdiff
.tv_usec
;
1534 /* debug mseconds */
1535 ms
= tdiff
.tv_sec
*(time_t)1000 + tdiff
.tv_usec
/(time_t)1000;
1536 if (ms
!= (time_t)(time
/1000.0)) {
1537 fprintf(stderr
, "ERROR: time calc mismatch of msec (%d) to usec (%f)\n",
1538 (int)ms
, time
/1000.0);
1543 /*--------------------------------------------------------------------------*/
1545 result_summary(void)
1547 char* label
= trans
? "ttcp-t" : "ttcp-r";
1548 double cput
= calc_cpu_time(&ru0
, &ru1
);
1549 double realt
= calc_real_time(&time0
, &time1
);
1551 double bytes_per_sec
;
1553 /* lower end boundary conditions */
1554 t_min
= 10.0; /* 10 usec */
1555 #if defined(__NTVIS__)
1556 t_min
= 1000.0; /* 1 msec */
1558 if (cput
<= t_min
) { /* value in usec */
1560 fprintf(stderr
,"%s: cpu time too short set at %.0f usec, NOT accurate result.\n",
1563 if (realt
<= t_min
) { /* value in usec */
1565 fprintf(stderr
,"%s: real time too short, set at %.0f usec, NOT accurate result.\n",
1569 bytes_per_sec
= (nbytes
/realt
)*1e6
;
1571 fprintf(stderr
,"%s: %.0f bytes in %.06f real seconds = %s/sec +++\n",
1572 label
, nbytes
, realt
/1e6
, outfmt(fmt
, bytes_per_sec
));
1575 fprintf(stderr
,"%s: %.0f bytes in %.06f cpu seconds = %s/cpu sec\n",
1576 label
, nbytes
,cput
/1e6
, outfmt(fmt
, (nbytes
/cput
)*1e6
));
1578 fprintf(stderr
,"%s: %ld I/O calls, %.3f msec(real)/call, %.3f msec(cpu)/call\n",
1580 (numCalls
>0)?(realt
/(double)numCalls
)/1000.0:0.0,
1581 (numCalls
>0)?(cput
/(double)numCalls
)/1000.0:0.0);
1583 fprintf(stderr
,"%s: ", label
);
1584 prusage(&ru0
, &ru1
, &time0
, &time1
);
1585 fprintf(stderr
,"\n");
1588 printf("%s: buffer address %p\n", label
, buf
);
1591 struct timeval tdiff
;
1593 tvsub(&tdiff
, &ru1
.ru_utime
, &ru0
.ru_utime
);
1594 fprintf(fplog
," %ld.%06ld", (long)tdiff
.tv_sec
, (long)tdiff
.tv_usec
);
1596 tvsub(&tdiff
, &ru1
.ru_stime
, &ru0
.ru_stime
);
1597 fprintf(fplog
," %ld.%06ld", (long)tdiff
.tv_sec
, (long)tdiff
.tv_usec
);
1598 /* Percent of cput usage */
1599 fprintf(fplog
," %.1f", 100.0 * (cput
/realt
));
1600 /* validity of real time mesurment */
1601 fprintf(fplog
, (realt
== t_min
)?" 0":" 1");
1602 /* bytes, seconds, MBytes/sec, IO calls */
1603 fprintf(fplog
," %10.0f %4.06f %4.3f %6ld",
1604 nbytes
, realt
/1e6
, bytes_per_sec
/(1024.0*1024.0), numCalls
);
1607 /*--------------------------------------------------------------------------*/
1609 sockets_err(char* s
)
1611 #if defined(__NTVIS__)
1612 int err
= WSAGetLastError();
1613 char* prefix
= trans
?"ttcp-t":"ttcp-r";
1614 fprintf(stderr
,"%s: %s\n", prefix
, s
);
1615 fprintf(stderr
,"%s: errno=%d\n", prefix
, err
);
1619 #endif /* __NTVIS__ */
1622 /*--------------------------------------------------------------------------*/
1626 char* prefix
= trans
?"ttcp-t":"ttcp-r";
1627 fprintf(stderr
,"%s: ", prefix
);
1629 fprintf(stderr
,"%s: errno=%d\n", prefix
, errno
);
1632 /*--------------------------------------------------------------------------*/
1636 fprintf(stderr
,"ttcp%s: %s\n", trans
?"-t":"-r", s
);
1638 /*--------------------------------------------------------------------------*/
1640 pattern( char *cp
, int cnt
)
1646 while( cnt1
-- > 0 ) {
1647 while( !isprint((c
&0x7F)) ) c
++;
1651 /*--------------------------------------------------------------------------*/
1653 outfmt(char format
, double b
)
1655 static char obuf
[50];
1656 double giga
= 1024.0 * 1024.0 * 1024.0;
1657 double mega
= 1024.0 * 1024.0;
1658 double kilo
= 1024.0;
1660 if (format
== 'A') {
1673 sprintf(obuf
, "%.3f GB", b
/ giga
);
1676 sprintf(obuf
, "%.3f MB", b
/ mega
);
1679 sprintf(obuf
, "%.3f KB", b
/ kilo
);
1682 sprintf(obuf
, "%4f B", b
);
1685 sprintf(obuf
, "%.3f Gbit", b
* 8.0 / giga
);
1688 sprintf(obuf
, "%.3f Mbit", b
* 8.0 / mega
);
1691 sprintf(obuf
, "%.3f Kbit", b
* 8.0 / kilo
);
1694 sprintf(obuf
, "%4f b", b
* 8.0);
1697 sprintf(obuf
, "default..........");
1701 /*--------------------------------------------------------------------------*/
1706 #if defined(__osf__)
1707 /* getrusage defined in the system lib */
1709 #if defined(__lynx__)
1710 /* getrusage defined in the system lib */
1712 #if defined(__sun__)
1713 /* getrusage defined in the system lib */
1717 getrusage(ignored
, ru
)
1719 register struct rusage
*ru
;
1723 #if defined(__NTVIS__)
1725 FILETIME CreateTime
, ExitTime
, KernelTime
, UserTime
;
1727 #if defined(UNDER_CE)
1728 phd
= GetCurrentThread();
1729 if( GetThreadTimes(phd
, &CreateTime
, &ExitTime
, &KernelTime
, &UserTime
)
1732 phd
= GetCurrentProcess();
1733 if( GetProcessTimes(phd
, &CreateTime
, &ExitTime
, &KernelTime
, &UserTime
)
1737 ru
->ru_stime
.tv_sec
= 0;
1738 ru
->ru_stime
.tv_usec
= 0;
1739 ru
->ru_utime
.tv_sec
= 0;
1740 ru
->ru_utime
.tv_usec
= 0;
1742 (void) FileTimeToSystemTime(&KernelTime
, &SysTime
);
1745 * "System sec=%d, msec=%d\n", SysTime.wSecond, SysTime.wMilliseconds);
1747 ru
->ru_stime
.tv_sec
= SysTime
.wSecond
;
1748 ru
->ru_stime
.tv_usec
= SysTime
.wMilliseconds
* 1000;
1749 (void) FileTimeToSystemTime(&UserTime
, &SysTime
);
1752 * " User sec=%d, msec=%d\n", SysTime.wSecond, SysTime.wMilliseconds);
1754 ru
->ru_utime
.tv_sec
= SysTime
.wSecond
;
1755 ru
->ru_utime
.tv_usec
= SysTime
.wMilliseconds
* 1000;
1757 #else /* __NTVIS__ */
1761 /* Assumption: HZ <= 2147 (LONG_MAX/1000000) */
1762 /* info : in lynxOS HZ is called TICKSPERSEC (<conf.h>) */
1764 ru
->ru_stime
.tv_sec
= buftime
.tms_stime
/ HZ
;
1765 ru
->ru_stime
.tv_usec
= ((buftime
.tms_stime
% HZ
) * 1000000) / HZ
;
1766 ru
->ru_utime
.tv_sec
= buftime
.tms_utime
/ HZ
;
1767 ru
->ru_utime
.tv_usec
= ((buftime
.tms_utime
% HZ
) * 1000000) / HZ
;
1768 #endif /* __NTVIS__ */
1771 } /* static getrusage */
1773 #endif /* __sun__ */
1774 #endif /* __lynx__ */
1775 #endif /* __osf__ */
1777 /*--------------------------------------------------------------------------*/
1779 #if defined(__hpux__) || defined(_AIX) || defined(__sun__)
1780 /* gettimeofday defined in the system lib */
1782 # if defined(__osf__) ||defined(__lynx__)
1783 /* gettimeofday defined in the system lib */
1787 gettimeofday(tp
, zp
)
1789 struct timezone
*zp
;
1791 #if defined(__NTVIS__)
1792 #if defined(UNDER_CE)
1793 SYSTEMTIME SystemTime
;
1795 GetLocalTime(&SystemTime
);
1796 tp
->tv_sec
= SystemTime
.wSecond
;
1797 tp
->tv_usec
= SystemTime
.wMilliseconds
* 1000;
1799 struct _timeb timeptr
;
1802 tp
->tv_sec
= timeptr
.time
;
1803 tp
->tv_usec
= timeptr
.millitm
* 1000;
1805 #else /* all cases */
1806 tp
->tv_sec
= time(0);
1808 #endif /* __NTVIS__ */
1810 } /* static gettimeofday */
1812 #endif /*__osf__ || __lynx__ */
1813 #endif /* __hpux__ || _AIX || __sun__ || __osf__*/
1815 /*--------------------------------------------------------------------------*/
1817 * P R E P _ T I M E R
1822 gettimeofday(&time0
, (struct timezone
*)0);
1823 getrusage(RUSAGE_SELF
, &ru0
);
1825 /*--------------------------------------------------------------------------*/
1827 * R E A D _ T I M E R
1833 getrusage(RUSAGE_SELF
, &ru1
);
1834 gettimeofday(&time1
, (struct timezone
*)0);
1836 /*--------------------------------------------------------------------------*/
1837 /* Print the process usage calculated from timers values extracted
1838 * before and after the transfer execution.
1841 prusage(struct rusage
*r0
, struct rusage
*r1
,
1842 struct timeval
*t0
, struct timeval
*t1
)
1844 struct timeval tdiff
;
1847 double cput
= calc_cpu_time(r0
, r1
);
1848 double realt
= calc_real_time(t0
, t1
);
1850 /* t == total user delta time + total system delta time */
1852 printf("timers : end startup\n");
1853 printf("user (sec) : %9ld %9ld\n",r1
->ru_utime
.tv_sec
,
1854 r0
->ru_utime
.tv_sec
);
1855 printf("user (usec): %9ld %9ld\n",r1
->ru_utime
.tv_usec
,
1856 r0
->ru_utime
.tv_usec
);
1857 printf("sys (sec) : %9ld %9ld\n",r1
->ru_stime
.tv_sec
,
1858 r0
->ru_stime
.tv_sec
);
1859 printf("sys (usec): %9ld %9ld\n",r1
->ru_stime
.tv_usec
,
1860 r0
->ru_stime
.tv_usec
);
1861 printf("time (sec) : %9ld %9ld\n",t1
->tv_sec
,t0
->tv_sec
);
1862 printf("time (usec): %9ld %9ld\n",t1
->tv_usec
,t0
->tv_usec
);
1864 /* for the AIX debug, most counters are outside a good range
1866 printf("ru_ixrss %20ld %20ld \n", r0->ru_ixrss ,r1->ru_ixrss );
1867 printf("ru_idrss %20ld %20ld \n", r0->ru_idrss ,r1->ru_idrss );
1868 printf("ru_isrss %20ld %20ld \n", r0->ru_isrss ,r1->ru_isrss );
1869 printf("ru_minflt %20ld %20ld \n", r0->ru_minflt ,r1->ru_minflt );
1870 printf("ru_majflt %20ld %20ld \n", r0->ru_majflt ,r1->ru_majflt );
1871 printf("ru_nswap %20ld %20ld \n", r0->ru_nswap ,r1->ru_nswap );
1872 printf("ru_inblock %20ld %20ld \n", r0->ru_inblock ,r1->ru_inblock );
1873 printf("ru_oublock %20ld %20ld \n", r0->ru_oublock ,r1->ru_oublock );
1874 printf("ru_msgsnd %20ld %20ld \n", r0->ru_msgsnd ,r1->ru_msgsnd );
1875 printf("ru_msgrcv %20ld %20ld \n", r0->ru_msgrcv ,r1->ru_msgrcv );
1876 printf("ru_nsignals %20ld %20ld \n", r0->ru_nsignals ,r1->ru_nsignals);
1877 printf("ru_nvcsw %20ld %20ld \n", r0->ru_nvcsw ,r1->ru_nvcsw );
1878 printf("ru_nivcsw %20ld %20ld \n", r0->ru_nivcsw ,r1->ru_nivcsw );
1881 /* cpu time in mseconds */
1882 t
= (int)(cput
/ 1000.0);
1884 /* ms == value of the internal clock at the end of the xfer */
1885 /* also called real time. */
1886 /* real time in mseconds */
1887 ms
= (int)(realt
/ 1000.0);
1889 /* The display is based on variables provided by the function getrusage
1890 Info located in : /usr/include/sys/resource.h
1895 /* with AIX cernsp most counters are wrong
1896 * cp = "%Uuser %Ssys %Ereal %P %Xi+%Dd %Mmaxrss %F+%Rpf %Ccsw\0";
1898 cp
= "%Uuser %Ssys %Ereal %P\0";
1901 #if defined(__osf__)
1902 cp
= "%Uuser %Ssys %Ereal %P %Xi+%Dd %Mmaxrss %F+%Rpf %Ccsw\0";
1904 #if defined(sgi) /* IRIX 3.3 will show 0 for %M,%F,%R,%C */
1905 cp
= "%Uuser %Ssys %Ereal %P %Mmaxrss %F+%Rpf %Ccsw\0";
1907 #if defined(__Lynx__)
1908 cp
= "%Uuser %Ssys %Ereal %P\0";
1910 cp
= "%Uuser %Ssys %Ereal %P\0"; /* all SYSV except those mentionned */
1911 #endif /*__lynx__ */
1916 #else /* BSD system */
1917 cp
= "%Uuser %Ssys %Ereal %P %Xi+%Dd %Mmaxrss %F+%Rpf %Ccsw\0";
1924 /* *outp++ = *cp; */
1928 tvsub(&tdiff
, &r1
->ru_utime
, &r0
->ru_utime
);
1929 fprintf(stderr
,"%ld.%06ld", (long)tdiff
.tv_sec
, (long)tdiff
.tv_usec
);
1933 tvsub(&tdiff
, &r1
->ru_stime
, &r0
->ru_stime
);
1934 fprintf(stderr
,"%ld.%06ld", (long)tdiff
.tv_sec
, (long)tdiff
.tv_usec
);
1942 fprintf(stderr
,"%.1f%%", (cput
*100.0 / (realt
? realt
: 1.0)) );
1945 #if !defined(SYSV) || defined(__osf__) || defined(_AIX)
1948 int i
= r1
->ru_nswap
- r0
->ru_nswap
;
1949 fprintf(stderr
,"%d", i
);
1954 fprintf(stderr
,"%ld", t
== 0 ? 0 : (r1
->ru_ixrss
-r0
->ru_ixrss
)/t
);
1958 fprintf(stderr
,"%ld", t
== 0 ? 0 :
1959 (r1
->ru_idrss
+r1
->ru_isrss
- (r0
->ru_idrss
+r0
->ru_isrss
))/t
);
1963 fprintf(stderr
,"%ld", t
== 0 ? 0 :
1964 ((r1
->ru_ixrss
+r1
->ru_isrss
+r1
->ru_idrss
) -
1965 (r0
->ru_ixrss
+r0
->ru_idrss
+r0
->ru_isrss
))/t
);
1969 fprintf(stderr
,"%ld", r1
->ru_maxrss
/2);
1973 fprintf(stderr
,"%ld", r1
->ru_majflt
-r0
->ru_majflt
);
1977 fprintf(stderr
,"%ld", r1
->ru_minflt
-r0
->ru_minflt
);
1981 fprintf(stderr
,"%ld", r1
->ru_inblock
-r0
->ru_inblock
);
1985 fprintf(stderr
,"%ld", r1
->ru_oublock
-r0
->ru_oublock
);
1989 fprintf(stderr
,"%ld+%ld",
1990 r1
->ru_nvcsw
-r0
->ru_nvcsw
, r1
->ru_nivcsw
-r0
->ru_nivcsw
);
1992 #endif /* !SYSV || __osf__ */
1999 /*--------------------------------------------------------------------------*/
2000 /* add 2 times structure and move usec bigger than 1000000 to sec */
2003 struct timeval
*tsum
, *t0
, *t1
;
2005 tsum
->tv_sec
= t0
->tv_sec
+ t1
->tv_sec
;
2006 tsum
->tv_usec
= t0
->tv_usec
+ t1
->tv_usec
;
2007 if (tsum
->tv_usec
> 1000000)
2008 tsum
->tv_sec
++, tsum
->tv_usec
-= 1000000;
2010 /*--------------------------------------------------------------------------*/
2011 /* substract 2 time structure (t1 > t0) */
2013 tvsub(tdiff
, t1
, t0
)
2014 struct timeval
*tdiff
, *t1
, *t0
;
2016 tdiff
->tv_sec
= t1
->tv_sec
- t0
->tv_sec
;
2017 tdiff
->tv_usec
= t1
->tv_usec
- t0
->tv_usec
;
2018 if (tdiff
->tv_usec
< 0)
2019 tdiff
->tv_sec
--, tdiff
->tv_usec
+= 1000000;
2022 /*--------------------------------------------------------------------------*/
2026 int i
= (int)l
/3600;
2030 fprintf(stderr
,"%d:", i
);
2032 fprintf(stderr
,"%.2d:%.2d", i
/60, i
%60);
2036 fprintf(stderr
,"%d:%.2d", i
/60, i
%60);
2039 /*--------------------------------------------------------------------------*/
2043 Nread(SOCKET s
, void* bufp
, int count
)
2045 #if defined(__lynx__) || defined(__svr4__) || defined(_AIX) || defined(__NTVIS__) || \
2046 defined(__FreeBSD__)
2047 struct sockaddr from
;
2049 struct sockaddr_in from
;
2051 int len
= sizeof(from
);
2055 fd_set readfds
, exceptfds
;
2056 struct timeval tv_timeout
;
2059 tv_timeout
.tv_sec
= timeout
/1000;
2060 tv_timeout
.tv_usec
= (timeout
%1000)*1000;
2063 FD_ZERO(&exceptfds
);
2064 FD_SET(s
, &readfds
);
2065 FD_SET(s
, &exceptfds
);
2067 n
= select( s
+1, &readfds
, NULL
, &exceptfds
, &tv_timeout
);
2068 if (n
== SOCKET_ERROR
) {
2069 sockets_err("select read");
2070 } else if (n
== 0) {
2077 cnt
= recvfrom( s
, bufp
, count
, 0, SOCKADDR_CAST
&from
, &len
);
2081 cnt
= mread( s
, bufp
, count
); /* fill bufp */
2083 #if defined(__NTVIS__)
2084 cnt
= recv( s
, bufp
, count
, 0 );
2086 cnt
= read( s
, bufp
, count
);
2087 #endif /* __NTVIS__ */
2090 if (touchdata
&& cnt
> 0) {
2091 register int c
= cnt
, sum
= 0;
2092 register char *b
= bufp
;
2093 while (c
--) sum
+= *b
++;
2097 /* rchrch printf (" numcall %d read buffer %d bytes \n",numCalls,cnt); */
2100 /*--------------------------------------------------------------------------*/
2104 Nwrite( int s
, void* bufp
, int count
)
2109 cnt
= sendto( s
, bufp
, count
, 0, SOCKADDR_CAST
&sinhim
,
2114 #if defined(__NTVIS__)
2115 if( cnt
<0 && WSAENOBUFS
== WSAGetLastError())
2117 if( cnt
<0 && errno
== ENOBUFS
)
2118 #endif /* __NTVIS__ */
2125 #if defined(__NTVIS__)
2126 cnt
= send( s
, bufp
, count
, 0 );
2131 struct timeval SendTimeout
;
2135 val
= fcntl(s
, F_GETFL
, 0);
2136 fcntl(s
,F_SETFL
, val
| O_NONBLOCK
);
2140 SendTimeout
.tv_sec
= timeout
/1000;
2141 SendTimeout
.tv_usec
= (timeout
%1000)*1000;
2142 ret
= select(s
+1, (fd_set
*) 0, &wset
, (fd_set
*) 0, &SendTimeout
);
2144 if (FD_ISSET(s
, &wset
) ) {
2145 cnt
= write( s
, bufp
, count
);
2146 fcntl(s
,F_SETFL
, val
);
2148 sockets_err("Socket Write");
2152 /* Select timed out */
2153 sockets_err("Select Write Timeout");
2157 cnt
= write( s
, bufp
, count
);
2160 cnt
= write( s
, bufp
, count
);
2163 #endif /* __NTVIS__ */
2167 /*--------------------------------------------------------------------------*/
2175 tv
.tv_usec
= (time_t)us
;
2177 #if defined(__hpux__)
2178 select(1, 0, 0, 0, &tv
);
2180 select(1, (fd_set
*)0, (fd_set
*)0, (fd_set
*)0, &tv
);
2183 /*--------------------------------------------------------------------------*/
2186 * This function performs the function of a read(II) but will
2187 * call read(II) multiple times in order to get the requested
2188 * number of characters. This can be necessary because
2189 * network connections don't deliver data with the same
2190 * grouping as it is written with. Written by Robert S. Miles, BRL.
2193 mread(int s
, char* bufp
, unsigned n
)
2195 register unsigned count
= 0;
2199 #if defined(__NTVIS__)
2200 nread
= recv(s
, bufp
, n
-count
, 0);
2202 nread
= read(s
, bufp
, n
-count
);
2203 #endif /* __NTVIS__ */
2206 perror("ttcp_mread");
2211 count
+= (unsigned)nread
;
2218 /*--------------------------------------------------------------------------*/
2222 if (hash
>= 1 && (numCalls
% hash
) == 0) {
2223 fprintf(stderr
, "#");
2231 fprintf(stderr
, "\n");
2234 /*--------------------------------------------------------------------------*/
2238 static long sysTicks
;
2239 #if defined(UNDER_CE)
2240 SYSTEMTIME SystemTime
;
2242 sprintf(logfile
,"%s_%s",logfile_head
,trans
?"t":"r");
2244 fprintf(stderr
,"open the log file >%s<\n",logfile
);
2245 if ((fplog
= fopen(logfile
,"r")) == NULL
) {
2246 if ((fplog
= fopen(logfile
,"a+")) == NULL
) {
2247 fprintf(stderr
,"Failure : creation of the file >%s< \n",logfile
);
2250 fprintf(fplog
," creation date : ");
2252 #if defined(UNDER_CE)
2253 GetLocalTime(&SystemTime
);
2254 sprintf(fplog
,"%02d-%02d-%02d %02d:%02d\n", SystemTime
.wDay
, month
[SystemTime
.wMonth
- 1],
2255 SystemTime
.wYear
, SystemTime
.wHour
, SystemTime
.wMinute
);
2258 tms
= localtime(&sysTicks
);
2259 fprintf(fplog
,"%02d-%02d-%02d %02d:%02d\n",
2260 tms
->tm_mday
, tms
->tm_mon
, tms
->tm_year
,tms
->tm_hour
, tms
->tm_min
);
2263 /* An other version will produce : Mon Aug 4 16:32:16 1997
2264 * long lDxcomsTicks; char *pDateTime;
2265 * time(&lDxcomsTicks);
2266 * pDateTime = ctime(&lDxcomsTicks); *(pDateTime+24) = '\0';
2267 * fprintf(fplog," ttcp called : %s", pDateTime);
2269 fprintf(fplog
,"format\n");
2270 fprintf(fplog
,",buflen, nbuf(byte), bufalign(byte), bufoffset(byte)");
2271 fprintf(fplog
,", port, sockbufsize(byte), UserTime(sec), SysTime(sec)\n");
2272 fprintf(fplog
,", CPUusage(%%), Validity, nbytes(byte), realt(sec)");
2273 fprintf(fplog
,", rate(MB/sec), I/O call, hours*3600+min*60+sec\n\n");
2274 /* day-month-year, hour:minute\n\n"); */
2276 } else { /* file already exists */
2278 if ((fplog
= fopen(logfile
,"a+")) == NULL
) {
2279 fprintf(stderr
,"Failure : access of the file >%s< \n",logfile
);
2284 /*--------------------------------------------------------------------------*/
2288 #if defined(UNDER_CE)
2289 SYSTEMTIME SystemTime
;
2291 GetLocalTime(&SystemTime
);
2292 fprintf(fplog
," %d\n", SystemTime
.wHour
* 3600 + SystemTime
.wMinute
* 60 + SystemTime
.wSecond
);
2294 static long sysTicks
;
2296 tms
= localtime(&sysTicks
);
2297 fprintf(fplog
," %d\n",((tms
->tm_hour
)*3600 + (tms
->tm_min
)*60 + tms
->tm_sec
));
2302 /*--------------------------------------------------------------------------*/
2303 /* routine emulating UNIX function under NT */
2304 #if defined(__NTVIS__)
2306 /*---------------------------------------------------------------------------*/
2311 return; // without printing
2313 fprintf(stderr
, "%s: %s: %c\n",
2314 (NULL
!= progname
) ? progname
: "getopt", pch
, optopt
);
2316 /*---------------------------------------------------------------------------*/
2318 getopt(int argc
, char **argv
, char *ostr
)
2320 static char *place
= EMSG
; /* option letter processing */
2321 register char *oli
; /* option letter list index */
2324 // update scanning pointer
2325 if (optind
>= argc
|| *(place
= argv
[optind
]) != '-' || !*++place
) {
2329 // place now points to the first char past the initial '-'
2330 if (place
[0] == '-') {
2332 // Was the word just a '--'?
2333 if (place
[1] == '\0')
2334 ++optind
; // yes, so consume the word
2335 // otherwise, the '--' was the start of a longer word,
2336 // so do not consume it.
2342 /* option letter okay? */
2343 if ((optopt
= (int)*place
++) == (int)':'
2344 || !(oli
= strchr(ostr
, optopt
))) {
2348 error("illegal option");
2351 if (*++oli
!= ':') {
2352 /* don't need argument */
2357 /* need an argument */
2359 optarg
= place
; /* no white space */
2360 } else if (argc
<= ++optind
) {
2363 error("option requires an argument");
2366 optarg
= argv
[optind
]; /* white space */
2371 return optopt
; // return option letter
2375 usleep(unsigned int microseconds
)
2377 Sleep(microseconds
/1000);
2379 #endif /* __NTVIS__ */
2380 /*--------------------------------------------------------------------------*/
2381 /*--------------------------------------------------------------------------*/
2386 " Details about the reply: \n"
2388 " ttcp-t: buflen=8192, nbuf=100, align=16384/0, port=5010\n"
2389 " ttcp-t: File-Descriptor 0x4 Opened\n"
2390 " # tcp sender -> <host> #\n"
2391 " ttcp-t: 819200 bytes in 1.152557 real seconds = 694.109 KB/sec +++\n"
2392 " ttcp-t: 100 I/O calls, 11.526 msec(real)/call, 0.213 msec(cpu)/call\n"
2393 " ttcp-t: 0.001914user 0.019388sys 0:01real 1% 9i+58d 190maxrss 1+2pf 177+180csw\n"
2394 " ttcp-t: buffer address 0x28000\n"
2395 " ttcp-t: File-Descriptor fd 0x4 Closed\n"
2397 "cpu seconds == (sec) elapse ru_utime + elapse ru_stime.\n"
2398 " ru_utime == The total amount of time running in user mode.\n"
2399 " ru_stime == The total amount of time spent in the system.\n"
2400 " executing on behalf of the process.\n"
2401 "real seconds == elapse time calculated by the system timer (date).\n"
2402 "I/O calls == I/O call to the driver.\n"
2403 "msec/call == average elapse time (Real seconds) between each I/O.\n"
2404 "calls/sec == invert of msec/call.\n"
2405 "user == (sec.msec) elaspe ru_utime.\n"
2406 "sys == (sec.msec) elapse ru_stime.\n"
2407 "real == (min:sec) CPU seconds.\n"
2408 "%% == Real seconds / CPU seconds.\n"
2409 "(ru_ixrss)i+(ru_idrss)d\n"
2410 " ru_ixrss == An integral value indicating the amount of memory \n"
2411 " used by the text segment that was also shared among\n"
2412 " other processes. This value is expressed in units of\n"
2413 " kilobytes * seconds-of-execution and is calculated \n"
2414 " by adding the number of shared memory pages in use \n"
2415 " each time the internal system clock ticks, and then\n"
2416 " averaging over one-second intervals.\n"
2417 " ru_idrss == An integral value of the amount of unshared memory \n"
2418 " in the data segment of a process (expressed in \n"
2419 " units of kilobytes * seconds-of-execution).\n";
2422 " (ru_maxrss/2)maxrss.\n"
2423 " ru_maxrss == The maximum size, in kilobytes, of the used\n"
2424 " resident set size. \n"
2425 " (ru_majflt)+(ru_minflt)pf : Page fault\n"
2426 " ru_majflt == The number of page faults serviced that required\n"
2428 " ru_minflt == The number of page faults serviced without any\n"
2429 " I/O activity. In this case, I/O activity is \n"
2430 " avoided by reclaiming a page frame from the list \n"
2431 " of pages awaiting reallocation. \n"
2432 "(ru_nvcsw)+(ru_nivcsw)csw : context switch\n"
2433 " ru_nvcsw == The number of times a context switch resulted \n"
2434 " because a process voluntarily gave up the \n"
2435 " processor before its time slice was completed. \n"
2436 " This usually occurs while the process waits \n"
2437 " for availability of a resource.\n"
2438 " ru_nivcsw == The number of times a context switch resulted \n"
2439 " because a higher priority process ran or because\n"
2440 " the current process exceeded its time slice.\n\n";
2443 "log file format :\n"
2444 " buflen, nbuf(byte), bufalign(byte), bufoffset(byte)\n"
2445 " port, sockbufsize(byte), UserTime(sec), SysTime(sec), CPUusage(%)\n"
2446 " nbytes(byte), realt(sec), rate(MB/sec), I/O call,\n"
2447 " hours*3600+min*60+sec\n\n";
2449 fprintf(stderr
,More_help
);
2450 fprintf(stderr
,More_help1
);
2451 fprintf(stderr
,More_help2
);
2453 /*---------------------------------------------------------------------------*/
2458 " Usage: ttcp -t [-options] host [ < in ] ttcp -r [-options > out]\n"
2459 "Example: ttcp -t -s -v -n100 host ttcp -r -s -v -n100\n"
2461 " -V prints version number and date of last modification\n"
2462 " -L create and append all results to a file named ttcp_log\n"
2464 " -l ## length of bufs read from or written to network (default 8192,\n"
2466 " -u use UDP instead of TCP\n"
2467 " -p ## port number to send to or listen at (default 5010)\n"
2468 #if defined(__linux__)
2469 " -P ## link-layer priority (default 0)\n"
2471 " -s (ttcp -t) : source a pattern to network\n"
2472 " (ttcp -r) : sink (discard) all data from network\n"
2473 " -A ## align the start of buffers to this modulus (default 16384)\n"
2474 " -O ## start buffers at this offset from the modulus (default 0)\n"
2475 " -v verbose: print more statistics\n"
2476 " -d set SO_DEBUG socket option\n"
2477 " -b ## set socket buffer size (if supported)\n"
2478 " -f X format for rate: b,B = bits, bytes k,K = kilo{bits,bytes};\n"
2479 " m,M = mega{bits,bytes}; g,G = giga{bits,bytes}\n"
2480 " -w ## set timeout value (in milliseconds) to exit if no receive data or tcp connect\n"
2481 "Options specific to (ttcp -t) :\n"
2482 " -n ## number of source bufs written to network (default 2048)\n"
2483 " -x use random data in tcp/udp frames (-I provides seed)\n"
2484 " -D don't buffer TCP writes (sets TCP_NODELAY socket option)\n"
2485 " -H print hash marks to indicate progress, one per buffer\n"
2486 " -# ## number of buffers to send between hash marks (implies -H)\n"
2487 " -I init/seed value for RNG when sending random size bufs (default 1)\n"
2488 " -N ## number of source bufs per burst, i.e between sleeps (default 1)\n"
2489 " -R ## send random size buffers with minimum size specified, max size\n"
2490 " is value of -l option\n"
2491 " -S ## millisecs between bursts (10ms resolution)\n"
2492 "Options specific to (ttcp -r) :\n"
2493 " -B for -s, only output full blocks as specified by -l (for TAR)\n"
2494 " -T \"touch\": access each byte as it's read\n"
2495 " -i report information on out of order sequence numbers\n"
2497 "Options for debug:\n"
2498 " --nostart do not send UDP start packets\n"
2499 " --noend do not send UDP end packets\n"
2500 " --nodata do not send UDP data packets\n"
2501 " --debug print extra debug outputs\n"
2505 fprintf(stderr
,Usage
);