blob: f5da81f397a7d6199e95d0ccbfa828fb5184c0c9 [file] [log] [blame]
Bernie Innocenti55864192018-08-30 04:05:20 +09001/* $NetBSD: res_query.c,v 1.7 2006/01/24 17:41:25 christos Exp $ */
2
3/*
4 * Copyright (c) 1988, 1993
5 * The Regents of the University of California. All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 * 3. All advertising materials mentioning features or use of this software
16 * must display the following acknowledgement:
17 * This product includes software developed by the University of
18 * California, Berkeley and its contributors.
19 * 4. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
22 *
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
33 * SUCH DAMAGE.
34 */
35
36/*
37 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
38 *
39 * Permission to use, copy, modify, and distribute this software for any
40 * purpose with or without fee is hereby granted, provided that the above
41 * copyright notice and this permission notice appear in all copies, and that
42 * the name of Digital Equipment Corporation not be used in advertising or
43 * publicity pertaining to distribution of the document or software without
44 * specific, written prior permission.
45 *
46 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
47 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
48 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
49 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
50 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
51 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
52 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
53 * SOFTWARE.
54 */
55
56/*
57 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
58 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
59 *
60 * Permission to use, copy, modify, and distribute this software for any
61 * purpose with or without fee is hereby granted, provided that the above
62 * copyright notice and this permission notice appear in all copies.
63 *
64 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
65 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
66 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
67 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
68 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
69 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
70 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
71 */
72
Bernie Innocenti55864192018-08-30 04:05:20 +090073#include <arpa/inet.h>
74#include <arpa/nameser.h>
75#include <ctype.h>
76#include <errno.h>
77#include <netdb.h>
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090078#include <netinet/in.h>
79#include <sys/param.h>
80#include <sys/types.h>
Bernie Innocenti55864192018-08-30 04:05:20 +090081#include <stdio.h>
82#include <stdlib.h>
Bernie Innocenti55864192018-08-30 04:05:20 +090083#include <string.h>
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090084#include <unistd.h>
Bernie Innocenti55864192018-08-30 04:05:20 +090085
chenbruce16adee42019-02-20 19:45:50 +080086#include <android-base/logging.h>
87
Bernie Innocenti189eb502018-10-01 23:10:18 +090088#include "resolv_cache.h"
89#include "resolv_private.h"
90
Bernie Innocenti55864192018-08-30 04:05:20 +090091#if PACKETSZ > 1024
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090092#define MAXPACKET PACKETSZ
Bernie Innocenti55864192018-08-30 04:05:20 +090093#else
Bernie Innocentif12d5bb2018-08-31 14:09:46 +090094#define MAXPACKET 1024
Bernie Innocenti55864192018-08-30 04:05:20 +090095#endif
96
97/*
98 * Formulate a normal query, send, and await answer.
99 * Returned answer is placed in supplied buffer "answer".
100 * Perform preliminary check of answer, returning success only
101 * if no error is indicated and the answer count is nonzero.
102 * Return the size of the response on success, -1 on error.
Hungming Chen56273d72018-12-26 16:14:17 +0800103 * Error number is left in *herrno.
Bernie Innocenti55864192018-08-30 04:05:20 +0900104 *
105 * Caller must parse answer and determine whether it answers the question.
106 */
Mike Yu69615f62018-11-06 15:42:36 +0800107int res_nquery(res_state statp, const char* name, // domain name
108 int cl, int type, // class and type of query
109 u_char* answer, // buffer to put answer
110 int anslen, // size of answer buffer
Hungming Chen7f0d3292018-12-27 18:33:19 +0800111 int* herrno) // legacy and extended h_errno
112 // NETD_RESOLV_H_ERRNO_EXT_*
Bernie Innocenti55864192018-08-30 04:05:20 +0900113{
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900114 u_char buf[MAXPACKET];
115 HEADER* hp = (HEADER*) (void*) answer;
116 int n;
Mike Yu69615f62018-11-06 15:42:36 +0800117 int rcode = NOERROR;
Ken Chenbfd32022019-01-02 14:59:38 +0800118 bool retried = false;
Bernie Innocenti55864192018-08-30 04:05:20 +0900119
120again:
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900121 hp->rcode = NOERROR; /* default */
Bernie Innocenti55864192018-08-30 04:05:20 +0900122
chenbruce16adee42019-02-20 19:45:50 +0800123 LOG(DEBUG) << ";; res_query(" << name << ", " << cl << ", " << type;
Bernie Innocenti55864192018-08-30 04:05:20 +0900124
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900125 n = res_nmkquery(statp, QUERY, name, cl, type, NULL, 0, NULL, buf, sizeof(buf));
Ken Chenbfd32022019-01-02 14:59:38 +0800126 if (n > 0 && (statp->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0U && !retried)
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900127 n = res_nopt(statp, n, buf, sizeof(buf), anslen);
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900128 if (n <= 0) {
chenbruce16adee42019-02-20 19:45:50 +0800129 LOG(DEBUG) << ";; res_query: mkquery failed";
Hungming Chen56273d72018-12-26 16:14:17 +0800130 *herrno = NO_RECOVERY;
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900131 return n;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900132 }
Luke Huang952d0942018-12-26 16:53:03 +0800133 n = res_nsend(statp, buf, n, answer, anslen, &rcode, 0);
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900134 if (n < 0) {
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900135 /* if the query choked with EDNS0, retry without EDNS0 */
136 if ((statp->options & (RES_USE_EDNS0 | RES_USE_DNSSEC)) != 0U &&
Ken Chenbfd32022019-01-02 14:59:38 +0800137 (statp->_flags & RES_F_EDNS0ERR) && !retried) {
chenbruce16adee42019-02-20 19:45:50 +0800138 LOG(DEBUG) << ";; res_nquery: retry without EDNS0";
Ken Chenbfd32022019-01-02 14:59:38 +0800139 retried = true;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900140 goto again;
141 }
chenbruce16adee42019-02-20 19:45:50 +0800142 LOG(DEBUG) << ";; res_query: send error";
143
Hungming Chen7f0d3292018-12-27 18:33:19 +0800144 // Note that rcodes SERVFAIL, NOTIMP, REFUSED may cause res_nquery() to return a general
145 // error code EAI_AGAIN, but mapping the error code from rcode as res_queryN() does for
146 // getaddrinfo(). Different rcodes trigger different behaviors:
147 //
148 // - SERVFAIL, NOTIMP, REFUSED
149 // These result in send_dg() returning 0, causing res_nsend() to try the next
150 // nameserver. After all nameservers failed, res_nsend() returns -ETIMEDOUT, causing
151 // res_nquery() to return EAI_AGAIN here regardless of the rcode from the DNS response.
152 //
153 // - NXDOMAIN, FORMERR
154 // These rcodes may cause res_nsend() to return successfully (i.e. the result is a
155 // positive integer). In this case, res_nquery() returns error number by referring
156 // the rcode from the DNS response.
157 switch (rcode) {
158 case RCODE_TIMEOUT: // Not defined in RFC.
159 // DNS metrics monitors DNS query timeout.
160 *herrno = NETD_RESOLV_H_ERRNO_EXT_TIMEOUT; // extended h_errno.
161 break;
162 default:
163 *herrno = TRY_AGAIN;
164 break;
165 }
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900166 return n;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900167 }
Bernie Innocenti55864192018-08-30 04:05:20 +0900168
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900169 if (hp->rcode != NOERROR || ntohs(hp->ancount) == 0) {
chenbruce16adee42019-02-20 19:45:50 +0800170 LOG(DEBUG) << ";; rcode = (" << p_rcode(hp->rcode)
171 << "), counts = an:" << ntohs(hp->ancount) << " ns:" << ntohs(hp->nscount)
172 << " ar:" << ntohs(hp->arcount);
173
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900174 switch (hp->rcode) {
175 case NXDOMAIN:
Hungming Chen56273d72018-12-26 16:14:17 +0800176 *herrno = HOST_NOT_FOUND;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900177 break;
178 case SERVFAIL:
Hungming Chen56273d72018-12-26 16:14:17 +0800179 *herrno = TRY_AGAIN;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900180 break;
181 case NOERROR:
Hungming Chen56273d72018-12-26 16:14:17 +0800182 *herrno = NO_DATA;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900183 break;
184 case FORMERR:
185 case NOTIMP:
186 case REFUSED:
187 default:
Hungming Chen56273d72018-12-26 16:14:17 +0800188 *herrno = NO_RECOVERY;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900189 break;
190 }
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900191 return -1;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900192 }
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900193 return n;
Bernie Innocenti55864192018-08-30 04:05:20 +0900194}
195
196/*
197 * Formulate a normal query, send, and retrieve answer in supplied buffer.
198 * Return the size of the response on success, -1 on error.
199 * If enabled, implement search rules until answer or unrecoverable failure
Hungming Chen56273d72018-12-26 16:14:17 +0800200 * is detected. Error code, if any, is left in *herrno.
Bernie Innocenti55864192018-08-30 04:05:20 +0900201 */
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900202int res_nsearch(res_state statp, const char* name, /* domain name */
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900203 int cl, int type, /* class and type of query */
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900204 u_char* answer, /* buffer to put answer */
Mike Yu69615f62018-11-06 15:42:36 +0800205 int anslen, /* size of answer */
Hungming Chen7f0d3292018-12-27 18:33:19 +0800206 int* herrno) /* legacy and extended
207 h_errno NETD_RESOLV_H_ERRNO_EXT_* */
Bernie Innocenti55864192018-08-30 04:05:20 +0900208{
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900209 const char *cp, *const *domain;
210 HEADER* hp = (HEADER*) (void*) answer;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900211 u_int dots;
212 int trailing_dot, ret, saved_herrno;
213 int got_nodata = 0, got_servfail = 0, root_on_list = 0;
214 int tried_as_is = 0;
215 int searched = 0;
Bernie Innocenti55864192018-08-30 04:05:20 +0900216
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900217 errno = 0;
Hungming Chen56273d72018-12-26 16:14:17 +0800218 *herrno = HOST_NOT_FOUND; /* True if we never query. */
Bernie Innocenti55864192018-08-30 04:05:20 +0900219
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900220 dots = 0;
221 for (cp = name; *cp != '\0'; cp++) dots += (*cp == '.');
222 trailing_dot = 0;
223 if (cp > name && *--cp == '.') trailing_dot++;
Bernie Innocenti55864192018-08-30 04:05:20 +0900224
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900225 /*
226 * If there are enough dots in the name, let's just give it a
227 * try 'as is'. The threshold can be set with the "ndots" option.
228 * Also, query 'as is', if there is a trailing dot in the name.
229 */
230 saved_herrno = -1;
231 if (dots >= statp->ndots || trailing_dot) {
Hungming Chen7f0d3292018-12-27 18:33:19 +0800232 ret = res_nquerydomain(statp, name, NULL, cl, type, answer, anslen, herrno);
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900233 if (ret > 0 || trailing_dot) return ret;
Hungming Chen56273d72018-12-26 16:14:17 +0800234 saved_herrno = *herrno;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900235 tried_as_is++;
236 }
Bernie Innocenti55864192018-08-30 04:05:20 +0900237
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900238 /*
239 * We do at least one level of search if
240 * - there is no dot and RES_DEFNAME is set, or
241 * - there is at least one dot, there is no trailing dot,
242 * and RES_DNSRCH is set.
243 */
244 if ((!dots && (statp->options & RES_DEFNAMES) != 0U) ||
245 (dots && !trailing_dot && (statp->options & RES_DNSRCH) != 0U)) {
246 int done = 0;
Bernie Innocenti55864192018-08-30 04:05:20 +0900247
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900248 /* Unfortunately we need to load network-specific info
249 * (dns servers, search domains) before
250 * the domain stuff is tried. Will have a better
251 * fix after thread pools are used as this will
252 * be loaded once for the thread instead of each
253 * time a query is tried.
254 */
255 _resolv_populate_res_for_net(statp);
Bernie Innocenti55864192018-08-30 04:05:20 +0900256
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900257 for (domain = (const char* const*) statp->dnsrch; *domain && !done; domain++) {
258 searched = 1;
Bernie Innocenti55864192018-08-30 04:05:20 +0900259
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900260 if (domain[0][0] == '\0' || (domain[0][0] == '.' && domain[0][1] == '\0'))
261 root_on_list++;
Bernie Innocenti55864192018-08-30 04:05:20 +0900262
Hungming Chen7f0d3292018-12-27 18:33:19 +0800263 ret = res_nquerydomain(statp, name, *domain, cl, type, answer, anslen, herrno);
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900264 if (ret > 0) return ret;
Bernie Innocenti55864192018-08-30 04:05:20 +0900265
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900266 /*
267 * If no server present, give up.
268 * If name isn't found in this domain,
269 * keep trying higher domains in the search list
270 * (if that's enabled).
271 * On a NO_DATA error, keep trying, otherwise
272 * a wildcard entry of another type could keep us
273 * from finding this entry higher in the domain.
274 * If we get some other error (negative answer or
275 * server failure), then stop searching up,
276 * but try the input name below in case it's
277 * fully-qualified.
278 */
279 if (errno == ECONNREFUSED) {
Hungming Chen56273d72018-12-26 16:14:17 +0800280 *herrno = TRY_AGAIN;
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900281 return -1;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900282 }
Bernie Innocenti55864192018-08-30 04:05:20 +0900283
Hungming Chen56273d72018-12-26 16:14:17 +0800284 switch (*herrno) {
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900285 case NO_DATA:
286 got_nodata++;
Bernie Innocenti11cd0202018-10-12 21:27:45 +0900287 break;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900288 case HOST_NOT_FOUND:
289 /* keep trying */
290 break;
291 case TRY_AGAIN:
292 if (hp->rcode == SERVFAIL) {
293 /* try next search element, if any */
294 got_servfail++;
295 break;
296 }
Bernie Innocenti8bb94ba2018-10-10 22:30:12 +0900297 [[fallthrough]];
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900298 default:
299 /* anything else implies that we're done */
300 done++;
301 }
Bernie Innocenti55864192018-08-30 04:05:20 +0900302
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900303 /* if we got here for some reason other than DNSRCH,
304 * we only wanted one iteration of the loop, so stop.
305 */
306 if ((statp->options & RES_DNSRCH) == 0U) done++;
307 }
308 }
Bernie Innocenti55864192018-08-30 04:05:20 +0900309
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900310 /*
311 * If the query has not already been tried as is then try it
312 * unless RES_NOTLDQUERY is set and there were no dots.
313 */
314 if ((dots || !searched || (statp->options & RES_NOTLDQUERY) == 0U) &&
315 !(tried_as_is || root_on_list)) {
Hungming Chen7f0d3292018-12-27 18:33:19 +0800316 ret = res_nquerydomain(statp, name, NULL, cl, type, answer, anslen, herrno);
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900317 if (ret > 0) return ret;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900318 }
Bernie Innocenti55864192018-08-30 04:05:20 +0900319
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900320 /* if we got here, we didn't satisfy the search.
321 * if we did an initial full query, return that query's H_ERRNO
322 * (note that we wouldn't be here if that query had succeeded).
323 * else if we ever got a nodata, send that back as the reason.
324 * else send back meaningless H_ERRNO, that being the one from
325 * the last DNSRCH we did.
326 */
327 if (saved_herrno != -1)
Hungming Chen56273d72018-12-26 16:14:17 +0800328 *herrno = saved_herrno;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900329 else if (got_nodata)
Hungming Chen56273d72018-12-26 16:14:17 +0800330 *herrno = NO_DATA;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900331 else if (got_servfail)
Hungming Chen56273d72018-12-26 16:14:17 +0800332 *herrno = TRY_AGAIN;
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900333 return -1;
Bernie Innocenti55864192018-08-30 04:05:20 +0900334}
335
336/*
337 * Perform a call on res_query on the concatenation of name and domain,
338 * removing a trailing dot from name if domain is NULL.
339 */
Mike Yu69615f62018-11-06 15:42:36 +0800340int res_nquerydomain(res_state statp, const char* name, const char* domain, int cl,
341 int type, /* class and type of query */
342 u_char* answer, /* buffer to put answer */
343 int anslen, /* size of answer */
Hungming Chen7f0d3292018-12-27 18:33:19 +0800344 int* herrno) /* legacy and extended h_errno NETD_RESOLV_H_ERRNO_EXT_* */
Bernie Innocenti55864192018-08-30 04:05:20 +0900345{
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900346 char nbuf[MAXDNAME];
347 const char* longname = nbuf;
348 int n, d;
Bernie Innocenti55864192018-08-30 04:05:20 +0900349
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900350 if (domain == NULL) {
chenbruce16adee42019-02-20 19:45:50 +0800351 LOG(DEBUG) << ";; res_nquerydomain(" << name << ", <Nil>, " << cl << ", " << type << ")";
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900352 /*
353 * Check for trailing '.';
354 * copy without '.' if present.
355 */
356 n = strlen(name);
357 if (n >= MAXDNAME) {
Hungming Chen56273d72018-12-26 16:14:17 +0800358 *herrno = NO_RECOVERY;
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900359 return -1;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900360 }
361 n--;
362 if (n >= 0 && name[n] == '.') {
363 strncpy(nbuf, name, (size_t) n);
364 nbuf[n] = '\0';
365 } else
366 longname = name;
367 } else {
chenbruce16adee42019-02-20 19:45:50 +0800368 LOG(DEBUG) << ";; res_nquerydomain(" << name << ", " << domain << ", " << cl << ", " << type
369 << ")";
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900370 n = strlen(name);
371 d = strlen(domain);
372 if (n + d + 1 >= MAXDNAME) {
Hungming Chen56273d72018-12-26 16:14:17 +0800373 *herrno = NO_RECOVERY;
Bernie Innocenti1f4a9fd2018-09-07 21:10:25 +0900374 return -1;
Bernie Innocentif12d5bb2018-08-31 14:09:46 +0900375 }
376 snprintf(nbuf, sizeof(nbuf), "%s.%s", name, domain);
377 }
Hungming Chen7f0d3292018-12-27 18:33:19 +0800378 return res_nquery(statp, longname, cl, type, answer, anslen, herrno);
Bernie Innocenti55864192018-08-30 04:05:20 +0900379}