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
15 __check_pf (bool *p1
, bool *p2
, struct in6addrinfo
**in6ai
, size_t *in6ailen
)
24 __free_in6ai (struct in6addrinfo
*ai
)
30 __check_native (uint32_t a1_index
, int *a1_native
,
31 uint32_t a2_index
, int *a2_native
)
37 __idna_to_ascii_lz (const char *input
, char **output
, int flags
)
44 __idna_to_unicode_lzlz (const char *input
, char **output
, int flags
)
52 _res_hconf_init (void)
56 #include "../sysdeps/posix/getaddrinfo.c"
58 service_user
*__nss_hosts_database attribute_hidden
;
61 /* This is the beginning of the real test code. The above defines
62 (among other things) the function rfc3484_sort. */
65 #if __BYTE_ORDER == __BIG_ENDIAN
68 # define h(n) __bswap_constant_32 (n)
71 struct sockaddr_in addrs
[] =
73 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a86d1d) } },
74 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a85d03) } },
75 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a82c3d) } },
76 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a86002) } },
77 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a802f3) } },
78 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a80810) } },
79 { .sin_family
= AF_INET
, .sin_addr
= { h (0xc0a85e02) } }
81 #define naddrs (sizeof (addrs) / sizeof (addrs[0]))
82 static struct addrinfo ais
[naddrs
];
83 static struct sort_result results
[naddrs
];
84 static size_t order
[naddrs
];
86 static int expected
[naddrs
] =
93 __getline (char **lineptr
, size_t *n
, FILE *s
)
104 labels
= default_labels
;
105 precedence
= default_precedence
;
106 scopes
= default_scopes
;
108 struct sockaddr_in so
;
109 so
.sin_family
= AF_INET
;
110 so
.sin_addr
.s_addr
= h (0xc0a85f19);
111 /* Clear the rest of the structure to avoid warnings. */
112 memset (so
.sin_zero
, '\0', sizeof (so
.sin_zero
));
114 for (int i
= 0; i
< naddrs
; ++i
)
116 ais
[i
].ai_family
= AF_INET
;
117 ais
[i
].ai_addr
= (struct sockaddr
*) &addrs
[i
];
118 results
[i
].dest_addr
= &ais
[i
];
119 results
[i
].got_source_addr
= true;
120 memcpy(&results
[i
].source_addr
, &so
, sizeof (so
));
121 results
[i
].source_addr_len
= sizeof (so
);
122 results
[i
].source_addr_flags
= 0;
123 results
[i
].prefixlen
= 8;
124 results
[i
].index
= 0;
129 struct sort_result_combo combo
= { .results
= results
, .nresults
= naddrs
};
130 qsort_r (order
, naddrs
, sizeof (order
[0]), rfc3484_sort
, &combo
);
133 for (int i
= 0; i
< naddrs
; ++i
)
135 struct in_addr addr
= ((struct sockaddr_in
*) (results
[order
[i
]].dest_addr
->ai_addr
))->sin_addr
;
137 int here
= memcmp (&addr
, &addrs
[expected
[i
]].sin_addr
,
138 sizeof (struct in_addr
));
139 printf ("[%d] = %s: %s\n", i
, inet_ntoa (addr
), here
? "FAIL" : "OK");
146 #define TEST_FUNCTION do_test ()
147 #include "../test-skeleton.c"