2 * test80: use the functions originally written for test56 to test TCP
6 #include <netinet/in.h>
9 #include <sys/socket.h>
12 #include "common-socket.h"
17 static void callback_check_sockaddr(const struct sockaddr
*sockaddr
,
18 socklen_t sockaddrlen
, const char *callname
, int addridx
) {
21 const struct sockaddr_in
*sockaddr_in
=
22 (const struct sockaddr_in
*) sockaddr
;
25 case 1: port
= PORT1
; break;
26 case 2: port
= PORT2
; break;
28 fprintf(stderr
, "error: invalid addridx %d in "
29 "callback_check_sockaddr\n", addridx
);
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",
39 memset(buf
, 0, sizeof(buf
));
40 inet_ntop(sockaddr_in
->sin_family
, &sockaddr_in
->sin_addr
,
42 fprintf(stderr
, "exp: localhost:%d | got: %s:%d\n", port
, buf
,
43 ntohs(sockaddr_in
->sin_port
));
47 static void callback_cleanup(void) {
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
),
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
),
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()");
118 test_getsockname(&info
);
119 test_shutdown(&info
);
123 test_shutdown(&info
);
126 test_sockopts(&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
);
134 test_connect_close(&info
);
135 /* test_listen_close(&info); -- not suitable for TCP */
136 test_listen_close_nb(&info
);
140 return -1; /* we should never get here */