1/* Test NSS query path for plugins that only implement gethostbyname2
2 (#30843).
3 Copyright The GNU Toolchain Authors.
4 This file is part of the GNU C Library.
5
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.
10
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.
15
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/>. */
19
20#include <nss.h>
21#include <netdb.h>
22#include <stdlib.h>
23#include <string.h>
24#include <mcheck.h>
25#include <support/check.h>
26#include <support/xstdio.h>
27#include "nss/tst-nss-gai-hv2-canonname.h"
28
29#define PREPARE do_prepare
30
31static void do_prepare (int a, char **av)
32{
33 FILE *hosts = xfopen (path: "/etc/hosts", mode: "w");
34 for (unsigned i = 2; i < 255; i++)
35 {
36 fprintf (hosts, "ff01::ff02:ff03:%u:2\ttest.example.com\n", i);
37 fprintf (hosts, "192.168.0.%u\ttest.example.com\n", i);
38 }
39 xfclose (hosts);
40}
41
42static int
43do_test (void)
44{
45 mtrace ();
46
47 __nss_configure_lookup (dbname: "hosts", string: "test_gai_hv2_canonname");
48
49 struct addrinfo hints = {};
50 struct addrinfo *result = NULL;
51
52 hints.ai_family = AF_INET6;
53 hints.ai_flags = AI_ALL | AI_V4MAPPED | AI_CANONNAME;
54
55 int ret = getaddrinfo (QUERYNAME, NULL, &hints, &result);
56
57 if (ret != 0)
58 FAIL_EXIT1 ("getaddrinfo failed: %s\n", gai_strerror (ret));
59
60 TEST_COMPARE_STRING (result->ai_canonname, QUERYNAME);
61
62 freeaddrinfo(result);
63 return 0;
64}
65
66#include <support/test-driver.c>
67

source code of glibc/nss/tst-nss-gai-hv2-canonname.c