2 * Copyright (c) 2008-2009 Robert N. M. Watson
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
14 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
15 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
16 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
17 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
18 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
19 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
20 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
21 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
22 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
23 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 #include <sys/types.h>
30 #include <sys/socket.h>
32 #include <netinet/in.h>
34 #include <arpa/inet.h>
46 #define BYTES_DEFAULT 10*1024*1024 /* Data per connection. */
47 #define MAXTCPS_DEFAULT 32 /* Number of TCPs at a time per proc. */
48 #define PROCS_DEFAULT 1 /* Processes used in run. */
49 #define TCPS_DEFAULT 1 /* Number of connections per process. */
50 #define BASEPORT_DEFAULT 10000
52 struct sockaddr_in remoteip; /* Base target address. */
53 struct sockaddr_in localipbase; /* Base local address, if -l. */
54 int cflag, lflag, mflag, pflag, sflag, tflag, Cflag, Mflag, Tflag;
62 fprintf(stderr, "client: tcpp"
76 fprintf(stderr, "server: tcpp"
88 main(int argc, char *argv[])
94 bzero(&localipbase, sizeof(localipbase));
95 localipbase.sin_len = sizeof(localipbase);
96 localipbase.sin_family = AF_INET;
97 localipbase.sin_addr.s_addr = htonl(INADDR_ANY); /* Default. */
98 localipbase.sin_port = htons(0); /* Default. */
100 bzero(&remoteip, sizeof(remoteip));
101 remoteip.sin_len = sizeof(remoteip);
102 remoteip.sin_family = AF_INET;
103 remoteip.sin_addr.s_addr = htonl(INADDR_LOOPBACK); /* Default. */
104 remoteip.sin_port = htons(0); /* Default. */
106 bflag = BYTES_DEFAULT;
107 mflag = MAXTCPS_DEFAULT;
108 pflag = PROCS_DEFAULT;
109 rflag = BASEPORT_DEFAULT;
110 tflag = TCPS_DEFAULT;
112 while ((ch = getopt(argc, argv, "b:c:l:m:p:r:st:CM:T")) != -1) {
115 ll = strtoll(optarg, &dummy, 10);
116 if (*dummy != '\0' || ll <= 0)
123 if (inet_aton(optarg, &remoteip.sin_addr) != 1)
124 err(-1, "inet_aton: %s", optarg);
129 if (inet_aton(optarg, &localipbase.sin_addr) != 1)
130 err(-1, "inet_aton: %s", optarg);
134 ll = strtoll(optarg, &dummy, 10);
135 if (*dummy != '\0' || ll <= 0)
141 ll = strtoll(optarg, &dummy, 10);
142 if (*dummy != '\0' || ll <= 0)
148 ll = strtol(optarg, &dummy, 10);
149 if (*dummy != '\0' || ll < 1 || ll > 65535)
159 ll = strtoll(optarg, &dummy, 10);
160 if (*dummy != '\0' || ll <= 0)
170 ll = strtoll(optarg, &dummy, 10);
171 if (*dummy != '\0' || ll <= 1)
185 /* Exactly one of client and server. */
186 if (cflag > 1 || sflag > 1)
188 if ((cflag && sflag) || (!cflag && !sflag))
191 /* If Mflag is specified, we must have the lflag for a local IP. */
192 if (Mflag > 1 && !lflag)
195 /* Several flags are valid only on the client, disallow if server. */
196 if (sflag && (Cflag || Mflag > 1))