2008-03-08 Roland McGrath <roland@frob.com>
[glibc.git] / posix / tst-rfc3484-2.c
blob56c0277b172a13f7ed2d2dd3f5976d49e0df4479
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;
21 void
22 attribute_hidden
23 __check_native (uint32_t a1_index, int *a1_native,
24 uint32_t a2_index, int *a2_native)
27 int
28 __idna_to_ascii_lz (const char *input, char **output, int flags)
30 return 0;
32 int
33 __idna_to_unicode_lzlz (const char *input, char **output, int flags)
35 *output = NULL;
36 return 0;
39 #include "../sysdeps/posix/getaddrinfo.c"
41 service_user *__nss_hosts_database attribute_hidden;
44 /* This is the beginning of the real test code. The above defines
45 (among other things) the function rfc3484_sort. */
48 #if __BYTE_ORDER == __BIG_ENDIAN
49 # define h(n) n
50 #else
51 # define h(n) __bswap_constant_32 (n)
52 #endif
55 ssize_t
56 __getline (char **lineptr, size_t *n, FILE *s)
58 *lineptr = NULL;
59 *n = 0;
60 return 0;
64 static int
65 do_test (void)
67 labels = default_labels;
68 precedence = default_precedence;
69 scopes = default_scopes;
71 struct sockaddr_in so1;
72 so1.sin_family = AF_INET;
73 so1.sin_addr.s_addr = h (0xc0a85f19);
75 struct sockaddr_in sa1;
76 sa1.sin_family = AF_INET;
77 sa1.sin_addr.s_addr = h (0xe0a85f19);
79 struct addrinfo ai1;
80 ai1.ai_family = AF_INET;
81 ai1.ai_addr = (struct sockaddr *) &sa1;
83 struct sockaddr_in6 so2;
84 so2.sin6_family = AF_INET6;
85 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
86 so2.sin6_addr.s6_addr32[1] = 1;
87 so2.sin6_addr.s6_addr32[2] = 1;
88 so2.sin6_addr.s6_addr32[3] = 1;
90 struct sockaddr_in6 sa2;
91 sa2.sin6_family = AF_INET6;
92 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
93 sa2.sin6_addr.s6_addr32[1] = 1;
94 sa2.sin6_addr.s6_addr32[2] = 1;
95 sa2.sin6_addr.s6_addr32[3] = 1;
97 struct addrinfo ai2;
98 ai2.ai_family = AF_INET6;
99 ai2.ai_addr = (struct sockaddr *) &sa2;
102 struct sort_result results[2];
103 size_t order[2];
105 results[0].dest_addr = &ai1;
106 results[0].got_source_addr = true;
107 results[0].source_addr_len = sizeof (so1);
108 results[0].source_addr_flags = 0;
109 results[0].prefixlen = 16;
110 results[0].index = 0;
111 memcpy (&results[0].source_addr, &so1, sizeof (so1));
112 order[0] = 0;
114 results[1].dest_addr = &ai2;
115 results[1].got_source_addr = true;
116 results[1].source_addr_len = sizeof (so2);
117 results[1].source_addr_flags = 0;
118 results[1].prefixlen = 16;
119 results[1].index = 0;
120 memcpy (&results[1].source_addr, &so2, sizeof (so2));
121 order[1] = 1;
124 struct sort_result_combo combo = { .results = results, .nresults = 2 };
125 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
127 int result = 0;
128 if (results[order[0]].dest_addr->ai_family == AF_INET6)
130 puts ("wrong order in first test");
131 result |= 1;
135 /* And again, this time with the reverse starting order. */
136 results[1].dest_addr = &ai1;
137 results[1].got_source_addr = true;
138 results[1].source_addr_len = sizeof (so1);
139 results[1].source_addr_flags = 0;
140 results[1].prefixlen = 16;
141 results[1].index = 0;
142 memcpy (&results[1].source_addr, &so1, sizeof (so1));
143 order[1] = 1;
145 results[0].dest_addr = &ai2;
146 results[0].got_source_addr = true;
147 results[0].source_addr_len = sizeof (so2);
148 results[0].source_addr_flags = 0;
149 results[0].prefixlen = 16;
150 results[0].index = 0;
151 memcpy (&results[0].source_addr, &so2, sizeof (so2));
152 order[0] = 0;
155 qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
157 if (results[order[0]].dest_addr->ai_family == AF_INET6)
159 puts ("wrong order in second test");
160 result |= 1;
163 return result;
166 #define TEST_FUNCTION do_test ()
167 #include "../test-skeleton.c"