2005-09-27 05:17:54 +08:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2006-04-25 05:11:34 +08:00
|
|
|
#include <ifaddrs.h>
|
2013-05-01 23:46:34 +08:00
|
|
|
#include <stdint.h>
|
2005-09-27 05:17:54 +08: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
|
2014-11-13 06:33:41 +08:00
|
|
|
#define __qsort_r qsort_r
|
2021-02-04 02:36:47 +08:00
|
|
|
#define __stat64 stat64
|
2005-09-27 05:17:54 +08:00
|
|
|
|
|
|
|
void
|
|
|
|
attribute_hidden
|
2006-04-20 14:27:35 +08:00
|
|
|
__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
|
2005-09-27 05:17:54 +08:00
|
|
|
{
|
|
|
|
*p1 = *p2 = true;
|
2006-04-20 14:27:35 +08:00
|
|
|
*in6ai = NULL;
|
|
|
|
*in6ailen = 0;
|
2005-09-27 05:17:54 +08:00
|
|
|
}
|
2008-05-15 11:06:50 +08:00
|
|
|
|
2011-11-01 22:55:29 +08:00
|
|
|
void
|
|
|
|
attribute_hidden
|
|
|
|
__free_in6ai (struct in6addrinfo *ai)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2007-11-14 14:58:35 +08:00
|
|
|
void
|
|
|
|
attribute_hidden
|
|
|
|
__check_native (uint32_t a1_index, int *a1_native,
|
|
|
|
uint32_t a2_index, int *a2_native)
|
|
|
|
{
|
|
|
|
}
|
2008-05-15 11:06:50 +08:00
|
|
|
|
2005-09-27 05:17:54 +08:00
|
|
|
int
|
2008-05-15 11:06:50 +08:00
|
|
|
attribute_hidden
|
2005-09-27 05:17:54 +08:00
|
|
|
__idna_to_ascii_lz (const char *input, char **output, int flags)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-15 11:06:50 +08:00
|
|
|
|
2005-09-27 05:17:54 +08:00
|
|
|
int
|
2008-05-15 11:06:50 +08:00
|
|
|
attribute_hidden
|
2005-09-27 05:17:54 +08:00
|
|
|
__idna_to_unicode_lzlz (const char *input, char **output, int flags)
|
|
|
|
{
|
2007-08-26 09:27:49 +08:00
|
|
|
*output = NULL;
|
2005-09-27 05:17:54 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2008-05-15 11:06:50 +08:00
|
|
|
void
|
|
|
|
attribute_hidden
|
|
|
|
_res_hconf_init (void)
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
2012-08-24 07:55:40 +08:00
|
|
|
#undef USE_NSCD
|
2023-10-02 20:55:27 +08:00
|
|
|
#include "getaddrinfo.c"
|
2005-09-27 05:17:54 +08:00
|
|
|
|
2020-11-10 11:09:34 +08:00
|
|
|
nss_action_list __nss_hosts_database attribute_hidden;
|
2005-09-27 05:17:54 +08:00
|
|
|
|
|
|
|
/* 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
|
|
|
|
|
|
|
|
struct sockaddr_in addrs[] =
|
|
|
|
{
|
2012-09-29 00:15:05 +08:00
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0x0aa85f19) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xac105f19) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0000219) } },
|
2005-09-27 05:17:54 +08:00
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0a86d1d) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0a85d03) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0a82c3d) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0a86002) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0a802f3) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0a80810) } },
|
|
|
|
{ .sin_family = AF_INET, .sin_addr = { h (0xc0a85e02) } }
|
|
|
|
};
|
|
|
|
#define naddrs (sizeof (addrs) / sizeof (addrs[0]))
|
|
|
|
static struct addrinfo ais[naddrs];
|
|
|
|
static struct sort_result results[naddrs];
|
2008-01-11 04:00:52 +08:00
|
|
|
static size_t order[naddrs];
|
2005-09-27 05:17:54 +08:00
|
|
|
|
|
|
|
static int expected[naddrs] =
|
|
|
|
{
|
2012-09-29 00:15:05 +08:00
|
|
|
9, 4, 3, 6, 5, 7, 8, 2, 0, 1
|
2005-09-27 05:17:54 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-05-04 14:38:07 +08:00
|
|
|
ssize_t
|
|
|
|
__getline (char **lineptr, size_t *n, FILE *s)
|
|
|
|
{
|
|
|
|
*lineptr = NULL;
|
|
|
|
*n = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-27 05:17:54 +08:00
|
|
|
static int
|
|
|
|
do_test (void)
|
|
|
|
{
|
2006-05-04 14:38:07 +08:00
|
|
|
labels = default_labels;
|
|
|
|
precedence = default_precedence;
|
2007-11-20 08:41:22 +08:00
|
|
|
scopes= default_scopes;
|
2006-05-04 14:38:07 +08:00
|
|
|
|
2005-09-27 05:17:54 +08:00
|
|
|
struct sockaddr_in so;
|
|
|
|
so.sin_family = AF_INET;
|
|
|
|
so.sin_addr.s_addr = h (0xc0a85f19);
|
2009-07-24 03:53:50 +08:00
|
|
|
/* Clear the rest of the structure to avoid warnings. */
|
|
|
|
memset (so.sin_zero, '\0', sizeof (so.sin_zero));
|
2005-09-27 05:17:54 +08:00
|
|
|
|
|
|
|
for (int i = 0; i < naddrs; ++i)
|
|
|
|
{
|
|
|
|
ais[i].ai_family = AF_INET;
|
|
|
|
ais[i].ai_addr = (struct sockaddr *) &addrs[i];
|
|
|
|
results[i].dest_addr = &ais[i];
|
|
|
|
results[i].got_source_addr = true;
|
|
|
|
memcpy(&results[i].source_addr, &so, sizeof (so));
|
|
|
|
results[i].source_addr_len = sizeof (so);
|
2006-04-25 07:02:03 +08:00
|
|
|
results[i].source_addr_flags = 0;
|
2007-11-14 01:06:28 +08:00
|
|
|
results[i].prefixlen = 8;
|
2007-11-14 14:58:35 +08:00
|
|
|
results[i].index = 0;
|
2008-01-11 04:00:52 +08:00
|
|
|
|
|
|
|
order[i] = i;
|
2005-09-27 05:17:54 +08:00
|
|
|
}
|
|
|
|
|
2007-11-14 14:58:35 +08:00
|
|
|
struct sort_result_combo combo = { .results = results, .nresults = naddrs };
|
2008-01-11 04:00:52 +08:00
|
|
|
qsort_r (order, naddrs, sizeof (order[0]), rfc3484_sort, &combo);
|
2005-09-27 05:17:54 +08:00
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
for (int i = 0; i < naddrs; ++i)
|
|
|
|
{
|
2008-01-11 04:00:52 +08:00
|
|
|
struct in_addr addr = ((struct sockaddr_in *) (results[order[i]].dest_addr->ai_addr))->sin_addr;
|
2005-09-27 05:17:54 +08:00
|
|
|
|
|
|
|
int here = memcmp (&addr, &addrs[expected[i]].sin_addr,
|
|
|
|
sizeof (struct in_addr));
|
|
|
|
printf ("[%d] = %s: %s\n", i, inet_ntoa (addr), here ? "FAIL" : "OK");
|
|
|
|
result |= here;
|
|
|
|
}
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
#define TEST_FUNCTION do_test ()
|
|
|
|
#include "../test-skeleton.c"
|