1 /* Test NSS query path for plugins that only implement gethostbyname2
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
6 The GNU C Library is free software; you can redistribute it and/or
7 modify it under the terms of the GNU Lesser General Public
8 License as published by the Free Software Foundation; either
9 version 2.1 of the License, or (at your option) any later version.
11 The GNU C Library is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 Lesser General Public License for more details.
16 You should have received a copy of the GNU Lesser General Public
17 License along with the GNU C Library; if not, see
18 <https://www.gnu.org/licenses/>. */
24 #include <support/check.h>
25 #include <support/xstdio.h>
26 #include "nss/tst-nss-gai-hv2-canonname.h"
28 #define PREPARE do_prepare
30 static void do_prepare (int a
, char **av
)
32 FILE *hosts
= xfopen ("/etc/hosts", "w");
33 for (unsigned i
= 2; i
< 255; i
++)
35 fprintf (hosts
, "ff01::ff02:ff03:%u:2\ttest.example.com\n", i
);
36 fprintf (hosts
, "192.168.0.%u\ttest.example.com\n", i
);
44 __nss_configure_lookup ("hosts", "test_gai_hv2_canonname");
46 struct addrinfo hints
= {};
47 struct addrinfo
*result
= NULL
;
49 hints
.ai_family
= AF_INET6
;
50 hints
.ai_flags
= AI_ALL
| AI_V4MAPPED
| AI_CANONNAME
;
52 int ret
= getaddrinfo (QUERYNAME
, NULL
, &hints
, &result
);
55 FAIL_EXIT1 ("getaddrinfo failed: %s\n", gai_strerror (ret
));
57 TEST_COMPARE_STRING (result
->ai_canonname
, QUERYNAME
);
63 #include <support/test-driver.c>