1 /* Test name resolution behavior with trailing characters.
2 Copyright (C) 2019-2021 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/>. */
19 #include <array_length.h>
21 #include <support/check.h>
22 #include <support/check_nss.h>
23 #include <support/resolv_test.h>
24 #include <support/support.h>
27 response (const struct resolv_response_context
*ctx
,
28 struct resolv_response_builder
*b
,
29 const char *qname
, uint16_t qclass
, uint16_t qtype
)
31 /* The tests are not supposed send any DNS queries. */
32 FAIL_EXIT1 ("unexpected DNS query for %s/%d/%d", qname
, qclass
, qtype
);
38 struct resolv_test
*aux
= resolv_test_start
39 ((struct resolv_redirect_config
)
41 .response_callback
= response
,
44 static const char *const queries
[] =
65 for (size_t query_idx
= 0; query_idx
< array_length (queries
); ++query_idx
)
67 const char *query
= queries
[query_idx
];
68 struct hostent storage
;
73 TEST_VERIFY (gethostbyname (query
) == NULL
);
74 TEST_COMPARE (h_errno
, HOST_NOT_FOUND
);
78 TEST_COMPARE (gethostbyname_r (query
, &storage
, buf
, sizeof (buf
),
80 TEST_VERIFY (e
== NULL
);
81 TEST_COMPARE (h_errno
, HOST_NOT_FOUND
);
84 TEST_VERIFY (gethostbyname2 (query
, AF_INET
) == NULL
);
85 TEST_COMPARE (h_errno
, HOST_NOT_FOUND
);
89 TEST_COMPARE (gethostbyname2_r (query
, AF_INET
,
90 &storage
, buf
, sizeof (buf
),
92 TEST_VERIFY (e
== NULL
);
93 TEST_COMPARE (h_errno
, HOST_NOT_FOUND
);
96 TEST_VERIFY (gethostbyname2 (query
, AF_INET6
) == NULL
);
97 TEST_COMPARE (h_errno
, HOST_NOT_FOUND
);
101 TEST_COMPARE (gethostbyname2_r (query
, AF_INET6
,
102 &storage
, buf
, sizeof (buf
),
104 TEST_VERIFY (e
== NULL
);
105 TEST_COMPARE (h_errno
, HOST_NOT_FOUND
);
107 static const int gai_flags
[] =
113 AI_IDN
| AI_NUMERICHOST
,
115 AI_V4MAPPED
| AI_NUMERICHOST
,
117 for (size_t gai_flags_idx
; gai_flags_idx
< array_length (gai_flags
);
120 struct addrinfo hints
= { .ai_flags
= gai_flags
[gai_flags_idx
], };
122 hints
.ai_family
= AF_INET
;
123 TEST_COMPARE (getaddrinfo (query
, "80", &hints
, &ai
), EAI_NONAME
);
124 hints
.ai_family
= AF_INET6
;
125 TEST_COMPARE (getaddrinfo (query
, "80", &hints
, &ai
), EAI_NONAME
);
126 hints
.ai_family
= AF_UNSPEC
;
127 TEST_COMPARE (getaddrinfo (query
, "80", &hints
, &ai
), EAI_NONAME
);
131 resolv_test_end (aux
);
136 #include <support/test-driver.c>