Updated to fedora-glibc-20071212T1051
[glibc.git] / posix / tst-rfc3484-2.c
blobd29f0725cceffefc9a3233b965dec4ef11b836cf
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];
104 results[0].dest_addr = &ai1;
105 results[0].got_source_addr = true;
106 results[0].source_addr_len = sizeof (so1);
107 results[0].source_addr_flags = 0;
108 results[0].service_order = 0;
109 results[0].prefixlen = 16;
110 results[0].index = 0;
111 memcpy (&results[0].source_addr, &so1, sizeof (so1));
113 results[1].dest_addr = &ai2;
114 results[1].got_source_addr = true;
115 results[1].source_addr_len = sizeof (so2);
116 results[1].source_addr_flags = 0;
117 results[1].service_order = 1;
118 results[1].prefixlen = 16;
119 results[1].index = 0;
120 memcpy (&results[1].source_addr, &so2, sizeof (so2));
123 struct sort_result_combo combo = { .results = results, .nresults = 2 };
124 qsort_r (results, 2, sizeof (results[0]), rfc3484_sort, &combo);
126 int result = 0;
127 if (results[0].dest_addr->ai_family == AF_INET6)
129 puts ("wrong order in first test");
130 result |= 1;
134 /* And again, this time with the reverse starting order. */
135 results[1].dest_addr = &ai1;
136 results[1].got_source_addr = true;
137 results[1].source_addr_len = sizeof (so1);
138 results[1].source_addr_flags = 0;
139 results[1].service_order = 1;
140 results[1].prefixlen = 16;
141 results[1].index = 0;
142 memcpy (&results[1].source_addr, &so1, sizeof (so1));
144 results[0].dest_addr = &ai2;
145 results[0].got_source_addr = true;
146 results[0].source_addr_len = sizeof (so2);
147 results[0].source_addr_flags = 0;
148 results[0].service_order = 0;
149 results[0].prefixlen = 16;
150 results[0].index = 0;
151 memcpy (&results[0].source_addr, &so2, sizeof (so2));
154 qsort_r (results, 2, sizeof (results[0]), rfc3484_sort, &combo);
156 if (results[0].dest_addr->ai_family == AF_INET6)
158 puts ("wrong order in second test");
159 result |= 1;
162 return result;
165 #define TEST_FUNCTION do_test ()
166 #include "../test-skeleton.c"