Remove i486 subdirectory
[glibc.git] / posix / tst-rfc3484-3.c
blobc987366e4e45aa37d35bd4b780a22559b23dc0b7
1 #include <stdbool.h>
2 #include <stdio.h>
3 #include <ifaddrs.h>
4 #include <stdint.h>
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
13 #define __qsort_r qsort_r
15 void
16 attribute_hidden
17 __check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
19 *p1 = *p2 = true;
20 *in6ai = NULL;
21 *in6ailen = 0;
24 void
25 attribute_hidden
26 __free_in6ai (struct in6addrinfo *ai)
30 void
31 attribute_hidden
32 __check_native (uint32_t a1_index, int *a1_native,
33 uint32_t a2_index, int *a2_native)
37 int
38 attribute_hidden
39 __idna_to_ascii_lz (const char *input, char **output, int flags)
41 return 0;
44 int
45 attribute_hidden
46 __idna_to_unicode_lzlz (const char *input, char **output, int flags)
48 *output = NULL;
49 return 0;
52 void
53 attribute_hidden
54 _res_hconf_init (void)
58 #undef USE_NSCD
59 #include "../sysdeps/posix/getaddrinfo.c"
61 service_user *__nss_hosts_database attribute_hidden;
64 /* This is the beginning of the real test code. The above defines
65 (among other things) the function rfc3484_sort. */
68 #if __BYTE_ORDER == __BIG_ENDIAN
69 # define h(n) n
70 #else
71 # define h(n) __bswap_constant_32 (n)
72 #endif
74 struct sockaddr_in addrs[] =
76 { .sin_family = AF_INET, .sin_addr = { h (0xa0a86d1d) } },
77 { .sin_family = AF_INET, .sin_addr = { h (0xa0a85d03) } },
78 { .sin_family = AF_INET, .sin_addr = { h (0xa0a82c3d) } },
79 { .sin_family = AF_INET, .sin_addr = { h (0xa0a86002) } },
80 { .sin_family = AF_INET, .sin_addr = { h (0xa0a802f3) } },
81 { .sin_family = AF_INET, .sin_addr = { h (0xa0a80810) } },
82 { .sin_family = AF_INET, .sin_addr = { h (0xa0a85e02) } },
83 { .sin_family = AF_INET, .sin_addr = { h (0xac162311) } },
84 { .sin_family = AF_INET, .sin_addr = { h (0x0a324572) } }
86 #define naddrs (sizeof (addrs) / sizeof (addrs[0]))
87 static struct addrinfo ais[naddrs];
88 static struct sort_result results[naddrs];
89 static size_t order[naddrs];
91 static const int expected[naddrs] =
93 8, 0, 1, 2, 3, 4, 5, 6, 7
96 static const struct scopeentry new_scopes[] =
98 { { { 169, 254, 0, 0 } }, h (0xffff0000), 2 },
99 { { { 127, 0, 0, 0 } }, h (0xff000000), 2 },
100 { { { 10, 0, 0, 0 } }, h (0xff000000), 5 },
101 { { { 192, 168, 0, 0 } }, h(0xffff0000), 5 },
102 { { { 0, 0, 0, 0 } }, h (0x00000000), 14 }
106 ssize_t
107 __getline (char **lineptr, size_t *n, FILE *s)
109 *lineptr = NULL;
110 *n = 0;
111 return 0;
115 static int
116 do_test (void)
118 labels = default_labels;
119 precedence = default_precedence;
120 scopes= new_scopes;
122 struct sockaddr_in so;
123 so.sin_family = AF_INET;
124 so.sin_addr.s_addr = h (0x0aa85f19);
125 /* Clear the rest of the structure to avoid warnings. */
126 memset (so.sin_zero, '\0', sizeof (so.sin_zero));
128 for (int i = 0; i < naddrs; ++i)
130 ais[i].ai_family = AF_INET;
131 ais[i].ai_addr = (struct sockaddr *) &addrs[i];
132 results[i].dest_addr = &ais[i];
133 results[i].got_source_addr = true;
134 memcpy(&results[i].source_addr, &so, sizeof (so));
135 results[i].source_addr_len = sizeof (so);
136 results[i].source_addr_flags = 0;
137 results[i].prefixlen = 8;
138 results[i].index = 0;
140 order[i] = i;
143 struct sort_result_combo combo = { .results = results, .nresults = naddrs };
144 qsort_r (order, naddrs, sizeof (order[0]), rfc3484_sort, &combo);
146 int result = 0;
147 for (int i = 0; i < naddrs; ++i)
149 struct in_addr addr = ((struct sockaddr_in *) (results[order[i]].dest_addr->ai_addr))->sin_addr;
151 int here = memcmp (&addr, &addrs[expected[i]].sin_addr,
152 sizeof (struct in_addr));
153 printf ("[%d] = %s: %s\n", i, inet_ntoa (addr), here ? "FAIL" : "OK");
154 result |= here;
157 return result;
160 #define TEST_FUNCTION do_test ()
161 #include "../test-skeleton.c"