]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/tst-rfc3484-2.c
Add TCP_TX_DELAY from Linux 5.3 to netinet/tcp.h.
[thirdparty/glibc.git] / posix / tst-rfc3484-2.c
CommitLineData
a2387282
UD
1#include <stdbool.h>
2#include <stdio.h>
4c5bc828 3#include <ifaddrs.h>
e054f494 4#include <stdint.h>
a2387282
UD
5
6/* Internal definitions used in the libc code. */
7#define __getservbyname_r getservbyname_r
8#define __socket socket
9#define __getsockname getsockname
10#define __inet_aton inet_aton
11#define __gethostbyaddr_r gethostbyaddr_r
12#define __gethostbyname2_r gethostbyname2_r
bef8fd60 13#define __qsort_r qsort_r
a2387282
UD
14
15void
16attribute_hidden
86e05449 17__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
a2387282
UD
18{
19 *p1 = *p2 = true;
86e05449
UD
20 *in6ai = NULL;
21 *in6ailen = 0;
a2387282 22}
b194db79 23
fadb59f8
UD
24void
25attribute_hidden
26__free_in6ai (struct in6addrinfo *ai)
27{
28}
29
773e79b3
UD
30void
31attribute_hidden
32__check_native (uint32_t a1_index, int *a1_native,
33 uint32_t a2_index, int *a2_native)
34{
35}
b194db79 36
a2387282 37int
b194db79 38attribute_hidden
a2387282
UD
39__idna_to_ascii_lz (const char *input, char **output, int flags)
40{
41 return 0;
42}
b194db79 43
a2387282 44int
b194db79 45attribute_hidden
a2387282
UD
46__idna_to_unicode_lzlz (const char *input, char **output, int flags)
47{
ec1e04de 48 *output = NULL;
a2387282
UD
49 return 0;
50}
51
b194db79
UD
52void
53attribute_hidden
54_res_hconf_init (void)
55{
56}
57
59a629f1 58#undef USE_NSCD
a2387282
UD
59#include "../sysdeps/posix/getaddrinfo.c"
60
eaf6753f 61service_user *__nss_hosts_database attribute_hidden;
a2387282
UD
62
63/* This is the beginning of the real test code. The above defines
64 (among other things) the function rfc3484_sort. */
65
66
67#if __BYTE_ORDER == __BIG_ENDIAN
68# define h(n) n
69#else
70# define h(n) __bswap_constant_32 (n)
71#endif
72
73
77dd4c3b
UD
74ssize_t
75__getline (char **lineptr, size_t *n, FILE *s)
76{
77 *lineptr = NULL;
78 *n = 0;
79 return 0;
80}
81
82
a2387282
UD
83static int
84do_test (void)
85{
77dd4c3b
UD
86 labels = default_labels;
87 precedence = default_precedence;
ee72b971 88 scopes = default_scopes;
77dd4c3b 89
a2387282
UD
90 struct sockaddr_in so1;
91 so1.sin_family = AF_INET;
92 so1.sin_addr.s_addr = h (0xc0a85f19);
666a9871
UD
93 /* Clear the rest of the structure to avoid warnings. */
94 memset (so1.sin_zero, '\0', sizeof (so1.sin_zero));
a2387282
UD
95
96 struct sockaddr_in sa1;
97 sa1.sin_family = AF_INET;
98 sa1.sin_addr.s_addr = h (0xe0a85f19);
99
100 struct addrinfo ai1;
101 ai1.ai_family = AF_INET;
102 ai1.ai_addr = (struct sockaddr *) &sa1;
103
104 struct sockaddr_in6 so2;
105 so2.sin6_family = AF_INET6;
106 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
107 so2.sin6_addr.s6_addr32[1] = 1;
108 so2.sin6_addr.s6_addr32[2] = 1;
109 so2.sin6_addr.s6_addr32[3] = 1;
110
111 struct sockaddr_in6 sa2;
112 sa2.sin6_family = AF_INET6;
113 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
114 sa2.sin6_addr.s6_addr32[1] = 1;
115 sa2.sin6_addr.s6_addr32[2] = 1;
116 sa2.sin6_addr.s6_addr32[3] = 1;
117
118 struct addrinfo ai2;
119 ai2.ai_family = AF_INET6;
120 ai2.ai_addr = (struct sockaddr *) &sa2;
121
122
123 struct sort_result results[2];
0efd1956 124 size_t order[2];
a2387282
UD
125
126 results[0].dest_addr = &ai1;
127 results[0].got_source_addr = true;
128 results[0].source_addr_len = sizeof (so1);
bdefc84c 129 results[0].source_addr_flags = 0;
bd63f380 130 results[0].prefixlen = 16;
773e79b3 131 results[0].index = 0;
a2387282 132 memcpy (&results[0].source_addr, &so1, sizeof (so1));
0efd1956 133 order[0] = 0;
a2387282
UD
134
135 results[1].dest_addr = &ai2;
136 results[1].got_source_addr = true;
137 results[1].source_addr_len = sizeof (so2);
bdefc84c 138 results[1].source_addr_flags = 0;
bd63f380 139 results[1].prefixlen = 16;
773e79b3 140 results[1].index = 0;
a2387282 141 memcpy (&results[1].source_addr, &so2, sizeof (so2));
0efd1956 142 order[1] = 1;
a2387282
UD
143
144
773e79b3 145 struct sort_result_combo combo = { .results = results, .nresults = 2 };
0efd1956 146 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
a2387282
UD
147
148 int result = 0;
0efd1956 149 if (results[order[0]].dest_addr->ai_family == AF_INET6)
a2387282
UD
150 {
151 puts ("wrong order in first test");
152 result |= 1;
153 }
154
155
156 /* And again, this time with the reverse starting order. */
157 results[1].dest_addr = &ai1;
158 results[1].got_source_addr = true;
159 results[1].source_addr_len = sizeof (so1);
bdefc84c 160 results[1].source_addr_flags = 0;
bd63f380 161 results[1].prefixlen = 16;
773e79b3 162 results[1].index = 0;
a2387282 163 memcpy (&results[1].source_addr, &so1, sizeof (so1));
0efd1956 164 order[1] = 1;
a2387282
UD
165
166 results[0].dest_addr = &ai2;
167 results[0].got_source_addr = true;
168 results[0].source_addr_len = sizeof (so2);
bdefc84c 169 results[0].source_addr_flags = 0;
bd63f380 170 results[0].prefixlen = 16;
773e79b3 171 results[0].index = 0;
a2387282 172 memcpy (&results[0].source_addr, &so2, sizeof (so2));
0efd1956 173 order[0] = 0;
a2387282
UD
174
175
0efd1956 176 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
a2387282 177
0efd1956 178 if (results[order[0]].dest_addr->ai_family == AF_INET6)
a2387282
UD
179 {
180 puts ("wrong order in second test");
181 result |= 1;
182 }
183
184 return result;
185}
186
187#define TEST_FUNCTION do_test ()
188#include "../test-skeleton.c"