* Versions.def (glibc): Add GLIBC_2.9.
[glibc.git] / posix / tst-rfc3484-2.c
blobc85fdd0742b152042e547f008a2192516ebfbfd5
1 #include <stdbool.h>
2 #include <stdio.h>
3 #include <ifaddrs.h>
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
13 void
14 attribute_hidden
15 __check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
17 *p1 = *p2 = true;
18 *in6ai = NULL;
19 *in6ailen = 0;
22 void
23 attribute_hidden
24 __check_native (uint32_t a1_index, int *a1_native,
25 uint32_t a2_index, int *a2_native)
29 int
30 attribute_hidden
31 __idna_to_ascii_lz (const char *input, char **output, int flags)
33 return 0;
36 int
37 attribute_hidden
38 __idna_to_unicode_lzlz (const char *input, char **output, int flags)
40 *output = NULL;
41 return 0;
44 void
45 attribute_hidden
46 _res_hconf_init (void)
50 #include "../sysdeps/posix/getaddrinfo.c"
52 service_user *__nss_hosts_database attribute_hidden;
55 /* This is the beginning of the real test code. The above defines
56 (among other things) the function rfc3484_sort. */
59 #if __BYTE_ORDER == __BIG_ENDIAN
60 # define h(n) n
61 #else
62 # define h(n) __bswap_constant_32 (n)
63 #endif
66 ssize_t
67 __getline (char **lineptr, size_t *n, FILE *s)
69 *lineptr = NULL;
70 *n = 0;
71 return 0;
75 static int
76 do_test (void)
78 labels = default_labels;
79 precedence = default_precedence;
80 scopes = default_scopes;
82 struct sockaddr_in so1;
83 so1.sin_family = AF_INET;
84 so1.sin_addr.s_addr = h (0xc0a85f19);
86 struct sockaddr_in sa1;
87 sa1.sin_family = AF_INET;
88 sa1.sin_addr.s_addr = h (0xe0a85f19);
90 struct addrinfo ai1;
91 ai1.ai_family = AF_INET;
92 ai1.ai_addr = (struct sockaddr *) &sa1;
94 struct sockaddr_in6 so2;
95 so2.sin6_family = AF_INET6;
96 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
97 so2.sin6_addr.s6_addr32[1] = 1;
98 so2.sin6_addr.s6_addr32[2] = 1;
99 so2.sin6_addr.s6_addr32[3] = 1;
101 struct sockaddr_in6 sa2;
102 sa2.sin6_family = AF_INET6;
103 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
104 sa2.sin6_addr.s6_addr32[1] = 1;
105 sa2.sin6_addr.s6_addr32[2] = 1;
106 sa2.sin6_addr.s6_addr32[3] = 1;
108 struct addrinfo ai2;
109 ai2.ai_family = AF_INET6;
110 ai2.ai_addr = (struct sockaddr *) &sa2;
113 struct sort_result results[2];
114 size_t order[2];
116 results[0].dest_addr = &ai1;
117 results[0].got_source_addr = true;
118 results[0].source_addr_len = sizeof (so1);
119 results[0].source_addr_flags = 0;
120 results[0].prefixlen = 16;
121 results[0].index = 0;
122 memcpy (&results[0].source_addr, &so1, sizeof (so1));
123 order[0] = 0;
125 results[1].dest_addr = &ai2;
126 results[1].got_source_addr = true;
127 results[1].source_addr_len = sizeof (so2);
128 results[1].source_addr_flags = 0;
129 results[1].prefixlen = 16;
130 results[1].index = 0;
131 memcpy (&results[1].source_addr, &so2, sizeof (so2));
132 order[1] = 1;
135 struct sort_result_combo combo = { .results = results, .nresults = 2 };
136 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
138 int result = 0;
139 if (results[order[0]].dest_addr->ai_family == AF_INET6)
141 puts ("wrong order in first test");
142 result |= 1;
146 /* And again, this time with the reverse starting order. */
147 results[1].dest_addr = &ai1;
148 results[1].got_source_addr = true;
149 results[1].source_addr_len = sizeof (so1);
150 results[1].source_addr_flags = 0;
151 results[1].prefixlen = 16;
152 results[1].index = 0;
153 memcpy (&results[1].source_addr, &so1, sizeof (so1));
154 order[1] = 1;
156 results[0].dest_addr = &ai2;
157 results[0].got_source_addr = true;
158 results[0].source_addr_len = sizeof (so2);
159 results[0].source_addr_flags = 0;
160 results[0].prefixlen = 16;
161 results[0].index = 0;
162 memcpy (&results[0].source_addr, &so2, sizeof (so2));
163 order[0] = 0;
166 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
168 if (results[order[0]].dest_addr->ai_family == AF_INET6)
170 puts ("wrong order in second test");
171 result |= 1;
174 return result;
177 #define TEST_FUNCTION do_test ()
178 #include "../test-skeleton.c"