summaryrefslogtreecommitdiff
path: root/package/ttcp/src
diff options
context:
space:
mode:
authorWaldemar Brodkorb <wbx@openadk.org>2010-02-07 20:03:20 +0100
committerWaldemar Brodkorb <wbx@openadk.org>2010-02-07 20:03:20 +0100
commit6daa792eab1488d013fefc5eb7e4d01f40f38687 (patch)
tree6391cc46bb9fc8b859d99175ea317e5fa7b37959 /package/ttcp/src
parentadcaca72539b2ff4a5f4deee00d5f0251378ac9b (diff)
change defaults for CONFIG/BUILD/INSTALL styles
All packages need an update, so here is a very huge commit. Most of the 460 source packages use automatic style for configuration, building and installing. Make these styles default to "auto". If you have a package, which does not conform to this, just use manual style and add a do-$task make target. I added a new style named AUTOTOOL style, which is needed for some broken packages, which needs to be updated via autoconf or automake. I renamed CONFIGURE_STYLE to CONFIG_STYLE. Updates for some packages, which have newer upstream versions. Renaming of all package/*/extra directories. Use the directory src/ to provide overwrites of source files or to add the code, when no upstream package is available or used. src directory will be automatically used.
Diffstat (limited to 'package/ttcp/src')
-rw-r--r--package/ttcp/src/ttcp.c2374
1 files changed, 2374 insertions, 0 deletions
diff --git a/package/ttcp/src/ttcp.c b/package/ttcp/src/ttcp.c
new file mode 100644
index 000000000..3b1f07adf
--- /dev/null
+++ b/package/ttcp/src/ttcp.c
@@ -0,0 +1,2374 @@
+/*
+ * T T C P . C
+ *
+ * Test TCP connection. Makes a connection on port 5010
+ * and transfers fabricated buffers or data copied from stdin.
+ *
+ * Usable on 4.2, 4.3, and 4.1a systems by defining one of
+ * BSD42 BSD43 (BSD41a)
+ * Machines using System V with BSD sockets should define SYSV.
+ *
+ * Modified for operation under 4.2BSD, 18 Dec 84
+ * T.C. Slattery, USNA
+ * Minor improvements, Mike Muuss and Terry Slattery, 16-Oct-85.
+ * Modified in 1989 at Silicon Graphics, Inc.
+ * catch SIGPIPE to be able to print stats when receiver has died
+ * for tcp, don't look for sentinel during reads to allow small transfers
+ * increased default buffer size to 8K, nbuf to 2K to transfer 16MB
+ * moved default port to 5001, beyond IPPORT_USERRESERVED
+ * make sinkmode default because it is more popular,
+ * -s now means don't sink/source
+ * count number of read/write system calls to see effects of
+ * blocking from full socket buffers
+ * for tcp, -D option turns off buffered writes (sets TCP_NODELAY sockopt)
+ * buffer alignment options, -A and -O
+ * print stats in a format that's a bit easier to use with grep & awk
+ * for SYSV, mimic BSD routines to use most of the existing timing code
+ * Modified by Steve Miller of the University of Maryland, College Park
+ * -b sets the socket buffer size (SO_SNDBUF/SO_RCVBUF)
+ * Modified Sept. 1989 at Silicon Graphics, Inc.
+ * restored -s sense at request of tcs@brl
+ * Modified Oct. 1991 at Silicon Graphics, Inc.
+ * use getopt(3) for option processing, add -f and -T options.
+ * SGI IRIX 3.3 and 4.0 releases don't need #define SYSV.
+ *
+ * Modified --> Nov 1996 at CERN (Daniel DAVIDS)
+ * printout of the Socket-Buffer-Sizes
+ * configured for HP-UX 9000 OS
+ * configured for Windows NT OS
+ * Modified Dec 1996 at CERN (Jacques ROCHEZ)
+ * severe cleanup
+ * addaptation to the gcc compiler (ANSI)
+ * configured for Lynx OS
+ * automatic format for the rate display (G/M/K/)bytes/sec
+ * added log (L) and more help (h) options.
+ * Modified May 1997 at CERN (Jacques ROCHEZ)
+ * removed the mes() function following err() function.
+ * changed the default port to 5010
+ * Modified jul 1997 at CERN (Jacques ROCHEZ)
+ * adapted the timing calculation in microseconds
+ * addapted the code for Vsisual C++ under NT4.0
+ * Modified aug 1997 at CERN (Jacques ROCHEZ)
+ * initialise to 0 the variables nbytes, numcalls
+ * moved the buffer pre-load outside the measured timed area
+ * Distribution Status -
+ * Public Domain. Distribution Unlimited.
+ * Modified jun 1998 at Epigram
+ * - print hash marks to indicate prograss on transmitting side
+ * - sleep between bursts of buffers
+ * - set number of buffers/burst
+ * Modified jul 1998 at Epigram
+ * - send random size buffers
+ * Modified jan 1999 at Epigram (WES)
+ * - added start and end patterns to UDP start and end packets
+ * - added handling of missed start, end, or data packets for UDP tests
+ */
+#ifndef lint
+static char RCSid[] = "ttcp.c $- CERN Revision: 3.8 (dev level) -$";
+#endif
+
+static char VersDate[] = "Epigram 15-jul-98";
+
+/* system dependent setting
+ * ------------------------
+ * uname -a,gcc -v a.c are the tools used
+ *
+ * Platform/OS #define MACRO predefined
+ * ----------- ------- ---------------------------------------------------
+ * SunOS OS BSD43 __unix__ __sun__ __sparc__
+ * SUN Solaris SYSV __unix__ __sun__ __sparc__ __svr4__
+ * SGI-IRIX < 3.3 SYSV set as #define sgi
+ * HP-UX 9000 SYSV __unix__ __hpux__ __hp9k8__
+ * OSF/1 V3.2 SYSV __unix__ __osf__ __alpha__
+ * OSF/1 V4.0 SYSV __unix__ __osf__ __alpha__ _CFE
+ * LynxOS SYSV __unix__ __lynx__ __powerpc__
+ * Windows NT SYSV __WINNT__ __i386__ __M_COFF__
+ * AIX SYSV _AIX _AIX32 _POWER _IBMR2 _ARCH_PWR
+
+
+ * Micosoft Visual C++ compiler under WindowNT 4.0
+ * Windows NT _WINDOWS WIN32
+
+ * Unix BSD 41a BSD41a
+ * 42 BSD42
+ * 43 BSD43
+
+ * Machines using System V with BSD sockets should define SYSV.
+ *
+ * Compiler commands
+ * -----------------
+ * LynxOS : gcc -c ttcp.c -o ttcp.o | gcc -o ttcp -O ttcp.o -lnetinet -lc_p -lc
+ */
+
+/* -------------attempt to set an automatic UNIX OS family detection -------*/
+
+#if defined(__hp9k8__) || defined(__osf__) || defined(__srv4__)
+#define SYSV
+#endif
+#if defined(__lynx__)
+#define SYSV
+#endif
+/* for solaris (__srv4__) the parameters SYSV is already set */
+
+/* version A.09.01 'key words' differs from A.09.05 A */
+#if defined(__hpux)
+#define __hpux__
+#endif
+
+#if defined(__sun__)&&!defined(__srv4__)
+#define BSD43 /* changed by BSD42 if necessary */
+#endif
+
+#if defined(_WIN32) /* Window NT 4.0 compiled with VisualC++ 4 */
+#define __NTVIS__
+#define SYSV
+#endif
+
+#if defined(__FreeBSD__)
+#define BSD43
+#endif
+
+#if defined(__linux__)
+#define BSD43
+#endif
+/*--------------------------------------------------------------------------*/
+
+#if !defined(UNDER_CE)
+#include <signal.h>
+#include <ctype.h>
+#include <errno.h>
+#include <sys/types.h>
+#endif
+
+#if defined(SYSV)
+
+#if defined(__osf__)
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/time.h> /* struct timeval */
+#include <sys/resource.h> /* definition of struct rusage */
+
+#else /* else of __osf__ */
+#if defined(__NTVIS__)
+#include <winsock2.h>
+#include <windows.h> /* required for all Windows applications */
+#include <ws2tcpip.h>
+#include <memory.h>
+#include <time.h>
+#if !defined(UNDER_CE)
+#include <sys\timeb.h>
+#include <fcntl.h>
+#endif
+#include <stdlib.h>
+#include <io.h>
+struct rusage { struct timeval ru_utime, ru_stime; };
+#define RUSAGE_SELF 0
+#else /* else of __NTVIS__ */
+#if defined(__lynx__)
+#include <socket.h> /* located in /usr/include/..... */
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <time.h>
+#include <resource.h> /* definition of struct rusage */
+#include <sys/times.h>
+#define RUSAGE_SELF 0
+#include <conf.h> /* definition of TICKSPERSEC (HZ) */
+#include <sys/param.h>
+
+#else /* else of __Lynx__ */
+#if defined(__svr4__)
+#include <sys/socket.h>
+#include <sys/uio.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/time.h> /* struct timeval */
+#include <sys/resource.h> /* definition of struct rusage */
+#include <sys/times.h>
+#define RUSAGE_SELF 0
+#include <sys/param.h>
+
+#else /* else of __svr4__ all SYSV cases except those mentionned before */
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#include <sys/time.h> /* struct timeval */
+#include <sys/resource.h> /* definition of struct rusage */
+#include <sys/times.h>
+#define RUSAGE_SELF 0
+#include <sys/param.h>
+
+#endif /* __svr4__ */
+#endif /* __lynx__ */
+#endif /* __NTVIS__ */
+#endif /* __osf__ */
+
+#else /* else of SYSV it is a BSD OS */
+#include <stdlib.h>
+#include <string.h>
+#include <sys/socket.h>
+#include <netinet/in.h>
+#include <netinet/tcp.h>
+#include <arpa/inet.h>
+#include <netdb.h>
+#if defined(__linux__)
+#include <time.h> /* struct timeval */
+#else
+#include <sys/time.h> /* struct timeval */
+#endif
+#include <sys/resource.h> /* definition of struct rusage */
+#include <unistd.h> /* for usleep() - henry */
+#define SOCKET_ERROR -1
+
+#endif /* SYSV */
+
+#if defined(__NTVIS__)
+
+#if defined(_DEBUG) /* usual debug symbol for VC++ */
+#define DEBUG 1
+#endif
+
+void usleep(unsigned int microseconds);
+
+#define bcopy(a,b,n) memcpy((b), (a), (n))
+#define bzero(a,n) memset((a), 0, (n))
+
+#ifndef _GETOPT_
+#define _GETOPT_
+int getopt(int argc, char **argv, char *optstring);
+
+extern char *optarg; // returned arg to go with this option
+extern int optind; // index to next argv element to process
+extern int opterr; // should error messages be printed?
+extern int optopt; //
+
+#define BADCH ('?')
+#endif // _GETOPT
+
+/* get option letter from argument vector */
+int
+ opterr = 1, // should error messages be printed?
+ optind = 1, // index into parent argv vector
+ optopt; // character checked for validity
+char *optarg; // argument associated with option
+
+#define EMSG ""
+char *progname; // may also be defined elsewhere
+#endif /*__NTVIS__*/
+
+/* sockaddr_in == file server address structure
+ *
+ * Socket address, internet style. declared in : /netinet/in.h
+ * struct sockaddr_in {short sin_family;
+ * u_short sin_port;
+ * struct in_addr sin_addr;
+ * char sin_zero[8];
+ * };
+ *
+ * Structure used by kernel to store most addresses. declared in ./sys/socket.h
+ * struct sockaddr{u_short sa_family; address family
+ * char sa_data[14]; up to 14 bytes of direct address
+ * };
+ * PS : sin stand for "socket internet number"
+ */
+
+#ifndef __NTVIS__
+#define FAR
+#endif
+
+#if defined(__CONST_SOCKADDR_ARG)
+#define SOCKADDR_CAST (__CONST_SOCKADDR_ARG)
+#elif defined(__lynx__) || defined(__sun__) || defined(_AIX) || defined(__FreeBSD__) || defined(__NTVIS__)
+#define SOCKADDR_CAST (struct sockaddr FAR *)
+#else
+#define SOCKADDR_CAST
+#endif
+
+#if defined(__sun__)
+struct sockaddr_in sockaddr; /* done in ./X11/Xdmcp.h */
+#endif
+
+struct sockaddr_in sinme; /* is the socket struct. in the local host */
+struct sockaddr_in sinhim; /* is the socket struc. in the remote host */
+
+#if defined(__lynx__) || defined(__svr4__) || defined(_AIX)
+struct sockaddr frominet;
+#else
+struct sockaddr_in frominet;
+#endif /* __lynx__ */
+
+int domain, fromlen;
+
+#if !defined(__NTVIS__)
+#define SOCKET int
+#endif /* __NTVIS__ */
+SOCKET fd; /* fd of network socket */
+
+#if !defined(__lynx__)
+extern int errno;
+#endif
+
+#include <stdio.h>
+
+FILE *fplog = NULL; /* file pointer for the log file */
+char logfile[100]; /* file name for the log */
+static char logfile_head[] ="ttcp_log"; /* header name for the log */
+int buflen = 8 * 1024; /* length of buffer */
+char *buf; /* ptr to dynamic buffer */
+int nbuf = 2 * 1024; /* number of buffers to send in sinkmode */
+
+#define START_PKT_LEN 4
+#define START_PATTERN_LEN 4
+#define END_PKT_LEN 8
+#define END_PATTERN_LEN 4
+#define MIN_UDP_LEN 5
+
+char start_pattern[START_PATTERN_LEN] = {1, 2, 3, 4};
+char end_pattern[END_PATTERN_LEN] = {2, 2, 2, 2};
+
+int bufoffset = 0; /* align buffer to this */
+int bufalign = 16*1024; /* modulo this */
+
+int udp = 0; /* 0 = tcp, !0 = udp */
+int options = 0; /* socket options */
+int one = 1; /* for 4.3 BSD style setsockopt() */
+short port = 5010; /* TCP port number */
+char *host; /* ptr to name of host */
+int rndm = 0; /* 0="normal", !0=random data */
+int trans; /* 0=receive, !0=transmit mode */
+int timeout; /* read timeout in millisec */
+int debug = 0; /* 0=No-Debug, 1=Debug-Set-On */
+int sinkmode = 0; /* 0=normal I/O, !0=sink/source mode */
+int verbose = 0; /* 0=print basic info, 1=print cpu rate,
+ * proc resource usage. */
+int nodelay = 0; /* set TCP_NODELAY socket option */
+int pri = 0; /* link layer priority */
+int b_flag = 0; /* use mread() */
+int log_cnt = 0; /* append result to a log */
+int sockbufsize = 0; /* socket buffer size to use */
+char fmt = 'A'; /* output format:
+ * b = bits, B = bytes,
+ * k = kilobits, K = kilobytes,
+ * m = megabits, M = megabytes,
+ * g = gigabits, G = gigabytes,
+ * A = automatic Xbytes (default) */
+int touchdata = 0; /* access data after reading */
+int seq_info = 0; /* report out of order seq nums */
+
+int hash = 0; /* print hash marks for each buffer */
+int udpsleep = 0; /* sleep in between udp buffers */
+int burstn = 1; /* number of buffers per burst */
+int bufmin = -1; /* minimum buffer size to use when
+ sending random-size buffers */
+unsigned int seed = 1; /* seed for random number generator
+ used for random buffer lengths */
+int no_start = 0; /* skip the start frames for UDP */
+int no_data = 0; /* skip all data frames for UDP */
+int no_end = 0; /* skip the end frames for UDP */
+
+double nbytes; /* bytes on net */
+unsigned long numCalls; /* # of I/O system calls */
+
+struct hostent *addr;
+extern int optind;
+extern char *optarg;
+
+#if defined(UNDER_CE)
+static int errno;
+static char *weekday[] ={"Sun", "Mon","Tues", "Wed", "Thurs", "Fri", "Sat"};
+static char *month[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "July", "Aug", "Sep", "Oct", "Nov", "Dec"};
+#define perror printf
+#endif
+
+/*--------------------------------------------------------------------------*/
+static struct timeval time0; /* Time at which timing started */
+static struct timeval time1;
+static struct rusage ru0; /* Resource utilization at the start */
+static struct rusage ru1;
+static struct tm *tms; /* system time structure */
+
+
+/*-----------Prototype functions definitions -------------------------------*/
+/*--------------------------------------------------------------------------*/
+
+ /* ANSI input/output functions (stdio.h) */
+
+#if defined(__lynx__)
+int getopt(int, char**, char*);
+int gettimeofday(struct timeval *tp, struct timezone *tzp);
+
+#else
+#if defined(__svr4__)
+
+#else
+#if defined(_AIX)
+
+#else
+#if defined(__hpux__)
+#else
+#if defined(__NTVIS__)
+#else
+#if defined(BSD42) || defined(BSD43)
+#else
+
+int printf( char*, ...);
+int fprintf(FILE*,char*, ...);
+void perror(char*);
+int getopt(int, char**, char*);
+int gettimeofday(struct timeval *tp, struct timezone *tzp);
+#endif /* BSD42 || BSD43 */
+#endif /* __NTVIS__ */
+#endif /* __hpux__ */
+#endif /* _AIX */
+#endif /* __svr4__ */
+#endif /* __lynx__ */
+
+int main(int argc, char* argv[]);
+#if ( (!(defined(BSD42))) && (!(defined(BSD43))) && (!(defined(__NTVIS__))) )
+int read(int, char*, int);
+int write(int, char*, int);
+int close(int);
+#endif /* !(BSD42) && !(BSD43) */
+int fclose(FILE *stream);
+
+#if !defined(BSD43) && !defined(__NTVIS__)
+void bzero(char*,int);
+void bcopy(char*, char*, int);
+char strncpy(char *s1,char *s2,size_t n);
+int atoi(char*);
+int malloc(int);
+#endif
+
+
+ /* ANSI socket functions prototype /sys/socket.h */
+#if defined(__lynx__)
+int select(int, fd_set*, fd_set*, fd_set*, struct timeval*);
+
+#else
+#if defined(__svr4__) && !defined(sparc)
+
+/* informations in : /usr/include/sys/socket.h */
+int socket(int, int, int);
+int connect(int, struct sockaddr *, int);
+int bind(int, struct sockaddr *, int);
+int listen(int, int);
+int accept(int, struct sockaddr *, int *);
+int sendto(int, const char *, int, int, const struct sockaddr *, int);
+int recvfrom(int, char *, int, int, struct sockaddr *, int *);
+int getpeername(int, struct sockaddr *, int *);
+int getsockopt(int, int, int, char *, int *);
+int select(int, fd_set*, fd_set*, fd_set*, struct timeval*);
+
+#else
+#if defined(_AIX)
+int select(unsigned long, void *, void *, void *, struct timeval *);
+
+#else
+#if defined(__hpux__)
+int getrusage(int who,struct rusage *rusage);
+
+#else
+#if defined(__NTVIS__)
+
+#else
+#if defined(BSD42) || defined(BSD43)
+
+#else
+
+int socket(int, int, int);
+int connect(int s,struct sockaddr_in *name, int namelen);
+int bind(int s,struct sockaddr *name,int namelen);
+int listen(int, int);
+int accept(int, struct sockaddr_in *, int *);
+int sendto(int, char *, int, int, struct sockaddr_in *, int);
+int recvfrom(int, char *, int, int, struct sockaddr_in *, int *);
+int getpeername(int, struct sockaddr *, int *);
+int setsockopt(int, int, int, char *, int);
+
+int getsockopt(int, int, int, char*, int*);
+int select(int, fd_set*, fd_set*, fd_set*, struct timeval*);
+
+#endif /* BSD42 || BSD43 */
+#endif /* __hpux__ */
+#endif /* _AIX */
+#endif /* __svr4__ */
+#endif /* __lynx__ */
+#endif /* __NTVIS__ */
+
+/* ttcp prototype functions */
+void udp_rcv_test(void);
+double calc_cpu_time(struct rusage *r0, struct rusage *r1);
+double calc_real_time(struct timeval *t0, struct timeval *t1);
+int getrusage(int who,struct rusage *rusage);
+void sockets_err(char*);
+void err(char *);
+void mes(char *);
+void pattern(char *, int);
+int Nread(SOCKET, void *, int);
+int Nwrite(int, void *, int);
+void delay(int);
+int mread(int, char *,unsigned);
+char *outfmt(char format, double b);
+void prep_timer(void);
+void read_timer(void);
+void result_summary(void);
+void prusage(struct rusage*, struct rusage*,
+ struct timeval*, struct timeval*);
+void tvadd(struct timeval *tsum, struct timeval *t0,struct timeval *t1);
+void tvsub(struct timeval *tdiff, struct timeval *t1, struct timeval *t0);
+void psecs(int);
+void open_log(void);
+void close_log(void);
+void do_Usage(void);
+void do_help(void);
+
+/*--------------------------------------------------------------------------*/
+#if !defined(__NTVIS__)
+void
+sigpipe()
+{;
+}
+#endif
+/*--------------------------------------------------------------------------*/
+/*--------------------------------------------------------------------------*/
+int
+main(int argc, char **argv)
+{
+ unsigned long addr_tmp;
+ int c,k;
+ int sockbufsndsize,sockbufrcvsize;
+ int sockbuflen;
+ struct sockaddr_in peer;
+ int peerlen = sizeof(peer);
+
+#if defined(__NTVIS__)
+ extern char *optarg;
+ WSADATA WSAData;
+ WSAStartup(MAKEWORD(1,1), &WSAData);
+#endif /* __NTVIS__ */
+
+ if (argc < 2) { do_Usage(); exit(1); }
+
+ while (1) {
+ while ((c=getopt(argc, argv, "hidrstuvxHVBDTLb:f:l:n:p:A:O:S:N:P:R:I:w:")) != -1) {
+ switch (c) {
+ case 'w':
+ timeout = atoi(optarg);
+ break;
+ case 'I':
+ seed = atoi(optarg);
+ break;
+ case 'N':
+ burstn = atoi(optarg);
+ break;
+ case 'P':
+#if defined(__linux__)
+ pri = atoi(optarg);
+ break;
+#else
+ fprintf(stderr, "ttcp: -P option not supported on this OS\n");
+ exit(1);
+#endif
+ case 'R':
+ bufmin = atoi(optarg);
+ break;
+ case 'S':
+ udpsleep = atoi(optarg);
+ if (udpsleep < 0) udpsleep = 0;
+ /* convert msec arg to usec for usleep, minimum 10ms */
+ udpsleep = udpsleep * 1000;
+ break;
+ case 'H':
+ hash = 1;
+ break;
+ case 'V':
+ fprintf(stdout,"%s %s\n" , RCSid , VersDate );
+ exit(0);
+ case 'B':
+ b_flag = 1;
+ break;
+ case 'L':
+ log_cnt = 1;
+ break;
+ case 'h':
+ do_help();
+ exit(1);
+ break;
+ case 't':
+ trans = 1;
+ break;
+ case 'r':
+ trans = 0;
+ break;
+ case 'x':
+ rndm = 1;
+ break;
+ case 'd':
+ options |= SO_DEBUG;
+ break;
+ case 'D':
+#ifdef TCP_NODELAY
+ nodelay = 1;
+#else
+ fprintf(stderr,
+ "ttcp: -D option ignored: TCP_NODELAY socket option not supported\n");
+#endif
+ break;
+ case 'n':
+ nbuf = atoi(optarg);
+ break;
+ case 'l':
+ buflen = atoi(optarg);
+ break;
+ case 's':
+ sinkmode = !sinkmode;
+ break;
+ case 'p':
+ port = atoi(optarg);
+ break;
+ case 'u':
+ udp = 1;
+ break;
+ case 'v':
+ verbose = 1;
+ break;
+ case 'A':
+ bufalign = atoi(optarg);
+ break;
+ case 'O':
+ bufoffset = atoi(optarg);
+ break;
+ case 'b':
+#if defined(SO_SNDBUF) || defined(SO_RCVBUF)
+ sockbufsize = atoi(optarg);
+#else
+ fprintf(stderr,
+"ttcp: -b option ignored: SO_SNDBUF/SO_RCVBUF socket options not supported\n");
+#endif
+ break;
+ case 'f':
+ fmt = *optarg;
+ break;
+ case 'T':
+ touchdata = 1;
+ break;
+ case 'i':
+ seq_info = 1;
+ break;
+
+ default:
+ {do_Usage(); exit(1);}
+ }/*switch */
+ }/* while getopt() */
+
+ argc -= optind;
+ argv += optind;
+ optind = 0;
+
+ /* check for '--' args */
+ if (argc == 0) {
+ /* no more args */
+ break; /* while (1) */
+#if defined(DEBUG)
+ } else if (!strcmp(argv[0], "--nostart")) {
+ no_start = 1;
+ argc--; argv++;
+ } else if (!strcmp(argv[0], "--nodata")) {
+ no_data = 1;
+ argc--; argv++;
+ } else if (!strcmp(argv[0], "--noend")) {
+ no_end = 1;
+ argc--; argv++;
+ } else if (!strcmp(argv[0], "--debug")) {
+ debug = 1;
+ argc--; argv++;
+#endif /* DEBUG */
+ } else if (!strncmp(argv[0], "--", 2)) {
+ fprintf(stderr, "ttcp: illegal option: %s\n", argv[0]);
+ do_Usage(); exit(1);
+ } else {
+ /* the arg was not a '--' arg */
+ break; /* while (1) */
+ }
+ } /* while (1) */
+
+
+ /* ----------------------- main part ----------------------- */
+
+#if defined(__NTVIS__) && !defined(UNDER_CE)
+ /* Set "stdin" to have binary mode: */
+ if (_setmode(_fileno(stdin), _O_BINARY) == -1)
+ perror("%s: Error setting stdin to binary mode");
+ /* Set "stdout" to have binary mode: */
+ if (_setmode(_fileno(stdout), _O_BINARY) == -1)
+ perror("%s: Error setting stdout to binary mode");
+#endif /* __NTVIS__ */
+
+if (log_cnt) open_log();
+
+/* input error checking */
+if (burstn > nbuf) {
+ fprintf(stderr, "ttcp: buffers per burst must be less than or equal to "
+ "total number of buffers\n");
+ exit(1);
+}
+if (bufmin < -1) {
+ fprintf(stderr, "ttcp: minimum buffer size specified with -R option must "
+ "be non-negative\n");
+ exit(1);
+}
+if (buflen > 65535) {
+ fprintf(stderr, "ttcp: maximum buffer size specified with -l option must "
+ "be <= 65536\n");
+ exit(1);
+}
+if (bufmin > buflen) {
+ fprintf(stderr, "ttcp: minimum buffer size specified with -R option must "
+ "be less than or equal to (maximum) buffer size specified with -l\n");
+ exit(1);
+}
+
+/* buffer allocation */
+
+ if (udp && buflen < MIN_UDP_LEN)
+ buflen = MIN_UDP_LEN; /* send more than the sentinel size */
+
+ if ( (buf = (char *)malloc(buflen+bufalign)) == (char *)NULL)
+ err("malloc");
+ if (bufalign != 0)
+ buf +=(bufalign - ((int)buf % bufalign) + bufoffset) % bufalign;
+
+ fprintf(stderr,"ttcp%s: buflen=%d, nbuf=%d, align=%d/%d, port=%d\n",
+ trans?"-t":"-r",buflen, nbuf, bufalign, bufoffset, port);
+ if (log_cnt)fprintf(fplog," %6d %6d %6d %6d %4d",
+ buflen, nbuf, bufalign, bufoffset, port);
+
+ /* preload the buffer for the transmit condition */
+ pattern( buf, buflen );
+
+ /* seed the random number generator */
+ if ((bufmin != -1) || (rndm != 0)) {
+#if defined(__NTVIS__)
+ srand(seed);
+#else /* ! __NTVIS__ */
+ srandom(seed);
+#endif /* __NTVIS__ */
+ }
+
+ if(trans)
+ {/* xmitr */
+ if (argc == 0) {
+ fprintf(stderr, "ttcp: missing destination host arg\n");
+ do_Usage(); exit(1);
+ }
+
+ memset((char *)&sinhim, 0, sizeof(sinhim));
+ host = argv[0];
+ if (atoi(host) > 0 )
+ {/* Numeric */
+ sinhim.sin_family = AF_INET;
+ sinhim.sin_addr.s_addr = inet_addr(host);
+ }
+ else
+ {if ((addr=gethostbyname(host)) == NULL) sockets_err("bad hostname");
+ sinhim.sin_family = addr->h_addrtype;
+ memcpy((char*)&addr_tmp, addr->h_addr, addr->h_length);
+ sinhim.sin_addr.s_addr = addr_tmp;
+ }
+ sinhim.sin_port = htons(port);
+ sinme.sin_port = 0; /* free choice */
+ }
+ else
+ {/* rcvr */
+ sinme.sin_port = htons(port);
+ }
+#if defined(__NTVIS__)
+ sinme.sin_family = AF_INET;
+#endif
+
+ fd = socket(AF_INET, udp?SOCK_DGRAM:SOCK_STREAM, 0);
+
+#if defined(__NTVIS__)
+ if (fd == INVALID_SOCKET) sockets_err("socket");
+#else
+ if (fd < 0) sockets_err("socket");
+#endif
+
+ if (verbose) {
+ char *label = trans?"ttcp-t":"ttcp-r";
+#if defined(UNDER_CE)
+ SYSTEMTIME SystemTime;
+ char time_str[30];
+
+ GetLocalTime(&SystemTime);
+ sprintf(time_str, "%s %s %d %02d:%02d:%02d %d\n", weekday[SystemTime.wDayOfWeek], month[SystemTime.wMonth - 1],
+ SystemTime.wDay, SystemTime.wHour, SystemTime.wMinute, SystemTime.wSecond, SystemTime.wYear);
+#else
+ time_t now;
+ char *time_str;
+
+ time(&now);
+ time_str = ctime(&now);
+#endif
+ fprintf(stdout,"%s: start time %s", label, time_str);
+ fprintf(stdout,"%s: File-Descriptor 0x%x Opened\n", label, fd );
+ }
+
+#if defined(__NTVIS__)
+ if (bind(fd, (struct sockaddr FAR *)&sinme, sizeof(sinme)) == SOCKET_ERROR)
+ sockets_err("bind");
+#else
+ if (bind(fd, SOCKADDR_CAST &sinme, sizeof(sinme)) < 0)
+ sockets_err("bind");
+#endif /* __NTVIS__ */
+
+
+#if defined(SO_SNDBUF) || defined(SO_RCVBUF)
+ if (sockbufsize)
+ {
+#if defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
+ if (trans)
+ {if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsize,
+ sizeof sockbufsize) < 0)
+ sockets_err("setsockopt: sndbuf");
+ }
+ else
+ {if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufsize,
+ sizeof sockbufsize) < 0)
+ sockets_err("setsockopt: rcvbuf");
+ }
+
+#else
+ if (trans)
+
+ {if (setsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sockbufsize,
+ sizeof sockbufsize) < 0)
+ sockets_err("setsockopt: sndbuf");
+ }
+ else
+ {if (setsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sockbufsize,
+ sizeof sockbufsize) < 0)
+ sockets_err("setsockopt: rcvbuf");
+ }
+#endif /* __lynx__ __sun__ __NTVIS__ */
+ }
+ else
+ {/*
+ ** Added by Daniel Davids to Know Socket-Buffer-Sizes
+ */
+ sockbuflen = sizeof sockbufsndsize;
+#if defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
+ getsockopt(fd, SOL_SOCKET, SO_SNDBUF, (char *)&sockbufsndsize,
+ &sockbuflen);
+ sockbuflen = sizeof sockbufrcvsize;
+ getsockopt(fd, SOL_SOCKET, SO_RCVBUF, (char *)&sockbufrcvsize,
+ &sockbuflen);
+#else
+ getsockopt(fd, SOL_SOCKET, SO_SNDBUF, &sockbufsndsize, &sockbuflen);
+ sockbuflen = sizeof sockbufrcvsize;
+ getsockopt(fd, SOL_SOCKET, SO_RCVBUF, &sockbufrcvsize, &sockbuflen);
+#endif /* __lynx__ __sun__ __NTVIS__ */
+ sockbufsize = ( sockbufsndsize + sockbufrcvsize ) / 2;
+
+ if ( sockbufsndsize != sockbufrcvsize )
+ {fprintf(stderr, "sockbufsndsize=%d, ", sockbufsndsize );
+ fprintf(stderr, "sockbufrcvsize=%d, ", sockbufrcvsize );
+ }
+ }
+#endif /* defined(SO_SNDBUF) || defined(SO_RCVBUF) */
+
+ if (sockbufsize) fprintf(stderr, "sockbufsize=%d, \n", sockbufsize);
+
+ if (log_cnt)
+ {if (sockbufsize)fprintf(fplog," %6d",sockbufsize);
+ else fprintf(fplog," 0");
+ }
+
+#if defined(__linux__)
+ if (setsockopt(fd, SOL_SOCKET, SO_PRIORITY, (char *)&pri, sizeof pri) < 0)
+ sockets_err("setsockopt: priority");
+#endif
+
+
+ if (trans) fprintf(stderr, "# %s sender -> %s #\n", udp?"udp":"tcp", host);
+ else fprintf(stderr, "# %s receiver #\n", udp?"udp":"tcp");
+
+ if (!udp)
+ {
+#if !defined(__NTVIS__)
+ signal(SIGPIPE, sigpipe);
+#endif /* !__NTVIS__ */
+
+ if (trans)
+ {/* We are the client if transmitting */
+ if (options)
+ {
+#if defined(BSD42)
+ if( setsockopt(fd, SOL_SOCKET, options, 0, 0) < 0)
+#else /* BSD43 */
+ if( setsockopt(fd, SOL_SOCKET, options, (char *)&one, sizeof(one)) < 0)
+#endif /* BDS42 */
+ sockets_err("setsockopt");
+ }
+#ifdef TCP_NODELAY
+ if (nodelay)
+ {struct protoent *p;
+ p = getprotobyname("tcp");
+#if defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
+ if( p && setsockopt(fd, p->p_proto, TCP_NODELAY,
+ (char *) &one, sizeof(one)) < 0)
+#else
+ if( p && setsockopt(fd, p->p_proto, TCP_NODELAY,
+ &one, sizeof(one)) < 0)
+#endif /* __lynx__ __sun__ __NTVIS__ */
+ sockets_err("setsockopt: nodelay");
+ }
+#endif /* TCP_NODELAY */
+ if (connect(fd, SOCKADDR_CAST &sinhim, sizeof(sinhim) ) < 0)
+ sockets_err("connect");
+ }/* if (trans) */
+ else
+ {/* otherwise, we are the server and should listen for connections */
+
+errno = 0;
+
+#if defined(sgi) || ( defined(__osf__) && !defined(_CFE) )
+ if( listen(fd,1) <0 )
+#else
+ if( listen(fd,0) <0 ) /* allow a queue of 0 */
+#endif
+ sockets_err("listen");
+
+ if(options) {
+ int err;
+#if defined(BSD42)
+ err = setsockopt(fd, SOL_SOCKET, options, 0, 0);
+#elif defined(__lynx__) || defined(__sun__) || defined(__NTVIS__)
+ err = setsockopt(fd, SOL_SOCKET, options, (char *) &one, sizeof(one));
+#else
+ err = setsockopt(fd, SOL_SOCKET, options, &one, sizeof(one));
+#endif /* BSD42 */
+ if (err < 0)
+ sockets_err("setsockopt");
+ }
+ fromlen = sizeof(frominet);
+ domain = AF_INET;
+ if (timeout > 0) {
+ fd_set readfds, exceptfds;
+ struct timeval tv_timeout;
+ int n;
+
+ tv_timeout.tv_sec = timeout/1000;
+ tv_timeout.tv_usec = (timeout%1000)*1000;
+
+ FD_ZERO(&readfds);
+ FD_ZERO(&exceptfds);
+ FD_SET(fd, &readfds);
+ FD_SET(fd, &exceptfds);
+
+ n = select( fd+1, &readfds, NULL, &exceptfds, &tv_timeout );
+ if (n == 0 || n == SOCKET_ERROR) {
+ sockets_err("select listen");
+ return 0;
+ }
+ }
+ if((fd=accept(fd, SOCKADDR_CAST &frominet, &fromlen) ) < 0)
+ sockets_err("accept");
+
+ if (getpeername(fd, SOCKADDR_CAST &peer, &peerlen) < 0)
+ sockets_err("getpeername");
+
+ fprintf(stderr,"ttcp-r: accept from %s\n",inet_ntoa(peer.sin_addr));
+
+ } /* otherwise we are ... */
+ }
+
+ prep_timer();
+ errno = 0;
+ nbytes = 0.0;
+ numCalls = 0;
+
+ {
+ register int cnt,multi;
+ char *pb;
+ int nb = 0;
+ unsigned long rbuflen = 0;
+ multi = nbuf;
+
+ if (trans) {
+#if !defined(BSD43)
+ if(udp) {
+ int err;
+ int nochecksum_opt = 0;
+ err = setsockopt(fd, IPPROTO_UDP, UDP_NOCHECKSUM,
+ (char *)&nochecksum_opt, sizeof(nochecksum_opt));
+ if (err < 0)
+ sockets_err("setsockopt");
+ }
+#endif
+
+ if(udp && !no_start) {
+ int start_count = 2;
+ char start_pkt[START_PKT_LEN];
+ memset(start_pkt, 0, START_PKT_LEN);
+ memcpy(start_pkt, start_pattern, START_PATTERN_LEN);
+
+ while (start_count-- > 0) {
+ (void)Nwrite( fd, start_pkt, START_PKT_LEN ); /* rcvr start */
+ if (udpsleep) {
+ usleep(udpsleep);
+ /* clear errno (see man page for errno(3), definition of
+ EINTR. usleep() uses SIGCONT? ) */
+ if (errno == EINTR) errno = 0;
+ } /* udpsleep */
+ }
+ }
+
+ /* initial seqence num for UDP */
+ if (udp) buf[0] = 0;
+ k = burstn;
+
+ if (sinkmode) {
+ while (multi-- > 0 && !no_data) {
+
+ if (bufmin == -1) {
+ rbuflen = buflen;
+ } else {
+ /* set rbuflen to a random value evenly distributed in
+ [bufmin, buflen]. As long as buflen is < 2^16, we can
+ fit the calculation in 32 bits */
+#if defined(__NTVIS__)
+ rbuflen = (( (unsigned long)rand() *
+ ((unsigned long)(buflen-bufmin+1)) ) >> 15) + bufmin;