]> git.ipfire.org Git - thirdparty/glibc.git/blame - posix/tst-rfc3484-3.c
Fix posix/tst-regex by using a dedicated input-file.
[thirdparty/glibc.git] / posix / tst-rfc3484-3.c
CommitLineData
ee72b971
UD
1#include <stdbool.h>
2#include <stdio.h>
3#include <ifaddrs.h>
e054f494 4#include <stdint.h>
ee72b971
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
ee72b971
UD
14
15void
16attribute_hidden
17__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
18{
19 *p1 = *p2 = true;
20 *in6ai = NULL;
21 *in6ailen = 0;
22}
b194db79 23
fadb59f8
UD
24void
25attribute_hidden
26__free_in6ai (struct in6addrinfo *ai)
27{
28}
29
ee72b971
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
ee72b971 37int
b194db79 38attribute_hidden
ee72b971
UD
39__idna_to_ascii_lz (const char *input, char **output, int flags)
40{
41 return 0;
42}
b194db79 43
ee72b971 44int
b194db79 45attribute_hidden
ee72b971
UD
46__idna_to_unicode_lzlz (const char *input, char **output, int flags)
47{
48 *output = NULL;
49 return 0;
50}
51
b194db79
UD
52void
53attribute_hidden
54_res_hconf_init (void)
55{
56}
57
59a629f1 58#undef USE_NSCD
ee72b971
UD
59#include "../sysdeps/posix/getaddrinfo.c"
60
eaf6753f 61service_user *__nss_hosts_database attribute_hidden;
ee72b971
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
73struct sockaddr_in addrs[] =
74{
75 { .sin_family = AF_INET, .sin_addr = { h (0xa0a86d1d) } },
76 { .sin_family = AF_INET, .sin_addr = { h (0xa0a85d03) } },
77 { .sin_family = AF_INET, .sin_addr = { h (0xa0a82c3d) } },
78 { .sin_family = AF_INET, .sin_addr = { h (0xa0a86002) } },
79 { .sin_family = AF_INET, .sin_addr = { h (0xa0a802f3) } },
80 { .sin_family = AF_INET, .sin_addr = { h (0xa0a80810) } },
81 { .sin_family = AF_INET, .sin_addr = { h (0xa0a85e02) } },
82 { .sin_family = AF_INET, .sin_addr = { h (0xac162311) } },
83 { .sin_family = AF_INET, .sin_addr = { h (0x0a324572) } }
84};
85#define naddrs (sizeof (addrs) / sizeof (addrs[0]))
86static struct addrinfo ais[naddrs];
87static struct sort_result results[naddrs];
0efd1956 88static size_t order[naddrs];
ee72b971
UD
89
90static const int expected[naddrs] =
91 {
92 8, 0, 1, 2, 3, 4, 5, 6, 7
93 };
94
95static const struct scopeentry new_scopes[] =
96 {
97 { { { 169, 254, 0, 0 } }, h (0xffff0000), 2 },
98 { { { 127, 0, 0, 0 } }, h (0xff000000), 2 },
99 { { { 10, 0, 0, 0 } }, h (0xff000000), 5 },
100 { { { 192, 168, 0, 0 } }, h(0xffff0000), 5 },
101 { { { 0, 0, 0, 0 } }, h (0x00000000), 14 }
102 };
103
104
105ssize_t
106__getline (char **lineptr, size_t *n, FILE *s)
107{
108 *lineptr = NULL;
109 *n = 0;
110 return 0;
111}
112
113
114static int
115do_test (void)
116{
117 labels = default_labels;
118 precedence = default_precedence;
119 scopes= new_scopes;
120
121 struct sockaddr_in so;
122 so.sin_family = AF_INET;
123 so.sin_addr.s_addr = h (0x0aa85f19);
666a9871
UD
124 /* Clear the rest of the structure to avoid warnings. */
125 memset (so.sin_zero, '\0', sizeof (so.sin_zero));
ee72b971
UD
126
127 for (int i = 0; i < naddrs; ++i)
128 {
129 ais[i].ai_family = AF_INET;
130 ais[i].ai_addr = (struct sockaddr *) &addrs[i];
131 results[i].dest_addr = &ais[i];
132 results[i].got_source_addr = true;
133 memcpy(&results[i].source_addr, &so, sizeof (so));
134 results[i].source_addr_len = sizeof (so);
135 results[i].source_addr_flags = 0;
ee72b971
UD
136 results[i].prefixlen = 8;
137 results[i].index = 0;
0efd1956
UD
138
139 order[i] = i;
ee72b971
UD
140 }
141
142 struct sort_result_combo combo = { .results = results, .nresults = naddrs };
0efd1956 143 qsort_r (order, naddrs, sizeof (order[0]), rfc3484_sort, &combo);
ee72b971
UD
144
145 int result = 0;
146 for (int i = 0; i < naddrs; ++i)
147 {
0efd1956 148 struct in_addr addr = ((struct sockaddr_in *) (results[order[i]].dest_addr->ai_addr))->sin_addr;
ee72b971
UD
149
150 int here = memcmp (&addr, &addrs[expected[i]].sin_addr,
151 sizeof (struct in_addr));
152 printf ("[%d] = %s: %s\n", i, inet_ntoa (addr), here ? "FAIL" : "OK");
153 result |= here;
154 }
155
156 return result;
157}
158
159#define TEST_FUNCTION do_test ()
160#include "../test-skeleton.c"