1 /* Parse /etc/hosts in multi mode with a trailing long line (bug 21915).
2 Copyright (C) 2017-2023 Free Software Foundation, Inc.
3 This file is part of the GNU C Library.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library; if not, see
17 <https://www.gnu.org/licenses/>. */
22 #include <gnu/lib-names.h>
25 #include <support/check.h>
26 #include <support/check_nss.h>
27 #include <support/namespace.h>
28 #include <support/test-driver.h>
29 #include <support/xunistd.h>
31 struct support_chroot
*chroot_env
;
33 #define X10 "XXXXXXXXXX"
34 #define X100 X10 X10 X10 X10 X10 X10 X10 X10 X10 X10
35 #define X1000 X100 X100 X100 X100 X100 X100 X100 X100 X100 X100
38 prepare (int argc
, char **argv
)
40 chroot_env
= support_chroot_create
41 ((struct support_chroot_configuration
)
45 "127.0.0.1 localhost localhost.localdomain\n"
46 "::1 localhost localhost.localdomain\n"
47 "192.0.2.1 example.com\n"
49 .host_conf
= "multi on\n",
56 support_become_root ();
57 if (!support_can_chroot ())
58 return EXIT_UNSUPPORTED
;
60 __nss_configure_lookup ("hosts", "files");
61 if (dlopen (LIBNSS_FILES_SO
, RTLD_LAZY
) == NULL
)
62 FAIL_EXIT1 ("could not load " LIBNSS_DNS_SO
": %s", dlerror ());
64 xchroot (chroot_env
->path_chroot
);
67 h_errno
= NETDB_INTERNAL
;
68 check_hostent ("gethostbyname example.com",
69 gethostbyname ("example.com"),
71 "address: 192.0.2.1\n");
73 h_errno
= NETDB_INTERNAL
;
74 check_hostent ("gethostbyname2 AF_INET example.com",
75 gethostbyname2 ("example.com", AF_INET
),
77 "address: 192.0.2.1\n");
79 struct addrinfo hints
=
81 .ai_family
= AF_UNSPEC
,
82 .ai_socktype
= SOCK_STREAM
,
83 .ai_protocol
= IPPROTO_TCP
,
86 h_errno
= NETDB_INTERNAL
;
88 int ret
= getaddrinfo ("example.com", "80", &hints
, &ai
);
89 check_addrinfo ("example.com AF_UNSPEC", ai
, ret
,
90 "address: STREAM/TCP 192.0.2.1 80\n");
94 hints
.ai_family
= AF_INET
;
96 h_errno
= NETDB_INTERNAL
;
97 ret
= getaddrinfo ("example.com", "80", &hints
, &ai
);
98 check_addrinfo ("example.com AF_INET", ai
, ret
,
99 "address: STREAM/TCP 192.0.2.1 80\n");
104 support_chroot_free (chroot_env
);
108 #define PREPARE prepare
109 #include <support/test-driver.c>