2 * test81: use the functions originally written for test56 to test UDP
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
= 32768,
82 .expected_sndbuf
= 8192,
83 .serveraddr
= (struct sockaddr
*) &serveraddr
,
84 .serveraddrlen
= sizeof(serveraddr
),
85 .serveraddr2
= (struct sockaddr
*) &serveraddr2
,
86 .serveraddr2len
= sizeof(serveraddr2
),
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()");
102 test_getsockname(&info
);
103 test_shutdown(&info
);
107 test_shutdown(&info
);
110 test_sockopts(&info
);
111 test_simple_client_server(&info
, info
.type
);
115 return -1; /* we should never get here */