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