Simplify _ELF_DYNAMIC_DO_RELOC after combining the old two defs.
[glibc.git] / posix / tst-rfc3484-2.c
blob298fe6695ccf062df79f0ef8571b2f407981c995
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 __free_in6ai (struct in6addrinfo *ai)
28 void
29 attribute_hidden
30 __check_native (uint32_t a1_index, int *a1_native,
31 uint32_t a2_index, int *a2_native)
35 int
36 attribute_hidden
37 __idna_to_ascii_lz (const char *input, char **output, int flags)
39 return 0;
42 int
43 attribute_hidden
44 __idna_to_unicode_lzlz (const char *input, char **output, int flags)
46 *output = NULL;
47 return 0;
50 void
51 attribute_hidden
52 _res_hconf_init (void)
56 #include "../sysdeps/posix/getaddrinfo.c"
58 service_user *__nss_hosts_database attribute_hidden;
61 /* This is the beginning of the real test code. The above defines
62 (among other things) the function rfc3484_sort. */
65 #if __BYTE_ORDER == __BIG_ENDIAN
66 # define h(n) n
67 #else
68 # define h(n) __bswap_constant_32 (n)
69 #endif
72 ssize_t
73 __getline (char **lineptr, size_t *n, FILE *s)
75 *lineptr = NULL;
76 *n = 0;
77 return 0;
81 static int
82 do_test (void)
84 labels = default_labels;
85 precedence = default_precedence;
86 scopes = default_scopes;
88 struct sockaddr_in so1;
89 so1.sin_family = AF_INET;
90 so1.sin_addr.s_addr = h (0xc0a85f19);
91 /* Clear the rest of the structure to avoid warnings. */
92 memset (so1.sin_zero, '\0', sizeof (so1.sin_zero));
94 struct sockaddr_in sa1;
95 sa1.sin_family = AF_INET;
96 sa1.sin_addr.s_addr = h (0xe0a85f19);
98 struct addrinfo ai1;
99 ai1.ai_family = AF_INET;
100 ai1.ai_addr = (struct sockaddr *) &sa1;
102 struct sockaddr_in6 so2;
103 so2.sin6_family = AF_INET6;
104 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
105 so2.sin6_addr.s6_addr32[1] = 1;
106 so2.sin6_addr.s6_addr32[2] = 1;
107 so2.sin6_addr.s6_addr32[3] = 1;
109 struct sockaddr_in6 sa2;
110 sa2.sin6_family = AF_INET6;
111 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
112 sa2.sin6_addr.s6_addr32[1] = 1;
113 sa2.sin6_addr.s6_addr32[2] = 1;
114 sa2.sin6_addr.s6_addr32[3] = 1;
116 struct addrinfo ai2;
117 ai2.ai_family = AF_INET6;
118 ai2.ai_addr = (struct sockaddr *) &sa2;
121 struct sort_result results[2];
122 size_t order[2];
124 results[0].dest_addr = &ai1;
125 results[0].got_source_addr = true;
126 results[0].source_addr_len = sizeof (so1);
127 results[0].source_addr_flags = 0;
128 results[0].prefixlen = 16;
129 results[0].index = 0;
130 memcpy (&results[0].source_addr, &so1, sizeof (so1));
131 order[0] = 0;
133 results[1].dest_addr = &ai2;
134 results[1].got_source_addr = true;
135 results[1].source_addr_len = sizeof (so2);
136 results[1].source_addr_flags = 0;
137 results[1].prefixlen = 16;
138 results[1].index = 0;
139 memcpy (&results[1].source_addr, &so2, sizeof (so2));
140 order[1] = 1;
143 struct sort_result_combo combo = { .results = results, .nresults = 2 };
144 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
146 int result = 0;
147 if (results[order[0]].dest_addr->ai_family == AF_INET6)
149 puts ("wrong order in first test");
150 result |= 1;
154 /* And again, this time with the reverse starting order. */
155 results[1].dest_addr = &ai1;
156 results[1].got_source_addr = true;
157 results[1].source_addr_len = sizeof (so1);
158 results[1].source_addr_flags = 0;
159 results[1].prefixlen = 16;
160 results[1].index = 0;
161 memcpy (&results[1].source_addr, &so1, sizeof (so1));
162 order[1] = 1;
164 results[0].dest_addr = &ai2;
165 results[0].got_source_addr = true;
166 results[0].source_addr_len = sizeof (so2);
167 results[0].source_addr_flags = 0;
168 results[0].prefixlen = 16;
169 results[0].index = 0;
170 memcpy (&results[0].source_addr, &so2, sizeof (so2));
171 order[0] = 0;
174 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
176 if (results[order[0]].dest_addr->ai_family == AF_INET6)
178 puts ("wrong order in second test");
179 result |= 1;
182 return result;
185 #define TEST_FUNCTION do_test ()
186 #include "../test-skeleton.c"