Deleted Added
full compact
tcpconnect.c (146251) tcpconnect.c (174032)
1/*-
2 * Copyright (c) 2004-2005 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-2005 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 146251 2005-05-16 00:54:47Z rwatson $
26 * $FreeBSD: head/tools/regression/netinet/tcpconnect/tcpconnect.c 174032 2007-11-28 20:33:58Z bz $
27 */
28
29#include <sys/types.h>
30#include <sys/socket.h>
31
32#include <netinet/in.h>
27 */
28
29#include <sys/types.h>
30#include <sys/socket.h>
31
32#include <netinet/in.h>
33#include <netinet/tcp.h>
33
34#include <arpa/inet.h>
35
36#include <errno.h>
34
35#include <arpa/inet.h>
36
37#include <errno.h>
38#include <fcntl.h>
37#include <stdio.h>
38#include <stdlib.h>
39#include <string.h>
40#include <unistd.h>
41
39#include <stdio.h>
40#include <stdlib.h>
41#include <string.h>
42#include <unistd.h>
43
44
42static void
43usage(void)
44{
45
46 fprintf(stderr, "tcpconnect server port\n");
45static void
46usage(void)
47{
48
49 fprintf(stderr, "tcpconnect server port\n");
47 fprintf(stderr, "tcpconnect client ip port count\n");
50 fprintf(stderr, "tcpconnect client ip port count [nonblock] [tcpmd5]\n");
48 exit(-1);
49}
50
51static void
52tcpconnect_server(int argc, char *argv[])
53{
54 int listen_sock, accept_sock;
55 struct sockaddr_in sin;

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

87
88static void
89tcpconnect_client(int argc, char *argv[])
90{
91 struct sockaddr_in sin;
92 long count, i, port;
93 char *dummy;
94 int sock;
51 exit(-1);
52}
53
54static void
55tcpconnect_server(int argc, char *argv[])
56{
57 int listen_sock, accept_sock;
58 struct sockaddr_in sin;

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

90
91static void
92tcpconnect_client(int argc, char *argv[])
93{
94 struct sockaddr_in sin;
95 long count, i, port;
96 char *dummy;
97 int sock;
98 int nonblock = 0, md5enable = 0;
95
99
96 if (argc != 3)
100 if (argc < 3 || argc > 5)
97 usage();
101 usage();
102 for (i=3; i < argc; i++) {
103 if (strcmp(argv[i], "nonblock") == 0)
104 nonblock = 1;
105 if (strcmp(argv[i], "tcpmd5") == 0)
106 md5enable = 1;
107 }
98
99 bzero(&sin, sizeof(sin));
100 sin.sin_len = sizeof(sin);
101 sin.sin_family = AF_INET;
102 if (inet_aton(argv[0], &sin.sin_addr) == 0)
103 errx(-1, "listen: %x", strerror(errno));
104
105 port = strtoul(argv[1], &dummy, 10);

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

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);
116 if (sock == -1)
117 errx(-1, "socket: %s", strerror(errno));
118
108
109 bzero(&sin, sizeof(sin));
110 sin.sin_len = sizeof(sin);
111 sin.sin_family = AF_INET;
112 if (inet_aton(argv[0], &sin.sin_addr) == 0)
113 errx(-1, "listen: %x", strerror(errno));
114
115 port = strtoul(argv[1], &dummy, 10);

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

121 if (count < 1 || count > 100000 || *dummy != '\0')
122 usage();
123
124 for (i = 0; i < count; i++) {
125 sock = socket(PF_INET, SOCK_STREAM, 0);
126 if (sock == -1)
127 errx(-1, "socket: %s", strerror(errno));
128
119#ifdef NONBLOCK
120 if (fcntl(sock, F_SETFL, O_NONBLOCK) != 0)
121 errx(-1, "fcntl(F_SETFL): %s", strerror(errno));
129 /* No warning in default case on ENOPROTOOPT. */
130 if (setsockopt(sock, IPPROTO_TCP, TCP_MD5SIG,
131 &md5enable, sizeof(md5enable)) != 0) {
132 if (errno == ENOPROTOOPT && md5enable > 0)
133 err(-1, "setsockopt(TCP_MD5SIG)");
134 else if (errno != ENOPROTOOPT)
135 warn("setsockopt(TCP_MD5SIG)");
136 }
122
137
123 if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1
124 && errno != EINPROGRESS)
125 errx(-1, "connect: %s", strerror(errno));
126#else
127 if (connect(sock, (struct sockaddr *)&sin, sizeof(sin)) == -1)
128 errx(-1, "connect: %s", strerror(errno));
129#endif
138 if (nonblock) {
139 if (fcntl(sock, F_SETFL, O_NONBLOCK) != 0)
140 errx(-1, "fcntl(F_SETFL): %s", strerror(errno));
130
141
142 if (connect(sock, (struct sockaddr *)&sin,
143 sizeof(sin)) == -1 && errno != EINPROGRESS)
144 errx(-1, "connect: %s", strerror(errno));
145 } else {
146 if (connect(sock, (struct sockaddr *)&sin,
147 sizeof(sin)) == -1)
148 errx(-1, "connect: %s", strerror(errno));
149 }
150
131 close(sock);
132 }
133}
134
135int
136main(int argc, char *argv[])
137{
138

--- 12 unchanged lines hidden ---
151 close(sock);
152 }
153}
154
155int
156main(int argc, char *argv[])
157{
158

--- 12 unchanged lines hidden ---