4 /* Internal definitions used in the libc code. */
5 #define __getservbyname_r getservbyname_r
6 #define __socket socket
7 #define __getsockname getsockname
8 #define __inet_aton inet_aton
9 #define __gethostbyaddr_r gethostbyaddr_r
10 #define __gethostbyname2_r gethostbyname2_r
14 __check_pf (bool *p1
, bool *p2
)
19 __idna_to_ascii_lz (const char *input
, char **output
, int flags
)
24 __idna_to_unicode_lzlz (const char *input
, char **output
, int flags
)
29 #include "../sysdeps/posix/getaddrinfo.c"
31 service_user
*__nss_hosts_database attribute_hidden
;
34 /* This is the beginning of the real test code. The above defines
35 (among other things) the function rfc3484_sort. */
38 #if __BYTE_ORDER == __BIG_ENDIAN
41 # define h(n) __bswap_constant_32 (n)
44 struct sockaddr_in addrs
[] =
46 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a86d1d) } },
47 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a85d03) } },
48 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a82c3d) } },
49 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a86002) } },
50 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a802f3) } },
51 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a80810) } },
52 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a85e02) } }
54 #define naddrs (sizeof (addrs) / sizeof (addrs[0]))
55 static struct addrinfo ais
[naddrs
];
56 static struct sort_result results
[naddrs
];
58 static int expected
[naddrs
] =
67 struct sockaddr_in so
;
68 so
.sin_family
= AF_INET
;
69 so
.sin_addr
.s_addr
= h (0xc0a85f19);
71 for (int i
= 0; i
< naddrs
; ++i
)
73 ais
[i
].ai_family
= AF_INET
;
74 ais
[i
].ai_addr
= (struct sockaddr
*) &addrs
[i
];
75 results
[i
].dest_addr
= &ais
[i
];
76 results
[i
].got_source_addr
= true;
77 memcpy(&results
[i
].source_addr
, &so
, sizeof (so
));
78 results
[i
].source_addr_len
= sizeof (so
);
81 qsort (results
, naddrs
, sizeof (results
[0]), rfc3484_sort
);
84 for (int i
= 0; i
< naddrs
; ++i
)
86 struct in_addr addr
= ((struct sockaddr_in
*) (results
[i
].dest_addr
->ai_addr
))->sin_addr
;
88 int here
= memcmp (&addr
, &addrs
[expected
[i
]].sin_addr
,
89 sizeof (struct in_addr
));
90 printf ("[%d] = %s: %s\n", i
, inet_ntoa (addr
), here
? "FAIL" : "OK");
97 #define TEST_FUNCTION do_test ()
98 #include "../test-skeleton.c"