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, hflag, lflag, mflag, pflag, sflag, tflag, Mflag, Pflag;
62 fprintf(stderr, "client: tcpp"
78 fprintf(stderr, "server: tcpp"
92 main(int argc, char *argv[])
98 bzero(&localipbase, sizeof(localipbase));
99 localipbase.sin_len = sizeof(localipbase);
100 localipbase.sin_family = AF_INET;
101 localipbase.sin_addr.s_addr = htonl(INADDR_ANY); /* Default. */
102 localipbase.sin_port = htons(0); /* Default. */
104 bzero(&remoteip, sizeof(remoteip));
105 remoteip.sin_len = sizeof(remoteip);
106 remoteip.sin_family = AF_INET;
107 remoteip.sin_addr.s_addr = htonl(INADDR_LOOPBACK); /* Default. */
108 remoteip.sin_port = htons(0); /* Default. */
110 bflag = BYTES_DEFAULT;
111 mflag = MAXTCPS_DEFAULT;
112 pflag = PROCS_DEFAULT;
113 rflag = BASEPORT_DEFAULT;
114 tflag = TCPS_DEFAULT;
116 while ((ch = getopt(argc, argv, "b:c:hl:m:p:r:st:CM:PT")) != -1) {
119 ll = strtoll(optarg, &dummy, 10);
120 if (*dummy != '\0' || ll <= 0)
127 if (inet_aton(optarg, &remoteip.sin_addr) != 1)
128 err(-1, "inet_aton: %s", optarg);
137 if (inet_aton(optarg, &localipbase.sin_addr) != 1)
138 err(-1, "inet_aton: %s", optarg);
142 ll = strtoll(optarg, &dummy, 10);
143 if (*dummy != '\0' || ll <= 0)
149 ll = strtoll(optarg, &dummy, 10);
150 if (*dummy != '\0' || ll <= 0)
156 ll = strtol(optarg, &dummy, 10);
157 if (*dummy != '\0' || ll < 1 || ll > 65535)
167 ll = strtoll(optarg, &dummy, 10);
168 if (*dummy != '\0' || ll <= 0)
174 ll = strtoll(optarg, &dummy, 10);
175 if (*dummy != '\0' || ll <= 1)
181 #if defined(CPU_SETSIZE) && 0
185 errx(EX_USAGE, "-P current unsupported");
193 /* Exactly one of client and server. */
194 if (cflag > 1 || sflag > 1)
196 if ((cflag && sflag) || (!cflag && !sflag))
199 /* If Mflag is specified, we must have the lflag for a local IP. */
200 if (Mflag > 1 && !lflag)
203 /* Several flags are valid only on the client, disallow if server. */
204 if (sflag && (hflag || Mflag > 1))