32bit memcmp/strcmp/strncmp optimized for SSSE3/SSS4.2
[glibc.git] / posix / tst-rfc3484.c
blob26835cf8b234e5985ed33c02a54be20025b12996
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;
22 void
23 attribute_hidden
24 __check_native (uint32_t a1_index, int *a1_native,
25 uint32_t a2_index, int *a2_native)
29 int
30 attribute_hidden
31 __idna_to_ascii_lz (const char *input, char **output, int flags)
33 return 0;
36 int
37 attribute_hidden
38 __idna_to_unicode_lzlz (const char *input, char **output, int flags)
40 *output = NULL;
41 return 0;
44 void
45 attribute_hidden
46 _res_hconf_init (void)
50 #include "../sysdeps/posix/getaddrinfo.c"
52 service_user *__nss_hosts_database attribute_hidden;
55 /* This is the beginning of the real test code. The above defines
56 (among other things) the function rfc3484_sort. */
59 #if __BYTE_ORDER == __BIG_ENDIAN
60 # define h(n) n
61 #else
62 # define h(n) __bswap_constant_32 (n)
63 #endif
65 struct sockaddr_in addrs[] =
67 { .sin_family = AF_INET, .sin_addr = { h (0xc0a86d1d) } },
68 { .sin_family = AF_INET, .sin_addr = { h (0xc0a85d03) } },
69 { .sin_family = AF_INET, .sin_addr = { h (0xc0a82c3d) } },
70 { .sin_family = AF_INET, .sin_addr = { h (0xc0a86002) } },
71 { .sin_family = AF_INET, .sin_addr = { h (0xc0a802f3) } },
72 { .sin_family = AF_INET, .sin_addr = { h (0xc0a80810) } },
73 { .sin_family = AF_INET, .sin_addr = { h (0xc0a85e02) } }
75 #define naddrs (sizeof (addrs) / sizeof (addrs[0]))
76 static struct addrinfo ais[naddrs];
77 static struct sort_result results[naddrs];
78 static size_t order[naddrs];
80 static int expected[naddrs] =
82 6, 1, 0, 3, 2, 4, 5
86 ssize_t
87 __getline (char **lineptr, size_t *n, FILE *s)
89 *lineptr = NULL;
90 *n = 0;
91 return 0;
95 static int
96 do_test (void)
98 labels = default_labels;
99 precedence = default_precedence;
100 scopes= default_scopes;
102 struct sockaddr_in so;
103 so.sin_family = AF_INET;
104 so.sin_addr.s_addr = h (0xc0a85f19);
105 /* Clear the rest of the structure to avoid warnings. */
106 memset (so.sin_zero, '\0', sizeof (so.sin_zero));
108 for (int i = 0; i < naddrs; ++i)
110 ais[i].ai_family = AF_INET;
111 ais[i].ai_addr = (struct sockaddr *) &addrs[i];
112 results[i].dest_addr = &ais[i];
113 results[i].got_source_addr = true;
114 memcpy(&results[i].source_addr, &so, sizeof (so));
115 results[i].source_addr_len = sizeof (so);
116 results[i].source_addr_flags = 0;
117 results[i].prefixlen = 8;
118 results[i].index = 0;
120 order[i] = i;
123 struct sort_result_combo combo = { .results = results, .nresults = naddrs };
124 qsort_r (order, naddrs, sizeof (order[0]), rfc3484_sort, &combo);
126 int result = 0;
127 for (int i = 0; i < naddrs; ++i)
129 struct in_addr addr = ((struct sockaddr_in *) (results[order[i]].dest_addr->ai_addr))->sin_addr;
131 int here = memcmp (&addr, &addrs[expected[i]].sin_addr,
132 sizeof (struct in_addr));
133 printf ("[%d] = %s: %s\n", i, inet_ntoa (addr), here ? "FAIL" : "OK");
134 result |= here;
137 return result;
140 #define TEST_FUNCTION do_test ()
141 #include "../test-skeleton.c"