blob: 679cb74a0f6bb4e9c8a01420f53b4104b4f42c01 [file] [log] [blame]
Bernie Innocenti318ed2d2018-08-30 04:05:20 +09001/* $NetBSD: gethnamaddr.c,v 1.91 2014/06/19 15:08:18 christos Exp $ */
2
3/*
4 * ++Copyright++ 1985, 1988, 1993
5 * -
6 * Copyright (c) 1985, 1988, 1993
7 * The Regents of the University of California. All rights reserved.
8 *
9 * Redistribution and use in source and binary forms, with or without
10 * modification, are permitted provided that the following conditions
11 * are met:
12 * 1. Redistributions of source code must retain the above copyright
13 * notice, this list of conditions and the following disclaimer.
14 * 2. Redistributions in binary form must reproduce the above copyright
15 * notice, this list of conditions and the following disclaimer in the
16 * documentation and/or other materials provided with the distribution.
17 * 3. Neither the name of the University nor the names of its contributors
18 * may be used to endorse or promote products derived from this software
19 * without specific prior written permission.
20 *
21 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
22 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
23 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
24 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
25 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 * -
33 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
34 *
35 * Permission to use, copy, modify, and distribute this software for any
36 * purpose with or without fee is hereby granted, provided that the above
37 * copyright notice and this permission notice appear in all copies, and that
38 * the name of Digital Equipment Corporation not be used in advertising or
39 * publicity pertaining to distribution of the document or software without
40 * specific, written prior permission.
41 *
42 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
43 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
44 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
45 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
46 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
47 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
48 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
49 * SOFTWARE.
50 * -
51 * --Copyright--
52 */
53
Bernie Innocentie71a28a2019-05-29 00:42:35 +090054#include "gethnamaddr.h"
55
chenbruceacb832c2019-02-20 19:45:50 +080056#include <android-base/logging.h>
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090057#include <arpa/inet.h>
58#include <arpa/nameser.h>
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090059#include <assert.h>
60#include <ctype.h>
61#include <errno.h>
62#include <netdb.h>
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090063#include <netinet/in.h>
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090064#include <stdarg.h>
65#include <stdbool.h>
Bernie Innocentie2bc46f2018-10-16 23:35:28 +090066#include <stdlib.h>
67#include <string.h>
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090068#include <sys/param.h>
69#include <sys/socket.h>
70#include <sys/un.h>
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090071#include <unistd.h>
nuccachen9227b7f2018-09-18 13:38:48 +080072#include <functional>
lifrbe7dfbf2019-01-09 14:41:15 +080073#include <vector>
Bernie Innocentiafaacf72018-08-30 07:34:37 +090074
Bernie Innocentie2bc46f2018-10-16 23:35:28 +090075#include "hostent.h"
Bernie Innocentiac18b122018-10-01 23:10:18 +090076#include "netd_resolv/resolv.h"
Bernie Innocenti10a90282020-01-23 23:28:00 +090077#include "res_comp.h"
78#include "res_debug.h" // p_class(), p_type()
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090079#include "resolv_cache.h"
Luke Huang1b3f4462020-12-04 17:48:39 +080080#include "resolv_private.h"
lifr94981782019-05-17 21:15:19 +080081#include "stats.pb.h"
82
83using android::net::NetworkDnsEventReported;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090084
Bernie Innocentibf0b3bc2019-10-11 19:45:56 +090085constexpr int MAXADDRS = 35;
86
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090087typedef union {
88 HEADER hdr;
chenbrucec51f1212019-09-12 16:59:33 +080089 uint8_t buf[MAXPACKET];
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090090} querybuf;
91
nuccachen9227b7f2018-09-18 13:38:48 +080092static void pad_v4v6_hostent(struct hostent* hp, char** bpp, char* ep);
waynema067e9842019-03-08 19:13:41 +080093static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
lifr94981782019-05-17 21:15:19 +080094 const android_net_context* netcontext, getnamaddr* info,
95 NetworkDnsEventReported* event);
Bernie Innocenti08487112019-10-11 21:14:13 +090096static int dns_gethtbyname(ResState* res, const char* name, int af, getnamaddr* info);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +090097
Bernie Innocenti8ad893f2018-08-31 14:09:46 +090098#define BOUNDED_INCR(x) \
99 do { \
100 BOUNDS_CHECK(cp, x); \
101 cp += (x); \
Bernie Innocenti9c575932018-09-07 21:10:25 +0900102 } while (0)
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900103
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900104#define BOUNDS_CHECK(ptr, count) \
105 do { \
106 if (eom - (ptr) < (count)) goto no_recovery; \
Bernie Innocenti9c575932018-09-07 21:10:25 +0900107 } while (0)
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900108
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900109static struct hostent* getanswer(const querybuf* _Nonnull answer, int anslen,
110 const char* _Nonnull qname, int qtype, struct hostent* hent,
111 char* buf, size_t buflen, int* he) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900112 const HEADER* hp;
chenbrucec51f1212019-09-12 16:59:33 +0800113 const uint8_t* cp;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900114 int n;
115 size_t qlen;
chenbrucec51f1212019-09-12 16:59:33 +0800116 const uint8_t *eom, *erdata;
lifrbe7dfbf2019-01-09 14:41:15 +0800117 char *bp, **hap, *ep;
Bernie Innocenti9c575932018-09-07 21:10:25 +0900118 int ancount, qdcount;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900119 int haveanswer, had_error;
120 int toobig = 0;
121 char tbuf[MAXDNAME];
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900122 char* addr_ptrs[MAXADDRS];
123 const char* tname;
lifrbe7dfbf2019-01-09 14:41:15 +0800124 std::vector<char*> aliases;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900125
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900126 tname = qname;
127 hent->h_name = NULL;
128 eom = answer->buf + anslen;
Bernie Innocenti10a90282020-01-23 23:28:00 +0900129
130 bool (*name_ok)(const char* dn);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900131 switch (qtype) {
132 case T_A:
133 case T_AAAA:
134 name_ok = res_hnok;
135 break;
136 case T_PTR:
137 name_ok = res_dnok;
138 break;
139 default:
140 *he = NO_RECOVERY;
141 return NULL; /* XXX should be abort(); */
142 }
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900143
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900144 /*
145 * find first satisfactory answer
146 */
147 hp = &answer->hdr;
148 ancount = ntohs(hp->ancount);
149 qdcount = ntohs(hp->qdcount);
150 bp = buf;
151 ep = buf + buflen;
152 cp = answer->buf;
153 BOUNDED_INCR(HFIXEDSZ);
154 if (qdcount != 1) goto no_recovery;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900155
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900156 n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp));
Bernie Innocenti10a90282020-01-23 23:28:00 +0900157 if ((n < 0) || !name_ok(bp)) goto no_recovery;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900158
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900159 BOUNDED_INCR(n + QFIXEDSZ);
160 if (qtype == T_A || qtype == T_AAAA) {
161 /* res_send() has already verified that the query name is the
162 * same as the one we sent; this just gets the expanded name
163 * (i.e., with the succeeding search-domain tacked on).
164 */
165 n = (int) strlen(bp) + 1; /* for the \0 */
166 if (n >= MAXHOSTNAMELEN) goto no_recovery;
167 hent->h_name = bp;
168 bp += n;
169 /* The qname can be abbreviated, but h_name is now absolute. */
170 qname = hent->h_name;
171 }
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900172 hent->h_addr_list = hap = addr_ptrs;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900173 *hap = NULL;
174 haveanswer = 0;
175 had_error = 0;
176 while (ancount-- > 0 && cp < eom && !had_error) {
177 n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp));
Bernie Innocenti10a90282020-01-23 23:28:00 +0900178 if ((n < 0) || !name_ok(bp)) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900179 had_error++;
180 continue;
181 }
182 cp += n; /* name */
183 BOUNDS_CHECK(cp, 3 * INT16SZ + INT32SZ);
chenbruce0d470422019-03-28 18:44:37 +0800184 int type = ntohs(*reinterpret_cast<const uint16_t*>(cp));
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900185 cp += INT16SZ; /* type */
chenbruce0d470422019-03-28 18:44:37 +0800186 int cl = ntohs(*reinterpret_cast<const uint16_t*>(cp));
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900187 cp += INT16SZ + INT32SZ; /* class, TTL */
chenbruce0d470422019-03-28 18:44:37 +0800188 n = ntohs(*reinterpret_cast<const uint16_t*>(cp));
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900189 cp += INT16SZ; /* len */
190 BOUNDS_CHECK(cp, n);
191 erdata = cp + n;
Bernie Innocenti9c575932018-09-07 21:10:25 +0900192 if (cl != C_IN) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900193 /* XXX - debug? syslog? */
194 cp += n;
195 continue; /* XXX - had_error++ ? */
196 }
197 if ((qtype == T_A || qtype == T_AAAA) && type == T_CNAME) {
198 n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf);
Bernie Innocenti10a90282020-01-23 23:28:00 +0900199 if ((n < 0) || !name_ok(tbuf)) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900200 had_error++;
201 continue;
202 }
203 cp += n;
204 if (cp != erdata) goto no_recovery;
205 /* Store alias. */
lifrbe7dfbf2019-01-09 14:41:15 +0800206 aliases.push_back(bp);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900207 n = (int) strlen(bp) + 1; /* for the \0 */
208 if (n >= MAXHOSTNAMELEN) {
209 had_error++;
210 continue;
211 }
212 bp += n;
213 /* Get canonical name. */
214 n = (int) strlen(tbuf) + 1; /* for the \0 */
215 if (n > ep - bp || n >= MAXHOSTNAMELEN) {
216 had_error++;
217 continue;
218 }
219 strlcpy(bp, tbuf, (size_t)(ep - bp));
220 hent->h_name = bp;
221 bp += n;
222 continue;
223 }
224 if (qtype == T_PTR && type == T_CNAME) {
225 n = dn_expand(answer->buf, eom, cp, tbuf, (int) sizeof tbuf);
Bernie Innocenti10a90282020-01-23 23:28:00 +0900226 if (n < 0 || !res_dnok(tbuf)) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900227 had_error++;
228 continue;
229 }
230 cp += n;
231 if (cp != erdata) goto no_recovery;
232 /* Get canonical name. */
233 n = (int) strlen(tbuf) + 1; /* for the \0 */
234 if (n > ep - bp || n >= MAXHOSTNAMELEN) {
235 had_error++;
236 continue;
237 }
238 strlcpy(bp, tbuf, (size_t)(ep - bp));
239 tname = bp;
240 bp += n;
241 continue;
242 }
243 if (type != qtype) {
244 if (type != T_KEY && type != T_SIG)
Ken Chenffc224a2019-03-19 17:41:28 +0800245 LOG(DEBUG) << __func__ << ": asked for \"" << qname << " " << p_class(C_IN) << " "
246 << p_type(qtype) << "\", got type \"" << p_type(type) << "\"";
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900247 cp += n;
248 continue; /* XXX - had_error++ ? */
249 }
250 switch (type) {
251 case T_PTR:
252 if (strcasecmp(tname, bp) != 0) {
Ken Chenffc224a2019-03-19 17:41:28 +0800253 LOG(DEBUG) << __func__ << ": asked for \"" << qname << "\", got \"" << bp
254 << "\"";
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900255 cp += n;
256 continue; /* XXX - had_error++ ? */
257 }
258 n = dn_expand(answer->buf, eom, cp, bp, (int) (ep - bp));
Bernie Innocenti10a90282020-01-23 23:28:00 +0900259 if ((n < 0) || !res_hnok(bp)) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900260 had_error++;
261 break;
262 }
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900263 cp += n;
264 if (cp != erdata) goto no_recovery;
265 if (!haveanswer)
266 hent->h_name = bp;
267 else
lifrbe7dfbf2019-01-09 14:41:15 +0800268 aliases.push_back(bp);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900269 if (n != -1) {
270 n = (int) strlen(bp) + 1; /* for the \0 */
271 if (n >= MAXHOSTNAMELEN) {
272 had_error++;
273 break;
274 }
275 bp += n;
276 }
277 break;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900278 case T_A:
279 case T_AAAA:
280 if (strcasecmp(hent->h_name, bp) != 0) {
Ken Chenffc224a2019-03-19 17:41:28 +0800281 LOG(DEBUG) << __func__ << ": asked for \"" << hent->h_name << "\", got \"" << bp
282 << "\"";
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900283 cp += n;
284 continue; /* XXX - had_error++ ? */
285 }
286 if (n != hent->h_length) {
287 cp += n;
288 continue;
289 }
290 if (type == T_AAAA) {
291 struct in6_addr in6;
292 memcpy(&in6, cp, NS_IN6ADDRSZ);
293 if (IN6_IS_ADDR_V4MAPPED(&in6)) {
294 cp += n;
295 continue;
296 }
297 }
298 if (!haveanswer) {
299 int nn;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900300
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900301 hent->h_name = bp;
302 nn = (int) strlen(bp) + 1; /* for the \0 */
303 bp += nn;
304 }
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900305
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900306 bp = align_ptr<sizeof(int32_t)>(bp);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900307
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900308 if (bp + n >= ep) {
Ken Chenffc224a2019-03-19 17:41:28 +0800309 LOG(DEBUG) << __func__ << ": size (" << n << ") too big";
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900310 had_error++;
311 continue;
312 }
313 if (hap >= &addr_ptrs[MAXADDRS - 1]) {
314 if (!toobig++) {
Ken Chenffc224a2019-03-19 17:41:28 +0800315 LOG(DEBUG) << __func__ << ": Too many addresses (" << MAXADDRS << ")";
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900316 }
317 cp += n;
318 continue;
319 }
320 (void) memcpy(*hap++ = bp, cp, (size_t) n);
321 bp += n;
322 cp += n;
323 if (cp != erdata) goto no_recovery;
324 break;
325 default:
326 abort();
327 }
328 if (!had_error) haveanswer++;
329 }
330 if (haveanswer) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900331 *hap = NULL;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900332 if (!hent->h_name) {
333 n = (int) strlen(qname) + 1; /* for the \0 */
334 if (n > ep - bp || n >= MAXHOSTNAMELEN) goto no_recovery;
335 strlcpy(bp, qname, (size_t)(ep - bp));
336 hent->h_name = bp;
337 bp += n;
338 }
nuccachen9227b7f2018-09-18 13:38:48 +0800339 if (hent->h_addrtype == AF_INET) pad_v4v6_hostent(hent, &bp, ep);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900340 goto success;
341 }
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900342no_recovery:
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900343 *he = NO_RECOVERY;
344 return NULL;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900345success:
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900346 bp = align_ptr(bp);
lifrbe7dfbf2019-01-09 14:41:15 +0800347 aliases.push_back(nullptr);
348 qlen = aliases.size() * sizeof(*hent->h_aliases);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900349 if ((size_t)(ep - bp) < qlen) goto nospc;
Bernie Innocenti9c575932018-09-07 21:10:25 +0900350 hent->h_aliases = (char**) bp;
lifrbe7dfbf2019-01-09 14:41:15 +0800351 memcpy(bp, aliases.data(), qlen);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900352
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900353 bp += qlen;
354 n = (int) (hap - addr_ptrs);
355 qlen = (n + 1) * sizeof(*hent->h_addr_list);
356 if ((size_t)(ep - bp) < qlen) goto nospc;
Bernie Innocenti9c575932018-09-07 21:10:25 +0900357 hent->h_addr_list = (char**) bp;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900358 memcpy(bp, addr_ptrs, qlen);
359 *he = NETDB_SUCCESS;
360 return hent;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900361nospc:
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900362 errno = ENOSPC;
363 *he = NETDB_INTERNAL;
364 return NULL;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900365}
366
Bernie Innocenti36db7732019-10-11 18:03:02 +0900367int resolv_gethostbyname(const char* name, int af, hostent* hp, char* buf, size_t buflen,
368 const android_net_context* netcontext, hostent** result,
369 NetworkDnsEventReported* event) {
Bernie Innocentic0d8ada2020-11-04 12:51:22 +0900370 if (name == nullptr || hp == nullptr) {
371 return EAI_SYSTEM;
372 }
Bernie Innocenti36db7732019-10-11 18:03:02 +0900373
Bernie Innocentic0d8ada2020-11-04 12:51:22 +0900374 getnamaddr info;
Luke Huang1b3f4462020-12-04 17:48:39 +0800375 ResState res(netcontext, event);
Bernie Innocenti36db7732019-10-11 18:03:02 +0900376
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900377 size_t size;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900378 switch (af) {
379 case AF_INET:
380 size = NS_INADDRSZ;
381 break;
382 case AF_INET6:
383 size = NS_IN6ADDRSZ;
384 break;
385 default:
Mike Yuc7d55102018-11-06 19:20:07 +0800386 return EAI_FAMILY;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900387 }
388 if (buflen < size) goto nospc;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900389
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900390 hp->h_addrtype = af;
391 hp->h_length = (int) size;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900392
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900393 /*
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900394 * disallow names consisting only of digits/dots, unless
395 * they end in a dot.
396 */
chenbrucec51f1212019-09-12 16:59:33 +0800397 if (isdigit((uint8_t)name[0])) {
Bernie Innocenti2e8540b2018-09-26 11:52:04 +0900398 for (const char* cp = name;; ++cp) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900399 if (!*cp) {
400 if (*--cp == '.') break;
401 /*
402 * All-numeric, no dot at the end.
403 * Fake up a hostent as if we'd actually
404 * done a lookup.
405 */
406 goto fake;
407 }
chenbrucec51f1212019-09-12 16:59:33 +0800408 if (!isdigit((uint8_t)*cp) && *cp != '.') break;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900409 }
Bernie Innocenti2e8540b2018-09-26 11:52:04 +0900410 }
chenbrucec51f1212019-09-12 16:59:33 +0800411 if ((isxdigit((uint8_t)name[0]) && strchr(name, ':') != NULL) || name[0] == ':') {
Bernie Innocenti2e8540b2018-09-26 11:52:04 +0900412 for (const char* cp = name;; ++cp) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900413 if (!*cp) {
414 if (*--cp == '.') break;
415 /*
416 * All-IPv6-legal, no dot at the end.
417 * Fake up a hostent as if we'd actually
418 * done a lookup.
419 */
420 goto fake;
421 }
chenbrucec51f1212019-09-12 16:59:33 +0800422 if (!isxdigit((uint8_t)*cp) && *cp != ':' && *cp != '.') break;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900423 }
Bernie Innocenti2e8540b2018-09-26 11:52:04 +0900424 }
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900425
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900426 info.hp = hp;
427 info.buf = buf;
428 info.buflen = buflen;
Hungming Chen6c84a3d2018-12-26 16:14:17 +0800429 if (_hf_gethtbyname2(name, af, &info)) {
Bernie Innocenti08487112019-10-11 21:14:13 +0900430 int error = dns_gethtbyname(&res, name, af, &info);
Hungming Chena6914a62019-01-19 15:07:04 +0800431 if (error != 0) return error;
Bernie Innocentic939de02018-09-12 17:59:17 +0900432 }
Bernie Innocenti36db7732019-10-11 18:03:02 +0900433 *result = hp;
Mike Yuc7d55102018-11-06 19:20:07 +0800434 return 0;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900435nospc:
Hungming Chen6c84a3d2018-12-26 16:14:17 +0800436 return EAI_MEMORY;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900437fake:
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900438 HENT_ARRAY(hp->h_addr_list, 1, buf, buflen);
439 HENT_ARRAY(hp->h_aliases, 0, buf, buflen);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900440
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900441 hp->h_aliases[0] = NULL;
442 if (size > buflen) goto nospc;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900443
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900444 if (inet_pton(af, name, buf) <= 0) {
Mike Yuc7d55102018-11-06 19:20:07 +0800445 return EAI_NODATA;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900446 }
447 hp->h_addr_list[0] = buf;
448 hp->h_addr_list[1] = NULL;
449 buf += size;
450 buflen -= size;
451 HENT_SCOPY(hp->h_name, name, buf, buflen);
Bernie Innocenti36db7732019-10-11 18:03:02 +0900452 *result = hp;
Mike Yuc7d55102018-11-06 19:20:07 +0800453 return 0;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900454}
455
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900456int resolv_gethostbyaddr(const void* _Nonnull addr, socklen_t len, int af, hostent* hp, char* buf,
Bernie Innocenti324f9f82019-10-11 18:50:20 +0900457 size_t buflen, const struct android_net_context* netcontext,
458 hostent** result, NetworkDnsEventReported* event) {
chenbrucec51f1212019-09-12 16:59:33 +0800459 const uint8_t* uaddr = (const uint8_t*)addr;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900460 socklen_t size;
461 struct getnamaddr info;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900462
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900463 if (af == AF_INET6 && len == NS_IN6ADDRSZ &&
464 (IN6_IS_ADDR_LINKLOCAL((const struct in6_addr*) addr) ||
465 IN6_IS_ADDR_SITELOCAL((const struct in6_addr*) addr))) {
Hungming Chen598202c2018-12-26 17:04:43 +0800466 return EAI_NODATA;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900467 }
468 if (af == AF_INET6 && len == NS_IN6ADDRSZ &&
469 (IN6_IS_ADDR_V4MAPPED((const struct in6_addr*) addr) ||
470 IN6_IS_ADDR_V4COMPAT((const struct in6_addr*) addr))) {
471 /* Unmap. */
472 uaddr += NS_IN6ADDRSZ - NS_INADDRSZ;
473 addr = uaddr;
474 af = AF_INET;
475 len = NS_INADDRSZ;
476 }
477 switch (af) {
478 case AF_INET:
479 size = NS_INADDRSZ;
480 break;
481 case AF_INET6:
482 size = NS_IN6ADDRSZ;
483 break;
484 default:
Hungming Chen598202c2018-12-26 17:04:43 +0800485 return EAI_FAMILY;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900486 }
487 if (size != len) {
Hungming Chena6914a62019-01-19 15:07:04 +0800488 // TODO: Consider converting to a private extended EAI_* error code.
489 // Currently, the EAI_* value has no corresponding error code for invalid argument socket
490 // length. In order to not rely on errno, convert the original error code pair, EAI_SYSTEM
491 // and EINVAL, to EAI_FAIL.
492 return EAI_FAIL;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900493 }
494 info.hp = hp;
495 info.buf = buf;
496 info.buflen = buflen;
Hungming Chen6c84a3d2018-12-26 16:14:17 +0800497 if (_hf_gethtbyaddr(uaddr, len, af, &info)) {
lifr94981782019-05-17 21:15:19 +0800498 int error = dns_gethtbyaddr(uaddr, len, af, netcontext, &info, event);
Hungming Chena6914a62019-01-19 15:07:04 +0800499 if (error != 0) return error;
Bernie Innocenti9f61dbd2018-09-12 20:03:11 +0900500 }
Bernie Innocenti324f9f82019-10-11 18:50:20 +0900501 *result = hp;
Hungming Chen598202c2018-12-26 17:04:43 +0800502 return 0;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900503}
504
Hungming Chena6914a62019-01-19 15:07:04 +0800505// TODO: Consider leaving function without returning error code as _gethtent() does because
506// the error code of the caller does not currently return to netd.
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900507struct hostent* netbsd_gethostent_r(FILE* hf, struct hostent* hent, char* buf, size_t buflen,
508 int* he) {
Bernie Innocenti9c575932018-09-07 21:10:25 +0900509 char *name;
lifrbe7dfbf2019-01-09 14:41:15 +0800510 char* cp;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900511 int af, len;
512 size_t anum;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900513 struct in6_addr host_addr;
lifrbe7dfbf2019-01-09 14:41:15 +0800514 std::vector<char*> aliases;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900515
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900516 if (hf == NULL) {
517 *he = NETDB_INTERNAL;
518 errno = EINVAL;
519 return NULL;
520 }
Bernie Innocenti9c575932018-09-07 21:10:25 +0900521 char* p = NULL;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900522
Bernie Innocenti36db7732019-10-11 18:03:02 +0900523 // Allocate a new space to read file lines like upstream does.
524 const size_t line_buf_size = MAXPACKET;
Bernie Innocenti9c575932018-09-07 21:10:25 +0900525 if ((p = (char*) malloc(line_buf_size)) == NULL) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900526 goto nospc;
527 }
528 for (;;) {
529 if (!fgets(p, line_buf_size, hf)) {
530 free(p);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900531 *he = HOST_NOT_FOUND;
532 return NULL;
533 }
534 if (*p == '#') {
535 continue;
536 }
537 if (!(cp = strpbrk(p, "#\n"))) {
538 continue;
539 }
540 *cp = '\0';
541 if (!(cp = strpbrk(p, " \t"))) continue;
542 *cp++ = '\0';
543 if (inet_pton(AF_INET6, p, &host_addr) > 0) {
544 af = AF_INET6;
545 len = NS_IN6ADDRSZ;
546 } else {
547 if (inet_pton(AF_INET, p, &host_addr) <= 0) continue;
chenbruce018fdb22019-06-12 18:08:04 +0800548 af = AF_INET;
549 len = NS_INADDRSZ;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900550 }
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900551
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900552 /* if this is not something we're looking for, skip it. */
553 if (hent->h_addrtype != 0 && hent->h_addrtype != af) continue;
554 if (hent->h_length != 0 && hent->h_length != len) continue;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900555
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900556 while (*cp == ' ' || *cp == '\t') cp++;
557 if ((cp = strpbrk(name = cp, " \t")) != NULL) *cp++ = '\0';
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900558 while (cp && *cp) {
559 if (*cp == ' ' || *cp == '\t') {
560 cp++;
561 continue;
562 }
lifrbe7dfbf2019-01-09 14:41:15 +0800563 aliases.push_back(cp);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900564 if ((cp = strpbrk(cp, " \t")) != NULL) *cp++ = '\0';
565 }
566 break;
567 }
568 hent->h_length = len;
569 hent->h_addrtype = af;
570 HENT_ARRAY(hent->h_addr_list, 1, buf, buflen);
lifrbe7dfbf2019-01-09 14:41:15 +0800571 anum = aliases.size();
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900572 HENT_ARRAY(hent->h_aliases, anum, buf, buflen);
573 HENT_COPY(hent->h_addr_list[0], &host_addr, hent->h_length, buf, buflen);
574 hent->h_addr_list[1] = NULL;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900575
nuccachenc28257d2018-09-11 11:20:00 +0800576 /* Reserve space for mapping IPv4 address to IPv6 address in place */
577 if (hent->h_addrtype == AF_INET) {
578 HENT_COPY(buf, NAT64_PAD, sizeof(NAT64_PAD), buf, buflen);
579 }
580
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900581 HENT_SCOPY(hent->h_name, name, buf, buflen);
582 for (size_t i = 0; i < anum; i++) HENT_SCOPY(hent->h_aliases[i], aliases[i], buf, buflen);
583 hent->h_aliases[anum] = NULL;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900584 *he = NETDB_SUCCESS;
585 free(p);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900586 return hent;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900587nospc:
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900588 free(p);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900589 errno = ENOSPC;
590 *he = NETDB_INTERNAL;
591 return NULL;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900592}
593
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900594/* Reserve space for mapping IPv4 address to IPv6 address in place */
595static void pad_v4v6_hostent(struct hostent* _Nonnull hp, char** _Nonnull bpp, char* _Nonnull ep) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900596 if (hp->h_addrtype != AF_INET || hp->h_length != NS_INADDRSZ) return;
nuccachen9227b7f2018-09-18 13:38:48 +0800597 for (char** ap = hp->h_addr_list; *ap; ap++) {
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900598 char* const bp = align_ptr<sizeof(int32_t)>(*bpp);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900599
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900600 if (ep - bp < NS_IN6ADDRSZ) {
601 // Out of space. Truncate address list here.
602 *ap = nullptr;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900603 return;
604 }
Bernie Innocentibc7d6c02021-06-22 16:59:52 +0900605 memcpy(bp, *ap, NS_INADDRSZ);
606 memcpy(bp + NS_INADDRSZ, NAT64_PAD, sizeof(NAT64_PAD));
607 *ap = bp;
608 *bpp = bp + NS_IN6ADDRSZ;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900609 }
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900610}
611
Bernie Innocenti08487112019-10-11 21:14:13 +0900612static int dns_gethtbyname(ResState* res, const char* name, int addr_type, getnamaddr* info) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900613 int n, type;
Bernie Innocentic939de02018-09-12 17:59:17 +0900614 info->hp->h_addrtype = addr_type;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900615
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900616 switch (info->hp->h_addrtype) {
617 case AF_INET:
618 info->hp->h_length = NS_INADDRSZ;
619 type = T_A;
620 break;
621 case AF_INET6:
622 info->hp->h_length = NS_IN6ADDRSZ;
623 type = T_AAAA;
624 break;
625 default:
Mike Yuc7d55102018-11-06 19:20:07 +0800626 return EAI_FAMILY;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900627 }
waynema0cac8c62019-03-08 16:58:06 +0800628 auto buf = std::make_unique<querybuf>();
629
Hungming Chena6914a62019-01-19 15:07:04 +0800630 int he;
631 n = res_nsearch(res, name, C_IN, type, buf->buf, (int)sizeof(buf->buf), &he);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900632 if (n < 0) {
Ken Chenffc224a2019-03-19 17:41:28 +0800633 LOG(DEBUG) << __func__ << ": res_nsearch failed (" << n << ")";
Hungming Chena6914a62019-01-19 15:07:04 +0800634 // Return h_errno (he) to catch more detailed errors rather than EAI_NODATA.
635 // Note that res_nsearch() doesn't set the pair NETDB_INTERNAL and errno.
636 // See also herrnoToAiErrno().
637 return herrnoToAiErrno(he);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900638 }
Bernie Innocenti3479d3b2019-10-08 22:23:26 +0900639 hostent* hp = getanswer(buf.get(), n, name, type, info->hp, info->buf, info->buflen, &he);
Hungming Chena6914a62019-01-19 15:07:04 +0800640 if (hp == NULL) return herrnoToAiErrno(he);
641
Mike Yuc7d55102018-11-06 19:20:07 +0800642 return 0;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900643}
644
waynema067e9842019-03-08 19:13:41 +0800645static int dns_gethtbyaddr(const unsigned char* uaddr, int len, int af,
lifr94981782019-05-17 21:15:19 +0800646 const android_net_context* netcontext, getnamaddr* info,
647 NetworkDnsEventReported* event) {
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900648 char qbuf[MAXDNAME + 1], *qp, *ep;
649 int n;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900650 int advance;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900651
Bernie Innocenti9f61dbd2018-09-12 20:03:11 +0900652 info->hp->h_length = len;
653 info->hp->h_addrtype = af;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900654
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900655 switch (info->hp->h_addrtype) {
656 case AF_INET:
657 (void) snprintf(qbuf, sizeof(qbuf), "%u.%u.%u.%u.in-addr.arpa", (uaddr[3] & 0xff),
658 (uaddr[2] & 0xff), (uaddr[1] & 0xff), (uaddr[0] & 0xff));
659 break;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900660
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900661 case AF_INET6:
662 qp = qbuf;
663 ep = qbuf + sizeof(qbuf) - 1;
664 for (n = NS_IN6ADDRSZ - 1; n >= 0; n--) {
665 advance = snprintf(qp, (size_t)(ep - qp), "%x.%x.", uaddr[n] & 0xf,
666 ((unsigned int) uaddr[n] >> 4) & 0xf);
667 if (advance > 0 && qp + advance < ep)
668 qp += advance;
669 else {
Hungming Chena6914a62019-01-19 15:07:04 +0800670 // TODO: Consider converting to a private extended EAI_* error code.
671 // Currently, the EAI_* value has no corresponding error code for an internal
672 // out of buffer space. In order to not rely on errno, convert the original
673 // error code EAI_SYSTEM to EAI_MEMORY.
674 return EAI_MEMORY;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900675 }
676 }
677 if (strlcat(qbuf, "ip6.arpa", sizeof(qbuf)) >= sizeof(qbuf)) {
Hungming Chena6914a62019-01-19 15:07:04 +0800678 // TODO: Consider converting to a private extended EAI_* error code.
679 // Currently, the EAI_* value has no corresponding error code for an internal
680 // out of buffer space. In order to not rely on errno, convert the original
681 // error code EAI_SYSTEM to EAI_MEMORY.
682 return EAI_MEMORY;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900683 }
684 break;
685 default:
Hungming Chen598202c2018-12-26 17:04:43 +0800686 return EAI_FAMILY;
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900687 }
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900688
waynema067e9842019-03-08 19:13:41 +0800689 auto buf = std::make_unique<querybuf>();
690
Luke Huang1b3f4462020-12-04 17:48:39 +0800691 ResState res(netcontext, event);
Hungming Chena6914a62019-01-19 15:07:04 +0800692 int he;
Bernie Innocenti08487112019-10-11 21:14:13 +0900693 n = res_nquery(&res, qbuf, C_IN, T_PTR, buf->buf, (int)sizeof(buf->buf), &he);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900694 if (n < 0) {
Ken Chenffc224a2019-03-19 17:41:28 +0800695 LOG(DEBUG) << __func__ << ": res_nquery failed (" << n << ")";
Hungming Chena6914a62019-01-19 15:07:04 +0800696 // Note that res_nquery() doesn't set the pair NETDB_INTERNAL and errno.
697 // Return h_errno (he) to catch more detailed errors rather than EAI_NODATA.
698 // See also herrnoToAiErrno().
699 return herrnoToAiErrno(he);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900700 }
Bernie Innocenti3479d3b2019-10-08 22:23:26 +0900701 hostent* hp = getanswer(buf.get(), n, qbuf, T_PTR, info->hp, info->buf, info->buflen, &he);
Hungming Chena6914a62019-01-19 15:07:04 +0800702 if (hp == NULL) return herrnoToAiErrno(he);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900703
Bernie Innocenti9c575932018-09-07 21:10:25 +0900704 char* bf = (char*) (hp->h_addr_list + 2);
705 size_t blen = (size_t)(bf - info->buf);
Bernie Innocenti8ad893f2018-08-31 14:09:46 +0900706 if (blen + info->hp->h_length > info->buflen) goto nospc;
707 hp->h_addr_list[0] = bf;
708 hp->h_addr_list[1] = NULL;
Bernie Innocenti9c575932018-09-07 21:10:25 +0900709 memcpy(bf, uaddr, (size_t) info->hp->h_length);
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900710
nuccachenc28257d2018-09-11 11:20:00 +0800711 /* Reserve enough space for mapping IPv4 address to IPv6 address in place */
712 if (info->hp->h_addrtype == AF_INET) {
713 if (blen + NS_IN6ADDRSZ > info->buflen) goto nospc;
714 // Pad zero to the unused address space
715 memcpy(bf + NS_INADDRSZ, NAT64_PAD, sizeof(NAT64_PAD));
716 }
717
Hungming Chen598202c2018-12-26 17:04:43 +0800718 return 0;
Bernie Innocenti9c575932018-09-07 21:10:25 +0900719
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900720nospc:
Hungming Chen598202c2018-12-26 17:04:43 +0800721 return EAI_MEMORY;
Bernie Innocenti318ed2d2018-08-30 04:05:20 +0900722}
723
Hungming Chena6914a62019-01-19 15:07:04 +0800724int herrnoToAiErrno(int he) {
725 switch (he) {
Hungming Chen947aab02018-12-27 18:33:19 +0800726 // extended h_errno
727 case NETD_RESOLV_H_ERRNO_EXT_TIMEOUT:
728 return NETD_RESOLV_TIMEOUT;
729 // legacy h_errno
730 case NETDB_SUCCESS:
731 return 0;
732 case HOST_NOT_FOUND: // TODO: Perhaps convert HOST_NOT_FOUND to EAI_NONAME instead
733 case NO_DATA: // NO_ADDRESS
Mike Yubfb1b342018-11-06 15:42:36 +0800734 return EAI_NODATA;
735 case TRY_AGAIN:
736 return EAI_AGAIN;
Hungming Chen947aab02018-12-27 18:33:19 +0800737 case NETDB_INTERNAL:
Hungming Chena6914a62019-01-19 15:07:04 +0800738 // TODO: Remove ENOSPC and call abort() immediately whenever any allocation fails.
739 if (errno == ENOSPC) return EAI_MEMORY;
740 // Theoretically, this should not happen. Leave this here just in case.
741 // Currently, getanswer() of {gethnamaddr, getaddrinfo}.cpp, res_nsearch() and
742 // res_searchN() use this function to convert error code. Only getanswer()
743 // of gethnamaddr.cpp may return the error code pair, herrno NETDB_INTERNAL and
744 // errno ENOSPC, which has already converted to EAI_MEMORY. The remaining functions
745 // don't set the pair herrno and errno.
Hungming Chen947aab02018-12-27 18:33:19 +0800746 return EAI_SYSTEM; // see errno for detail
747 case NO_RECOVERY:
Mike Yubfb1b342018-11-06 15:42:36 +0800748 default:
Hungming Chena6914a62019-01-19 15:07:04 +0800749 return EAI_FAIL; // TODO: Perhaps convert default to EAI_MAX (unknown error) instead
Mike Yubfb1b342018-11-06 15:42:36 +0800750 }
Bernie Innocentie71a28a2019-05-29 00:42:35 +0900751}