Add sysdeps/ieee754/soft-fp.
[glibc.git] / posix / tst-rfc3484-2.c
blobf509534ca9b99775880ba6fa90f11d6fbe4251b3
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"
62 /* This is the beginning of the real test code. The above defines
63 (among other things) the function rfc3484_sort. */
66 #if __BYTE_ORDER == __BIG_ENDIAN
67 # define h(n) n
68 #else
69 # define h(n) __bswap_constant_32 (n)
70 #endif
73 ssize_t
74 __getline (char **lineptr, size_t *n, FILE *s)
76 *lineptr = NULL;
77 *n = 0;
78 return 0;
82 static int
83 do_test (void)
85 labels = default_labels;
86 precedence = default_precedence;
87 scopes = default_scopes;
89 struct sockaddr_in so1;
90 so1.sin_family = AF_INET;
91 so1.sin_addr.s_addr = h (0xc0a85f19);
92 /* Clear the rest of the structure to avoid warnings. */
93 memset (so1.sin_zero, '\0', sizeof (so1.sin_zero));
95 struct sockaddr_in sa1;
96 sa1.sin_family = AF_INET;
97 sa1.sin_addr.s_addr = h (0xe0a85f19);
99 struct addrinfo ai1;
100 ai1.ai_family = AF_INET;
101 ai1.ai_addr = (struct sockaddr *) &sa1;
103 struct sockaddr_in6 so2;
104 so2.sin6_family = AF_INET6;
105 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
106 so2.sin6_addr.s6_addr32[1] = 1;
107 so2.sin6_addr.s6_addr32[2] = 1;
108 so2.sin6_addr.s6_addr32[3] = 1;
110 struct sockaddr_in6 sa2;
111 sa2.sin6_family = AF_INET6;
112 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
113 sa2.sin6_addr.s6_addr32[1] = 1;
114 sa2.sin6_addr.s6_addr32[2] = 1;
115 sa2.sin6_addr.s6_addr32[3] = 1;
117 struct addrinfo ai2;
118 ai2.ai_family = AF_INET6;
119 ai2.ai_addr = (struct sockaddr *) &sa2;
122 struct sort_result results[2];
123 size_t order[2];
125 results[0].dest_addr = &ai1;
126 results[0].got_source_addr = true;
127 results[0].source_addr_len = sizeof (so1);
128 results[0].source_addr_flags = 0;
129 results[0].prefixlen = 16;
130 results[0].index = 0;
131 memcpy (&results[0].source_addr, &so1, sizeof (so1));
132 order[0] = 0;
134 results[1].dest_addr = &ai2;
135 results[1].got_source_addr = true;
136 results[1].source_addr_len = sizeof (so2);
137 results[1].source_addr_flags = 0;
138 results[1].prefixlen = 16;
139 results[1].index = 0;
140 memcpy (&results[1].source_addr, &so2, sizeof (so2));
141 order[1] = 1;
144 struct sort_result_combo combo = { .results = results, .nresults = 2 };
145 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
147 int result = 0;
148 if (results[order[0]].dest_addr->ai_family == AF_INET6)
150 puts ("wrong order in first test");
151 result |= 1;
155 /* And again, this time with the reverse starting order. */
156 results[1].dest_addr = &ai1;
157 results[1].got_source_addr = true;
158 results[1].source_addr_len = sizeof (so1);
159 results[1].source_addr_flags = 0;
160 results[1].prefixlen = 16;
161 results[1].index = 0;
162 memcpy (&results[1].source_addr, &so1, sizeof (so1));
163 order[1] = 1;
165 results[0].dest_addr = &ai2;
166 results[0].got_source_addr = true;
167 results[0].source_addr_len = sizeof (so2);
168 results[0].source_addr_flags = 0;
169 results[0].prefixlen = 16;
170 results[0].index = 0;
171 memcpy (&results[0].source_addr, &so2, sizeof (so2));
172 order[0] = 0;
175 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
177 if (results[order[0]].dest_addr->ai_family == AF_INET6)
179 puts ("wrong order in second test");
180 result |= 1;
183 return result;
186 #define TEST_FUNCTION do_test ()
187 #include "../test-skeleton.c"