Deleted Added
full compact
tcpstream.c (135132) tcpstream.c (136843)
1/*-
2 * Copyright (c) 2004 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

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
24 * SUCH DAMAGE.
25 *
1/*-
2 * Copyright (c) 2004 Robert N. M. Watson
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright

--- 9 unchanged lines hidden (view full) ---

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
24 * SUCH DAMAGE.
25 *
26 * $FreeBSD: head/tools/regression/netinet/tcpstream/tcpstream.c 135132 2004-09-13 03:17:22Z rwatson $
26 * $FreeBSD: head/tools/regression/netinet/tcpstream/tcpstream.c 136843 2004-10-23 22:11:35Z rwatson $
27 */
28
29/*
30 * tcpstream sets up a simple TCP client and server, and then streams a
31 * predictable pseudo-random byte sequence through it using variable block
32 * sizes. The intent is to to detect corruption of data in the TCP stream.
33 */
34
35#include <sys/types.h>
36#include <sys/errno.h>
37#include <sys/socket.h>
38
39#include <netinet/in.h>
40
41#include <arpa/inet.h>
42
27 */
28
29/*
30 * tcpstream sets up a simple TCP client and server, and then streams a
31 * predictable pseudo-random byte sequence through it using variable block
32 * sizes. The intent is to to detect corruption of data in the TCP stream.
33 */
34
35#include <sys/types.h>
36#include <sys/errno.h>
37#include <sys/socket.h>
38
39#include <netinet/in.h>
40
41#include <arpa/inet.h>
42
43#include <err.h>
44#include <errno.h>
43#include <stdio.h>
44#include <stdlib.h>
45#include <string.h>
46#include <unistd.h>
47
48#define MAX_LOOPS 10240
49#define MAX_LONGS 1024
50

--- 32 unchanged lines hidden (view full) ---

83{
84 long buffer[MAX_LONGS];
85 ssize_t len;
86 int i, j, sock;
87
88 srandom(seed);
89
90 sock = socket(PF_INET, SOCK_STREAM, 0);
45#include <stdio.h>
46#include <stdlib.h>
47#include <string.h>
48#include <unistd.h>
49
50#define MAX_LOOPS 10240
51#define MAX_LONGS 1024
52

--- 32 unchanged lines hidden (view full) ---

85{
86 long buffer[MAX_LONGS];
87 ssize_t len;
88 int i, j, sock;
89
90 srandom(seed);
91
92 sock = socket(PF_INET, SOCK_STREAM, 0);
91 if (sock == -1) {
92 perror("socket");
93 exit(-1);
94 }
93 if (sock == -1)
94 errx(-1, "socket: %s", strerror(errno));
95
95
96 if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1) {
97 perror("connect");
98 exit(-1);
99 }
96 if (connect(sock, (struct sockaddr *) &sin, sizeof(sin)) == -1)
97 errx(-1, "connect: %s", strerror(errno));
100
101 for (j = 0; j < MAX_LOOPS; j++) {
102 for (i = 0; i < MAX_LONGS; i++) {
103 fill_buffer(buffer, i);
104 len = send(sock, buffer, i * sizeof(long), 0);
105 if (len == -1) {
106 printf("%d bytes written of %d expected\n",
107 len, i * sizeof(long));

--- 15 unchanged lines hidden (view full) ---

123 struct sockaddr_in other_sin;
124 long buffer[MAX_LONGS];
125 socklen_t addrlen;
126 ssize_t len;
127
128 int input_byte_counter;
129
130 listen_sock = socket(PF_INET, SOCK_STREAM, 0);
98
99 for (j = 0; j < MAX_LOOPS; j++) {
100 for (i = 0; i < MAX_LONGS; i++) {
101 fill_buffer(buffer, i);
102 len = send(sock, buffer, i * sizeof(long), 0);
103 if (len == -1) {
104 printf("%d bytes written of %d expected\n",
105 len, i * sizeof(long));

--- 15 unchanged lines hidden (view full) ---

121 struct sockaddr_in other_sin;
122 long buffer[MAX_LONGS];
123 socklen_t addrlen;
124 ssize_t len;
125
126 int input_byte_counter;
127
128 listen_sock = socket(PF_INET, SOCK_STREAM, 0);
131 if (listen_sock == -1) {
132 perror("socket");
133 exit(-1);
134 }
129 if (listen_sock == -1)
130 errx(-1, "socket: %s", strerror(errno));
135
131
136 if (bind(listen_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
137 perror("bind");
138 exit(-1);
139 }
132 if (bind(listen_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
133 errx(-1, "bind: %s", strerror(errno));
140
134
141 if (listen(listen_sock, -1) == -1) {
142 perror("listen");
143 exit(-1);
144 }
135 if (listen(listen_sock, -1) == -1)
136 errx(-1, "listen: %s", strerror(errno));
145
146 while (1) {
147 bzero(&other_sin, sizeof(other_sin));
148 addrlen = sizeof(other_sin);
149
150 accept_sock = accept(listen_sock, (struct sockaddr *)
151 &other_sin, &addrlen);
152 if (accept_sock == -1) {

--- 43 unchanged lines hidden (view full) ---

196 if (strcmp(argv[1], "client") == 0) {
197 if (argc != 5)
198 usage();
199
200 bzero(&sin, sizeof(sin));
201 sin.sin_len = sizeof(sin);
202 sin.sin_family = AF_INET;
203
137
138 while (1) {
139 bzero(&other_sin, sizeof(other_sin));
140 addrlen = sizeof(other_sin);
141
142 accept_sock = accept(listen_sock, (struct sockaddr *)
143 &other_sin, &addrlen);
144 if (accept_sock == -1) {

--- 43 unchanged lines hidden (view full) ---

188 if (strcmp(argv[1], "client") == 0) {
189 if (argc != 5)
190 usage();
191
192 bzero(&sin, sizeof(sin));
193 sin.sin_len = sizeof(sin);
194 sin.sin_family = AF_INET;
195
204 if (inet_aton(argv[2], &sin.sin_addr) != 1) {
205 errno = EINVAL;
206 perror(argv[2]);
207 exit(-1);
208 }
196 if (inet_aton(argv[2], &sin.sin_addr) != 1)
197 errx(-1, "%s: %s", argv[2], strerror(EINVAL));
209
210 port = strtoul(argv[3], &dummy, 10);
211 if (port < 1 || port > 65535 || *dummy != '\0')
212 usage();
213 sin.sin_port = htons(port);
214
215 seed = strtoul(argv[4], &dummy, 10);
216 if (*dummy != '\0')

--- 28 unchanged lines hidden ---
198
199 port = strtoul(argv[3], &dummy, 10);
200 if (port < 1 || port > 65535 || *dummy != '\0')
201 usage();
202 sin.sin_port = htons(port);
203
204 seed = strtoul(argv[4], &dummy, 10);
205 if (*dummy != '\0')

--- 28 unchanged lines hidden ---