Drop main() prototype. Syncs with NetBSD-8
[minix.git] / minix / tests / test81.c
blob61510cf0caf31f497cef4f6b131bff39bac6dbcc
1 /*
2 * test81: use the functions originally written for test56 to test UDP
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 = 32768,
82 .expected_sndbuf = 8192,
83 .serveraddr = (struct sockaddr *) &serveraddr,
84 .serveraddrlen = sizeof(serveraddr),
85 .serveraddr2 = (struct sockaddr *) &serveraddr2,
86 .serveraddr2len = sizeof(serveraddr2),
87 .type = SOCK_DGRAM,
88 .types = &info.type,
89 .typecount = 1,
90 .callback_check_sockaddr = callback_check_sockaddr,
91 .callback_cleanup = callback_cleanup,
92 .callback_xfer_prepclient = NULL,
93 .callback_xfer_peercred = NULL,
96 debug("entering main()");
98 start(81);
100 test_socket(&info);
101 test_bind(&info);
102 test_getsockname(&info);
103 test_shutdown(&info);
104 test_close(&info);
105 test_dup(&info);
106 test_dup2(&info);
107 test_shutdown(&info);
108 test_read(&info);
109 test_write(&info);
110 test_sockopts(&info);
111 test_simple_client_server(&info, info.type);
113 quit();
115 return -1; /* we should never get here */