2 * Copyright (c) 2008 Peter Holm <pho@FreeBSD.org>
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
28 #include <sys/param.h>
29 #include <sys/socket.h>
30 #include <netinet/in.h>
42 #define NB (400 * 1024 * 1024)
52 struct sockaddr_in inetaddr, inetpeer;
56 if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
57 err(1, "socket(), %s:%d", __FILE__, __LINE__);
59 if (setsockopt(tcpsock,
60 SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
61 err(1, "setsockopt(), %s:%d", __FILE__, __LINE__);
63 inetaddr.sin_family = AF_INET;
64 inetaddr.sin_addr.s_addr = INADDR_ANY;
65 inetaddr.sin_port = htons(port);
66 inetaddr.sin_len = sizeof(inetaddr);
69 (struct sockaddr *)&inetaddr, sizeof (inetaddr)) < 0)
70 err(1, "bind(), %s:%d", __FILE__, __LINE__);
72 if (listen(tcpsock, 5) < 0)
73 err(1, "listen(), %s:%d", __FILE__, __LINE__);
75 if ((random_int(1,100) > 60) || (op->hog == 1)) {
76 usleep(random_int(1000000,1000000) * 60);
79 len = sizeof(inetpeer);
80 if ((msgsock = accept(tcpsock,
81 (struct sockaddr *)&inetpeer, &len)) < 0)
82 err(1, "accept(), %s:%d", __FILE__, __LINE__);
85 if ((buf = malloc(bufsize)) == NULL)
86 err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
87 while (done_testing == 0) {
88 if ((n = read(msgsock, buf, bufsize)) < 0)
89 err(1, "read(), %s:%d", __FILE__, __LINE__);
100 struct sockaddr_in inetaddr;
101 struct hostent *hostent;
105 for (i = 1; i < 5; i++) {
106 if ((tcpsock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
107 err(1, "socket(), %s:%d", __FILE__, __LINE__);
109 if (setsockopt(tcpsock,
110 SOL_SOCKET, SO_REUSEADDR, (char *)&on, sizeof(on)) < 0)
111 err(1, "setsockopt(), %s:%d", __FILE__, __LINE__);
113 hostent = gethostbyname ("localhost");
114 memcpy (&inetaddr.sin_addr.s_addr, hostent->h_addr,
115 sizeof (struct in_addr));
117 inetaddr.sin_family = AF_INET;
118 inetaddr.sin_addr.s_addr = INADDR_ANY;
119 inetaddr.sin_port = htons(port);
120 inetaddr.sin_len = sizeof(inetaddr);
122 r = connect(tcpsock, (struct sockaddr *) &inetaddr,
130 err(1, "connect(), %s:%d", __FILE__, __LINE__);
132 if ((buf = malloc(bufsize)) == NULL)
133 err(1, "malloc(%d), %s:%d", bufsize, __FILE__, __LINE__);
134 for (i = 0; i < bufsize / sizeof(int); i++)
138 for (i = 0; i < NB; i+= bufsize) {
139 if (write(tcpsock, buf, bufsize) < 0) {
142 err(1, "write(%d), %s:%d", tcpsock,
154 bufsize = 2 << random_int(1, 12);
168 if ((pid = fork()) == 0) {
172 } else if (pid > 0) {
176 err(1, "fork(), %s:%d", __FILE__, __LINE__);