Deleted Added
full compact
tcpconnect.c (136613) tcpconnect.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/tcpconnect/tcpconnect.c 136613 2004-10-17 11:07:03Z ru $
26 * $FreeBSD: head/tools/regression/netinet/tcpconnect/tcpconnect.c 136843 2004-10-23 22:11:35Z rwatson $
27 */
28
29#include <sys/types.h>
30#include <sys/socket.h>
31
32#include <netinet/in.h>
33
34#include <arpa/inet.h>
35
27 */
28
29#include <sys/types.h>
30#include <sys/socket.h>
31
32#include <netinet/in.h>
33
34#include <arpa/inet.h>
35
36#include <errno.h>
36#include <stdio.h>
37#include <stdlib.h>
38#include <string.h>
39#include <unistd.h>
40
41static void
42usage(void)
43{

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

64 sin.sin_addr.s_addr = htonl(INADDR_ANY);
65
66 port = strtoul(argv[0], &dummy, 10);
67 if (port < 1 || port > 65535 || *dummy != '\0')
68 usage();
69 sin.sin_port = htons(port);
70
71 listen_sock = socket(PF_INET, SOCK_STREAM, 0);
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <unistd.h>
41
42static void
43usage(void)
44{

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

65 sin.sin_addr.s_addr = htonl(INADDR_ANY);
66
67 port = strtoul(argv[0], &dummy, 10);
68 if (port < 1 || port > 65535 || *dummy != '\0')
69 usage();
70 sin.sin_port = htons(port);
71
72 listen_sock = socket(PF_INET, SOCK_STREAM, 0);
72 if (listen_sock == -1) {
73 perror("socket");
74 exit(-1);
75 }
73 if (listen_sock == -1)
74 errx(-1, "socket: %s", strerror(errno));
76
75
77 if (bind(listen_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
78 perror("bind");
79 exit(-1);
80 }
76 if (bind(listen_sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
77 errx(-1, "bind: %s", strerror(errno));
81
78
82 if (listen(listen_sock, -1) == -1) {
83 perror("listen");
84 exit(1);
85 }
79 if (listen(listen_sock, -1) == -1)
80 errx(-1, "listen: %s", strerror(errno));
86
87 while (1) {
88 accept_sock = accept(listen_sock, NULL, NULL);
89 close(accept_sock);
90 }
91}
92
93static void

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

99 int sock;
100
101 if (argc != 3)
102 usage();
103
104 bzero(&sin, sizeof(sin));
105 sin.sin_len = sizeof(sin);
106 sin.sin_family = AF_INET;
81
82 while (1) {
83 accept_sock = accept(listen_sock, NULL, NULL);
84 close(accept_sock);
85 }
86}
87
88static void

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

94 int sock;
95
96 if (argc != 3)
97 usage();
98
99 bzero(&sin, sizeof(sin));
100 sin.sin_len = sizeof(sin);
101 sin.sin_family = AF_INET;
107 if (inet_aton(argv[0], &sin.sin_addr) == 0) {
108 perror(argv[0]);
109 exit(-1);
110 }
102 if (inet_aton(argv[0], &sin.sin_addr) == 0)
103 errx(-1, "listen: %x", strerror(errno));
111
112 port = strtoul(argv[1], &dummy, 10);
113 if (port < 1 || port > 65535 || *dummy != '\0')
114 usage();
115 sin.sin_port = htons(port);
116
117 count = strtoul(argv[2], &dummy, 10);
118 if (count < 1 || count > 100000 || *dummy != '\0')
119 usage();
120
121 for (i = 0; i < count; i++) {
122 sock = socket(PF_INET, SOCK_STREAM, 0);
104
105 port = strtoul(argv[1], &dummy, 10);
106 if (port < 1 || port > 65535 || *dummy != '\0')
107 usage();
108 sin.sin_port = htons(port);
109
110 count = strtoul(argv[2], &dummy, 10);
111 if (count < 1 || count > 100000 || *dummy != '\0')
112 usage();
113
114 for (i = 0; i < count; i++) {
115 sock = socket(PF_INET, SOCK_STREAM, 0);
123 if (sock == -1) {
124 perror("socket");
125 exit(-1);
126 }
116 if (sock == -1)
117 errx(-1, "socket: %s", strerror(errno));
127
118
128 if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1) {
129 perror("connect");
130 exit(-1);
131 }
119 if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
120 errx(-1, "connect: %s", strerror(errno));
132
133 close(sock);
134 }
135}
136
137int
138main(int argc, char *argv[])
139{

--- 13 unchanged lines hidden ---
121
122 close(sock);
123 }
124}
125
126int
127main(int argc, char *argv[])
128{

--- 13 unchanged lines hidden ---