* posix/tst-rfc3484.c: Include <ifaddrs.h> early.
[glibc.git] / posix / tst-rfc3484-2.c
blob436ccf1e9c4043aa21891dcc4318ce57ade6ff93
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 static int
49 do_test (void)
51 struct sockaddr_in so1;
52 so1.sin_family = AF_INET;
53 so1.sin_addr.s_addr = h (0xc0a85f19);
55 struct sockaddr_in sa1;
56 sa1.sin_family = AF_INET;
57 sa1.sin_addr.s_addr = h (0xe0a85f19);
59 struct addrinfo ai1;
60 ai1.ai_family = AF_INET;
61 ai1.ai_addr = (struct sockaddr *) &sa1;
63 struct sockaddr_in6 so2;
64 so2.sin6_family = AF_INET6;
65 so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
66 so2.sin6_addr.s6_addr32[1] = 1;
67 so2.sin6_addr.s6_addr32[2] = 1;
68 so2.sin6_addr.s6_addr32[3] = 1;
70 struct sockaddr_in6 sa2;
71 sa2.sin6_family = AF_INET6;
72 sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
73 sa2.sin6_addr.s6_addr32[1] = 1;
74 sa2.sin6_addr.s6_addr32[2] = 1;
75 sa2.sin6_addr.s6_addr32[3] = 1;
77 struct addrinfo ai2;
78 ai2.ai_family = AF_INET6;
79 ai2.ai_addr = (struct sockaddr *) &sa2;
82 struct sort_result results[2];
84 results[0].dest_addr = &ai1;
85 results[0].got_source_addr = true;
86 results[0].source_addr_len = sizeof (so1);
87 memcpy (&results[0].source_addr, &so1, sizeof (so1));
89 results[1].dest_addr = &ai2;
90 results[1].got_source_addr = true;
91 results[1].source_addr_len = sizeof (so2);
92 memcpy (&results[1].source_addr, &so2, sizeof (so2));
95 qsort (results, 2, sizeof (results[0]), rfc3484_sort);
97 int result = 0;
98 if (results[0].dest_addr->ai_family == AF_INET6)
100 puts ("wrong order in first test");
101 result |= 1;
105 /* And again, this time with the reverse starting order. */
106 results[1].dest_addr = &ai1;
107 results[1].got_source_addr = true;
108 results[1].source_addr_len = sizeof (so1);
109 memcpy (&results[1].source_addr, &so1, sizeof (so1));
111 results[0].dest_addr = &ai2;
112 results[0].got_source_addr = true;
113 results[0].source_addr_len = sizeof (so2);
114 memcpy (&results[0].source_addr, &so2, sizeof (so2));
117 qsort (results, 2, sizeof (results[0]), rfc3484_sort);
119 if (results[0].dest_addr->ai_family == AF_INET6)
121 puts ("wrong order in second test");
122 result |= 1;
125 return result;
128 #define TEST_FUNCTION do_test ()
129 #include "../test-skeleton.c"