]>
Commit | Line | Data |
---|---|---|
419bcf40 UD |
1 | #include <stdbool.h> |
2 | #include <stdio.h> | |
4c5bc828 | 3 | #include <ifaddrs.h> |
e054f494 | 4 | #include <stdint.h> |
419bcf40 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 |
419bcf40 UD |
14 | |
15 | void | |
16 | attribute_hidden | |
86e05449 | 17 | __check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen) |
419bcf40 UD |
18 | { |
19 | *p1 = *p2 = true; | |
86e05449 UD |
20 | *in6ai = NULL; |
21 | *in6ailen = 0; | |
419bcf40 | 22 | } |
b194db79 | 23 | |
fadb59f8 UD |
24 | void |
25 | attribute_hidden | |
26 | __free_in6ai (struct in6addrinfo *ai) | |
27 | { | |
28 | } | |
29 | ||
773e79b3 UD |
30 | void |
31 | attribute_hidden | |
32 | __check_native (uint32_t a1_index, int *a1_native, | |
33 | uint32_t a2_index, int *a2_native) | |
34 | { | |
35 | } | |
b194db79 | 36 | |
419bcf40 | 37 | int |
b194db79 | 38 | attribute_hidden |
419bcf40 UD |
39 | __idna_to_ascii_lz (const char *input, char **output, int flags) |
40 | { | |
41 | return 0; | |
42 | } | |
b194db79 | 43 | |
419bcf40 | 44 | int |
b194db79 | 45 | attribute_hidden |
419bcf40 UD |
46 | __idna_to_unicode_lzlz (const char *input, char **output, int flags) |
47 | { | |
ec1e04de | 48 | *output = NULL; |
419bcf40 UD |
49 | return 0; |
50 | } | |
51 | ||
b194db79 UD |
52 | void |
53 | attribute_hidden | |
54 | _res_hconf_init (void) | |
55 | { | |
56 | } | |
57 | ||
59a629f1 | 58 | #undef USE_NSCD |
419bcf40 UD |
59 | #include "../sysdeps/posix/getaddrinfo.c" |
60 | ||
eaf6753f | 61 | service_user *__nss_hosts_database attribute_hidden; |
419bcf40 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 | ||
73 | struct sockaddr_in addrs[] = | |
74 | { | |
11541177 JL |
75 | { .sin_family = AF_INET, .sin_addr = { h (0x0aa85f19) } }, |
76 | { .sin_family = AF_INET, .sin_addr = { h (0xac105f19) } }, | |
77 | { .sin_family = AF_INET, .sin_addr = { h (0xc0000219) } }, | |
419bcf40 UD |
78 | { .sin_family = AF_INET, .sin_addr = { h (0xc0a86d1d) } }, |
79 | { .sin_family = AF_INET, .sin_addr = { h (0xc0a85d03) } }, | |
80 | { .sin_family = AF_INET, .sin_addr = { h (0xc0a82c3d) } }, | |
81 | { .sin_family = AF_INET, .sin_addr = { h (0xc0a86002) } }, | |
82 | { .sin_family = AF_INET, .sin_addr = { h (0xc0a802f3) } }, | |
83 | { .sin_family = AF_INET, .sin_addr = { h (0xc0a80810) } }, | |
84 | { .sin_family = AF_INET, .sin_addr = { h (0xc0a85e02) } } | |
85 | }; | |
86 | #define naddrs (sizeof (addrs) / sizeof (addrs[0])) | |
87 | static struct addrinfo ais[naddrs]; | |
88 | static struct sort_result results[naddrs]; | |
0efd1956 | 89 | static size_t order[naddrs]; |
419bcf40 UD |
90 | |
91 | static int expected[naddrs] = | |
92 | { | |
11541177 | 93 | 9, 4, 3, 6, 5, 7, 8, 2, 0, 1 |
419bcf40 UD |
94 | }; |
95 | ||
96 | ||
77dd4c3b UD |
97 | ssize_t |
98 | __getline (char **lineptr, size_t *n, FILE *s) | |
99 | { | |
100 | *lineptr = NULL; | |
101 | *n = 0; | |
102 | return 0; | |
103 | } | |
104 | ||
105 | ||
419bcf40 UD |
106 | static int |
107 | do_test (void) | |
108 | { | |
77dd4c3b UD |
109 | labels = default_labels; |
110 | precedence = default_precedence; | |
ee72b971 | 111 | scopes= default_scopes; |
77dd4c3b | 112 | |
419bcf40 UD |
113 | struct sockaddr_in so; |
114 | so.sin_family = AF_INET; | |
115 | so.sin_addr.s_addr = h (0xc0a85f19); | |
666a9871 UD |
116 | /* Clear the rest of the structure to avoid warnings. */ |
117 | memset (so.sin_zero, '\0', sizeof (so.sin_zero)); | |
419bcf40 UD |
118 | |
119 | for (int i = 0; i < naddrs; ++i) | |
120 | { | |
121 | ais[i].ai_family = AF_INET; | |
122 | ais[i].ai_addr = (struct sockaddr *) &addrs[i]; | |
123 | results[i].dest_addr = &ais[i]; | |
124 | results[i].got_source_addr = true; | |
125 | memcpy(&results[i].source_addr, &so, sizeof (so)); | |
126 | results[i].source_addr_len = sizeof (so); | |
bdefc84c | 127 | results[i].source_addr_flags = 0; |
bd63f380 | 128 | results[i].prefixlen = 8; |
773e79b3 | 129 | results[i].index = 0; |
0efd1956 UD |
130 | |
131 | order[i] = i; | |
419bcf40 UD |
132 | } |
133 | ||
773e79b3 | 134 | struct sort_result_combo combo = { .results = results, .nresults = naddrs }; |
0efd1956 | 135 | qsort_r (order, naddrs, sizeof (order[0]), rfc3484_sort, &combo); |
419bcf40 UD |
136 | |
137 | int result = 0; | |
138 | for (int i = 0; i < naddrs; ++i) | |
139 | { | |
0efd1956 | 140 | struct in_addr addr = ((struct sockaddr_in *) (results[order[i]].dest_addr->ai_addr))->sin_addr; |
419bcf40 UD |
141 | |
142 | int here = memcmp (&addr, &addrs[expected[i]].sin_addr, | |
143 | sizeof (struct in_addr)); | |
144 | printf ("[%d] = %s: %s\n", i, inet_ntoa (addr), here ? "FAIL" : "OK"); | |
145 | result |= here; | |
146 | } | |
147 | ||
148 | return result; | |
149 | } | |
150 | ||
151 | #define TEST_FUNCTION do_test () | |
152 | #include "../test-skeleton.c" |