2006-04-15 21:43:13 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2006-04-24 21:11:34 +00:00
|
|
|
#include <ifaddrs.h>
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
/* Internal definitions used in the libc code. */
|
|
|
|
#define __getservbyname_r getservbyname_r
|
|
|
|
#define __socket socket
|
|
|
|
#define __getsockname getsockname
|
|
|
|
#define __inet_aton inet_aton
|
|
|
|
#define __gethostbyaddr_r gethostbyaddr_r
|
|
|
|
#define __gethostbyname2_r gethostbyname2_r
|
|
|
|
|
|
|
|
void
|
|
|
|
attribute_hidden
|
2006-04-20 06:27:35 +00:00
|
|
|
__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
|
2006-04-15 21:43:13 +00:00
|
|
|
{
|
|
|
|
*p1 = *p2 = true;
|
2006-04-20 06:27:35 +00:00
|
|
|
*in6ai = NULL;
|
|
|
|
*in6ailen = 0;
|
2006-04-15 21:43:13 +00:00
|
|
|
}
|
2008-05-15 03:06:50 +00:00
|
|
|
|
2011-11-01 14:55:29 +00:00
|
|
|
void
|
|
|
|
attribute_hidden
|
|
|
|
__free_in6ai (struct in6addrinfo *ai)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-14 06:58:35 +00:00
|
|
|
void
|
|
|
|
attribute_hidden
|
|
|
|
__check_native (uint32_t a1_index, int *a1_native,
|
|
|
|
uint32_t a2_index, int *a2_native)
|
|
|
|
{
|
|
|
|
}
|
2008-05-15 03:06:50 +00:00
|
|
|
|
2006-04-15 21:43:13 +00:00
|
|
|
int
|
2008-05-15 03:06:50 +00:00
|
|
|
attribute_hidden
|
2006-04-15 21:43:13 +00:00
|
|
|
__idna_to_ascii_lz (const char *input, char **output, int flags)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-15 03:06:50 +00:00
|
|
|
|
2006-04-15 21:43:13 +00:00
|
|
|
int
|
2008-05-15 03:06:50 +00:00
|
|
|
attribute_hidden
|
2006-04-15 21:43:13 +00:00
|
|
|
__idna_to_unicode_lzlz (const char *input, char **output, int flags)
|
|
|
|
{
|
2007-08-26 01:27:49 +00:00
|
|
|
*output = NULL;
|
2006-04-15 21:43:13 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-15 03:06:50 +00:00
|
|
|
void
|
|
|
|
attribute_hidden
|
|
|
|
_res_hconf_init (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-23 23:55:40 +00:00
|
|
|
#undef USE_NSCD
|
2006-04-15 21:43:13 +00:00
|
|
|
#include "../sysdeps/posix/getaddrinfo.c"
|
|
|
|
|
|
|
|
service_user *__nss_hosts_database attribute_hidden;
|
|
|
|
|
|
|
|
|
|
|
|
/* This is the beginning of the real test code. The above defines
|
|
|
|
(among other things) the function rfc3484_sort. */
|
|
|
|
|
|
|
|
|
|
|
|
#if __BYTE_ORDER == __BIG_ENDIAN
|
|
|
|
# define h(n) n
|
|
|
|
#else
|
|
|
|
# define h(n) __bswap_constant_32 (n)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
ssize_t
|
|
|
|
__getline (char **lineptr, size_t *n, FILE *s)
|
|
|
|
{
|
|
|
|
*lineptr = NULL;
|
|
|
|
*n = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2006-04-15 21:43:13 +00:00
|
|
|
static int
|
|
|
|
do_test (void)
|
|
|
|
{
|
2006-05-04 06:38:07 +00:00
|
|
|
labels = default_labels;
|
|
|
|
precedence = default_precedence;
|
2007-11-20 00:41:22 +00:00
|
|
|
scopes = default_scopes;
|
2006-05-04 06:38:07 +00:00
|
|
|
|
2006-04-15 21:43:13 +00:00
|
|
|
struct sockaddr_in so1;
|
|
|
|
so1.sin_family = AF_INET;
|
|
|
|
so1.sin_addr.s_addr = h (0xc0a85f19);
|
2009-07-23 19:53:50 +00:00
|
|
|
/* Clear the rest of the structure to avoid warnings. */
|
|
|
|
memset (so1.sin_zero, '\0', sizeof (so1.sin_zero));
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
struct sockaddr_in sa1;
|
|
|
|
sa1.sin_family = AF_INET;
|
|
|
|
sa1.sin_addr.s_addr = h (0xe0a85f19);
|
|
|
|
|
|
|
|
struct addrinfo ai1;
|
|
|
|
ai1.ai_family = AF_INET;
|
|
|
|
ai1.ai_addr = (struct sockaddr *) &sa1;
|
|
|
|
|
|
|
|
struct sockaddr_in6 so2;
|
|
|
|
so2.sin6_family = AF_INET6;
|
|
|
|
so2.sin6_addr.s6_addr32[0] = h (0xfec01234);
|
|
|
|
so2.sin6_addr.s6_addr32[1] = 1;
|
|
|
|
so2.sin6_addr.s6_addr32[2] = 1;
|
|
|
|
so2.sin6_addr.s6_addr32[3] = 1;
|
|
|
|
|
|
|
|
struct sockaddr_in6 sa2;
|
|
|
|
sa2.sin6_family = AF_INET6;
|
|
|
|
sa2.sin6_addr.s6_addr32[0] = h (0x07d10001);
|
|
|
|
sa2.sin6_addr.s6_addr32[1] = 1;
|
|
|
|
sa2.sin6_addr.s6_addr32[2] = 1;
|
|
|
|
sa2.sin6_addr.s6_addr32[3] = 1;
|
|
|
|
|
|
|
|
struct addrinfo ai2;
|
|
|
|
ai2.ai_family = AF_INET6;
|
|
|
|
ai2.ai_addr = (struct sockaddr *) &sa2;
|
|
|
|
|
|
|
|
|
|
|
|
struct sort_result results[2];
|
2008-01-10 20:00:52 +00:00
|
|
|
size_t order[2];
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
results[0].dest_addr = &ai1;
|
|
|
|
results[0].got_source_addr = true;
|
|
|
|
results[0].source_addr_len = sizeof (so1);
|
2006-04-24 23:02:03 +00:00
|
|
|
results[0].source_addr_flags = 0;
|
2007-11-13 17:06:28 +00:00
|
|
|
results[0].prefixlen = 16;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[0].index = 0;
|
2006-04-15 21:43:13 +00:00
|
|
|
memcpy (&results[0].source_addr, &so1, sizeof (so1));
|
2008-01-10 20:00:52 +00:00
|
|
|
order[0] = 0;
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
results[1].dest_addr = &ai2;
|
|
|
|
results[1].got_source_addr = true;
|
|
|
|
results[1].source_addr_len = sizeof (so2);
|
2006-04-24 23:02:03 +00:00
|
|
|
results[1].source_addr_flags = 0;
|
2007-11-13 17:06:28 +00:00
|
|
|
results[1].prefixlen = 16;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[1].index = 0;
|
2006-04-15 21:43:13 +00:00
|
|
|
memcpy (&results[1].source_addr, &so2, sizeof (so2));
|
2008-01-10 20:00:52 +00:00
|
|
|
order[1] = 1;
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
|
2007-11-14 06:58:35 +00:00
|
|
|
struct sort_result_combo combo = { .results = results, .nresults = 2 };
|
2008-01-10 20:00:52 +00:00
|
|
|
qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
int result = 0;
|
2008-01-10 20:00:52 +00:00
|
|
|
if (results[order[0]].dest_addr->ai_family == AF_INET6)
|
2006-04-15 21:43:13 +00:00
|
|
|
{
|
|
|
|
puts ("wrong order in first test");
|
|
|
|
result |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/* And again, this time with the reverse starting order. */
|
|
|
|
results[1].dest_addr = &ai1;
|
|
|
|
results[1].got_source_addr = true;
|
|
|
|
results[1].source_addr_len = sizeof (so1);
|
2006-04-24 23:02:03 +00:00
|
|
|
results[1].source_addr_flags = 0;
|
2007-11-13 17:06:28 +00:00
|
|
|
results[1].prefixlen = 16;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[1].index = 0;
|
2006-04-15 21:43:13 +00:00
|
|
|
memcpy (&results[1].source_addr, &so1, sizeof (so1));
|
2008-01-10 20:00:52 +00:00
|
|
|
order[1] = 1;
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
results[0].dest_addr = &ai2;
|
|
|
|
results[0].got_source_addr = true;
|
|
|
|
results[0].source_addr_len = sizeof (so2);
|
2006-04-24 23:02:03 +00:00
|
|
|
results[0].source_addr_flags = 0;
|
2007-11-13 17:06:28 +00:00
|
|
|
results[0].prefixlen = 16;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[0].index = 0;
|
2006-04-15 21:43:13 +00:00
|
|
|
memcpy (&results[0].source_addr, &so2, sizeof (so2));
|
2008-01-10 20:00:52 +00:00
|
|
|
order[0] = 0;
|
2006-04-15 21:43:13 +00:00
|
|
|
|
|
|
|
|
2008-01-10 20:00:52 +00:00
|
|
|
qsort_r (order, 2, sizeof (order[0]), rfc3484_sort, &combo);
|
2006-04-15 21:43:13 +00:00
|
|
|
|
2008-01-10 20:00:52 +00:00
|
|
|
if (results[order[0]].dest_addr->ai_family == AF_INET6)
|
2006-04-15 21:43:13 +00:00
|
|
|
{
|
|
|
|
puts ("wrong order in second test");
|
|
|
|
result |= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|