Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / tests / test80.c
blob99e65376b1201ac5267b42562788ac4ff12c75cd
1 /*
2 * test80: use the functions originally written for test56 to test TCP
3 */
5 #include <arpa/inet.h>
6 #include <netinet/in.h>
7 #include <stdio.h>
8 #include <stdlib.h>
9 #include <sys/socket.h>
11 #include "common.h"
12 #include "common-socket.h"
14 #define PORT1 4321
15 #define PORT2 4322
17 static void callback_check_sockaddr(const struct sockaddr *sockaddr,
18 socklen_t sockaddrlen, const char *callname, int addridx) {
19 char buf[256];
20 int port;
21 const struct sockaddr_in *sockaddr_in =
22 (const struct sockaddr_in *) sockaddr;
24 switch (addridx) {
25 case 1: port = PORT1; break;
26 case 2: port = PORT2; break;
27 default:
28 fprintf(stderr, "error: invalid addridx %d in "
29 "callback_check_sockaddr\n", addridx);
30 abort();
33 if (sockaddr_in->sin_family != AF_INET ||
34 sockaddr_in->sin_port != htons(port)) {
35 snprintf(buf, sizeof(buf), "%s() didn't return the right addr",
36 callname);
37 test_fail(buf);
39 memset(buf, 0, sizeof(buf));
40 inet_ntop(sockaddr_in->sin_family, &sockaddr_in->sin_addr,
41 buf, sizeof(buf));
42 fprintf(stderr, "exp: localhost:%d | got: %s:%d\n", port, buf,
43 ntohs(sockaddr_in->sin_port));
47 static void callback_cleanup(void) {
48 /* nothing to do */
51 int main(int argc, char *argv[])
53 struct sockaddr_in clientaddr = {
54 .sin_family = AF_INET,
55 .sin_port = htons(PORT1),
56 .sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
58 struct sockaddr_in clientaddr2 = {
59 .sin_family = AF_INET,
60 .sin_port = htons(PORT2),
61 .sin_addr = { .s_addr = htonl(INADDR_LOOPBACK) },
63 struct sockaddr_in serveraddr = {
64 .sin_family = AF_INET,
65 .sin_port = htons(PORT1),
66 .sin_addr = { .s_addr = htonl(INADDR_ANY) },
68 struct sockaddr_in serveraddr2 = {
69 .sin_family = AF_INET,
70 .sin_port = htons(PORT2),
71 .sin_addr = { .s_addr = htonl(INADDR_ANY) },
73 const struct socket_test_info info = {
74 .clientaddr = (struct sockaddr *) &clientaddr,
75 .clientaddrlen = sizeof(clientaddr),
76 .clientaddr2 = (struct sockaddr *) &clientaddr2,
77 .clientaddr2len = sizeof(clientaddr2),
78 .clientaddrsym = (struct sockaddr *) &clientaddr,
79 .clientaddrsymlen = sizeof(clientaddr),
80 .domain = PF_INET,
81 .expected_rcvbuf = -1,
82 .expected_sndbuf = -1,
83 .serveraddr = (struct sockaddr *) &serveraddr,
84 .serveraddrlen = sizeof(serveraddr),
85 .serveraddr2 = (struct sockaddr *) &serveraddr2,
86 .serveraddr2len = sizeof(serveraddr2),
87 .type = SOCK_STREAM,
88 .types = &info.type,
89 .typecount = 1,
92 * Maintainer's note: common-socket was adapted from test56 in
93 * a time that UDS's LOCAL_CONNWAIT was the default. Due to
94 * this as well as inherent behavioral differences between TCP
95 * and UDS, these exceptions basically work around the fact
96 * that common-socket was not designed for its current task.
98 .ignore_accept_delay = 1,
99 .ignore_connect_unaccepted = 1,
100 .ignore_connect_delay = 1,
101 .ignore_select_delay = 1,
102 .ignore_send_waiting = 1,
103 .ignore_write_conn_reset = 1,
105 .callback_check_sockaddr = callback_check_sockaddr,
106 .callback_cleanup = callback_cleanup,
107 .callback_xfer_prepclient = NULL,
108 .callback_xfer_peercred = NULL,
111 debug("entering main()");
113 start(80);
115 test_socket(&info);
116 test_bind(&info);
117 test_listen(&info);
118 test_getsockname(&info);
119 test_shutdown(&info);
120 test_close(&info);
121 test_dup(&info);
122 test_dup2(&info);
123 test_shutdown(&info);
124 test_read(&info);
125 test_write(&info);
126 test_sockopts(&info);
127 test_xfer(&info);
128 test_simple_client_server(&info, info.type);
129 test_abort_client_server(&info, 1);
130 test_abort_client_server(&info, 2);
131 test_nonblock(&info);
132 test_connect_nb(&info);
133 test_intr(&info);
134 test_connect_close(&info);
135 /* test_listen_close(&info); -- not suitable for TCP */
136 test_listen_close_nb(&info);
138 quit();
140 return -1; /* we should never get here */