[BZ #5040]
[glibc.git] / posix / tst-rfc3484-2.c
blobf318523ed58569864fd78006fd5b04d49dcb36df
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 int
22 __idna_to_ascii_lz (const char *input, char **output, int flags)
24 return 0;
26 int
27 __idna_to_unicode_lzlz (const char *input, char **output, int flags)
29 *output = NULL;
30 return 0;
33 #include "../sysdeps/posix/getaddrinfo.c"
35 service_user *__nss_hosts_database attribute_hidden;
38 /* This is the beginning of the real test code. The above defines
39 (among other things) the function rfc3484_sort. */
42 #if __BYTE_ORDER == __BIG_ENDIAN
43 # define h(n) n
44 #else
45 # define h(n) __bswap_constant_32 (n)
46 #endif
49 ssize_t
50 __getline (char **lineptr, size_t *n, FILE *s)
52 *lineptr = NULL;
53 *n = 0;
54 return 0;
58 static int
59 do_test (void)
61 labels = default_labels;
62 precedence = default_precedence;
64 struct sockaddr_in so1;
65 so1.sin_family = AF_INET;
66 so1.sin_addr.s_addr = h (0xc0a85f19);
68 struct sockaddr_in sa1;
69 sa1.sin_family = AF_INET;
70 sa1.sin_addr.s_addr = h (0xe0a85f19);
72 struct addrinfo ai1;
73 ai1.ai_family = AF_INET;
74 ai1.ai_addr = (struct sockaddr *) &sa1;
76 struct sockaddr_in6 so2;
77 so2.sin6_family = AF_INET6;
78 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
79 so2.sin6_addr.s6_addr32[1] = 1;
80 so2.sin6_addr.s6_addr32[2] = 1;
81 so2.sin6_addr.s6_addr32[3] = 1;
83 struct sockaddr_in6 sa2;
84 sa2.sin6_family = AF_INET6;
85 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
86 sa2.sin6_addr.s6_addr32[1] = 1;
87 sa2.sin6_addr.s6_addr32[2] = 1;
88 sa2.sin6_addr.s6_addr32[3] = 1;
90 struct addrinfo ai2;
91 ai2.ai_family = AF_INET6;
92 ai2.ai_addr = (struct sockaddr *) &sa2;
95 struct sort_result results[2];
97 results[0].dest_addr = &ai1;
98 results[0].got_source_addr = true;
99 results[0].source_addr_len = sizeof (so1);
100 results[0].source_addr_flags = 0;
101 results[0].service_order = 0;
102 memcpy (&results[0].source_addr, &so1, sizeof (so1));
104 results[1].dest_addr = &ai2;
105 results[1].got_source_addr = true;
106 results[1].source_addr_len = sizeof (so2);
107 results[1].source_addr_flags = 0;
108 results[1].service_order = 1;
109 memcpy (&results[1].source_addr, &so2, sizeof (so2));
112 qsort (results, 2, sizeof (results[0]), rfc3484_sort);
114 int result = 0;
115 if (results[0].dest_addr->ai_family == AF_INET6)
117 puts ("wrong order in first test");
118 result |= 1;
122 /* And again, this time with the reverse starting order. */
123 results[1].dest_addr = &ai1;
124 results[1].got_source_addr = true;
125 results[1].source_addr_len = sizeof (so1);
126 results[1].source_addr_flags = 0;
127 results[1].service_order = 1;
128 memcpy (&results[1].source_addr, &so1, sizeof (so1));
130 results[0].dest_addr = &ai2;
131 results[0].got_source_addr = true;
132 results[0].source_addr_len = sizeof (so2);
133 results[0].source_addr_flags = 0;
134 results[0].service_order = 0;
135 memcpy (&results[0].source_addr, &so2, sizeof (so2));
138 qsort (results, 2, sizeof (results[0]), rfc3484_sort);
140 if (results[0].dest_addr->ai_family == AF_INET6)
142 puts ("wrong order in second test");
143 result |= 1;
146 return result;
149 #define TEST_FUNCTION do_test ()
150 #include "../test-skeleton.c"