.
[glibc/history.git] / posix / tst-rfc3484-2.c
blob2536da8f87b5065a2c2e442671291494add9406c
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 return 0;
32 #include "../sysdeps/posix/getaddrinfo.c"
34 service_user *__nss_hosts_database attribute_hidden;
37 /* This is the beginning of the real test code. The above defines
38 (among other things) the function rfc3484_sort. */
41 #if __BYTE_ORDER == __BIG_ENDIAN
42 # define h(n) n
43 #else
44 # define h(n) __bswap_constant_32 (n)
45 #endif
48 ssize_t
49 __getline (char **lineptr, size_t *n, FILE *s)
51 *lineptr = NULL;
52 *n = 0;
53 return 0;
57 static int
58 do_test (void)
60 labels = default_labels;
61 precedence = default_precedence;
63 struct sockaddr_in so1;
64 so1.sin_family = AF_INET;
65 so1.sin_addr.s_addr = h (0xc0a85f19);
67 struct sockaddr_in sa1;
68 sa1.sin_family = AF_INET;
69 sa1.sin_addr.s_addr = h (0xe0a85f19);
71 struct addrinfo ai1;
72 ai1.ai_family = AF_INET;
73 ai1.ai_addr = (struct sockaddr *) &sa1;
75 struct sockaddr_in6 so2;
76 so2.sin6_family = AF_INET6;
77 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
78 so2.sin6_addr.s6_addr32[1] = 1;
79 so2.sin6_addr.s6_addr32[2] = 1;
80 so2.sin6_addr.s6_addr32[3] = 1;
82 struct sockaddr_in6 sa2;
83 sa2.sin6_family = AF_INET6;
84 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
85 sa2.sin6_addr.s6_addr32[1] = 1;
86 sa2.sin6_addr.s6_addr32[2] = 1;
87 sa2.sin6_addr.s6_addr32[3] = 1;
89 struct addrinfo ai2;
90 ai2.ai_family = AF_INET6;
91 ai2.ai_addr = (struct sockaddr *) &sa2;
94 struct sort_result results[2];
96 results[0].dest_addr = &ai1;
97 results[0].got_source_addr = true;
98 results[0].source_addr_len = sizeof (so1);
99 results[0].source_addr_flags = 0;
100 memcpy (&results[0].source_addr, &so1, sizeof (so1));
102 results[1].dest_addr = &ai2;
103 results[1].got_source_addr = true;
104 results[1].source_addr_len = sizeof (so2);
105 results[1].source_addr_flags = 0;
106 memcpy (&results[1].source_addr, &so2, sizeof (so2));
109 qsort (results, 2, sizeof (results[0]), rfc3484_sort);
111 int result = 0;
112 if (results[0].dest_addr->ai_family == AF_INET6)
114 puts ("wrong order in first test");
115 result |= 1;
119 /* And again, this time with the reverse starting order. */
120 results[1].dest_addr = &ai1;
121 results[1].got_source_addr = true;
122 results[1].source_addr_len = sizeof (so1);
123 results[1].source_addr_flags = 0;
124 memcpy (&results[1].source_addr, &so1, sizeof (so1));
126 results[0].dest_addr = &ai2;
127 results[0].got_source_addr = true;
128 results[0].source_addr_len = sizeof (so2);
129 results[0].source_addr_flags = 0;
130 memcpy (&results[0].source_addr, &so2, sizeof (so2));
133 qsort (results, 2, sizeof (results[0]), rfc3484_sort);
135 if (results[0].dest_addr->ai_family == AF_INET6)
137 puts ("wrong order in second test");
138 result |= 1;
141 return result;
144 #define TEST_FUNCTION do_test ()
145 #include "../test-skeleton.c"