2005-09-26 21:17:54 +00:00
|
|
|
#include <stdbool.h>
|
|
|
|
#include <stdio.h>
|
2006-04-24 21:11:34 +00:00
|
|
|
#include <ifaddrs.h>
|
2013-05-01 15:46:34 +00:00
|
|
|
#include <stdint.h>
|
2005-09-26 21:17:54 +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
|
2014-11-12 22:33:41 +00:00
|
|
|
#define __qsort_r qsort_r
|
2021-02-03 18:36:47 +00:00
|
|
|
#define __stat64 stat64
|
2005-09-26 21:17:54 +00:00
|
|
|
|
|
|
|
void
|
|
|
|
attribute_hidden
|
2006-04-20 06:27:35 +00:00
|
|
|
__check_pf (bool *p1, bool *p2, struct in6addrinfo **in6ai, size_t *in6ailen)
|
2005-09-26 21:17:54 +00:00
|
|
|
{
|
|
|
|
*p1 = *p2 = true;
|
2006-04-20 06:27:35 +00:00
|
|
|
*in6ai = NULL;
|
|
|
|
*in6ailen = 0;
|
2005-09-26 21:17:54 +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
|
|
|
|
2005-09-26 21:17:54 +00:00
|
|
|
int
|
2008-05-15 03:06:50 +00:00
|
|
|
attribute_hidden
|
2005-09-26 21:17:54 +00:00
|
|
|
__idna_to_ascii_lz (const char *input, char **output, int flags)
|
|
|
|
{
|
|
|
|
return 0;
|
|
|
|
}
|
2008-05-15 03:06:50 +00:00
|
|
|
|
2005-09-26 21:17:54 +00:00
|
|
|
int
|
2008-05-15 03:06:50 +00:00
|
|
|
attribute_hidden
|
2005-09-26 21:17:54 +00:00
|
|
|
__idna_to_unicode_lzlz (const char *input, char **output, int flags)
|
|
|
|
{
|
2007-08-26 01:27:49 +00:00
|
|
|
*output = NULL;
|
2005-09-26 21:17:54 +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
|
2023-10-02 12:55:27 +00:00
|
|
|
#include "getaddrinfo.c"
|
2005-09-26 21:17:54 +00:00
|
|
|
|
2020-11-10 03:09:34 +00:00
|
|
|
nss_action_list __nss_hosts_database attribute_hidden;
|
2005-09-26 21:17:54 +00: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-28 16:15:05 +00: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-26 21:17:54 +00: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-10 20:00:52 +00:00
|
|
|
static size_t order[naddrs];
|
2005-09-26 21:17:54 +00:00
|
|
|
|
|
|
|
static int expected[naddrs] =
|
|
|
|
{
|
2012-09-28 16:15:05 +00:00
|
|
|
9, 4, 3, 6, 5, 7, 8, 2, 0, 1
|
2005-09-26 21:17:54 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
2006-05-04 06:38:07 +00:00
|
|
|
ssize_t
|
|
|
|
__getline (char **lineptr, size_t *n, FILE *s)
|
|
|
|
{
|
|
|
|
*lineptr = NULL;
|
|
|
|
*n = 0;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-09-26 21:17:54 +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
|
|
|
|
2005-09-26 21:17:54 +00:00
|
|
|
struct sockaddr_in so;
|
|
|
|
so.sin_family = AF_INET;
|
|
|
|
so.sin_addr.s_addr = h (0xc0a85f19);
|
2009-07-23 19:53:50 +00:00
|
|
|
/* Clear the rest of the structure to avoid warnings. */
|
|
|
|
memset (so.sin_zero, '\0', sizeof (so.sin_zero));
|
2005-09-26 21:17:54 +00: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-24 23:02:03 +00:00
|
|
|
results[i].source_addr_flags = 0;
|
2007-11-13 17:06:28 +00:00
|
|
|
results[i].prefixlen = 8;
|
2007-11-14 06:58:35 +00:00
|
|
|
results[i].index = 0;
|
2008-01-10 20:00:52 +00:00
|
|
|
|
|
|
|
order[i] = i;
|
2005-09-26 21:17:54 +00:00
|
|
|
}
|
|
|
|
|
2007-11-14 06:58:35 +00:00
|
|
|
struct sort_result_combo combo = { .results = results, .nresults = naddrs };
|
2008-01-10 20:00:52 +00:00
|
|
|
qsort_r (order, naddrs, sizeof (order[0]), rfc3484_sort, &combo);
|
2005-09-26 21:17:54 +00:00
|
|
|
|
|
|
|
int result = 0;
|
|
|
|
for (int i = 0; i < naddrs; ++i)
|
|
|
|
{
|
2008-01-10 20:00:52 +00:00
|
|
|
struct in_addr addr = ((struct sockaddr_in *) (results[order[i]].dest_addr->ai_addr))->sin_addr;
|
2005-09-26 21:17:54 +00: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"
|