summaryrefslogtreecommitdiff
path: root/src/lib/libc/net/res_init.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/libc/net/res_init.c')
-rw-r--r--src/lib/libc/net/res_init.c666
1 files changed, 666 insertions, 0 deletions
diff --git a/src/lib/libc/net/res_init.c b/src/lib/libc/net/res_init.c
new file mode 100644
index 0000000000..43ee5ac6bb
--- /dev/null
+++ b/src/lib/libc/net/res_init.c
@@ -0,0 +1,666 @@
1/* $OpenBSD: res_init.c,v 1.34 2005/12/22 06:52:11 tedu Exp $ */
2
3/*
4 * ++Copyright++ 1985, 1989, 1993
5 * -
6 * Copyright (c) 1985, 1989, 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
54#ifndef INET6
55#define INET6
56#endif
57
58#include <sys/types.h>
59#include <sys/param.h>
60#include <sys/socket.h>
61#include <sys/time.h>
62#include <sys/stat.h>
63#include <netinet/in.h>
64#include <arpa/inet.h>
65#include <arpa/nameser.h>
66
67#include <stdio.h>
68#include <ctype.h>
69#include <resolv.h>
70#include <unistd.h>
71#include <stdlib.h>
72#include <string.h>
73#ifdef INET6
74#include <netdb.h>
75#endif /* INET6 */
76
77#include "thread_private.h"
78
79/*-------------------------------------- info about "sortlist" --------------
80 * Marc Majka 1994/04/16
81 * Allan Nathanson 1994/10/29 (BIND 4.9.3.x)
82 *
83 * NetInfo resolver configuration directory support.
84 *
85 * Allow a NetInfo directory to be created in the hierarchy which
86 * contains the same information as the resolver configuration file.
87 *
88 * - The local domain name is stored as the value of the "domain" property.
89 * - The Internet address(es) of the name server(s) are stored as values
90 * of the "nameserver" property.
91 * - The name server addresses are stored as values of the "nameserver"
92 * property.
93 * - The search list for host-name lookup is stored as values of the
94 * "search" property.
95 * - The sortlist comprised of IP address netmask pairs are stored as
96 * values of the "sortlist" property. The IP address and optional netmask
97 * should be separated by a slash (/) or ampersand (&) character.
98 * - Internal resolver variables can be set from the value of the "options"
99 * property.
100 */
101
102static void res_setoptions(char *, char *);
103
104#ifdef RESOLVSORT
105static const char sort_mask[] = "/&";
106#define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
107static u_int32_t net_mask(struct in_addr);
108#endif
109
110/*
111 * Resolver state default settings.
112 */
113void *__THREAD_NAME(_res);
114
115struct __res_state _res
116# if defined(__BIND_RES_TEXT)
117 = { RES_TIMEOUT, } /* Motorola, et al. */
118# endif
119 ;
120#ifdef INET6
121void *__THREAD_NAME(_res_ext);
122
123struct __res_state_ext _res_ext;
124#endif /* INET6 */
125
126int __res_chktime = 30;
127
128/*
129 * Set up default settings. If the configuration file exist, the values
130 * there will have precedence. Otherwise, the server address is set to
131 * INADDR_ANY and the default domain name comes from the gethostname().
132 *
133 * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
134 * rather than INADDR_ANY ("0.0.0.0") as the default name server address
135 * since it was noted that INADDR_ANY actually meant ``the first interface
136 * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
137 * it had to be "up" in order for you to reach your own name server. It
138 * was later decided that since the recommended practice is to always
139 * install local static routes through 127.0.0.1 for all your network
140 * interfaces, that we could solve this problem without a code change.
141 *
142 * The configuration file should always be used, since it is the only way
143 * to specify a default domain. If you are running a server on your local
144 * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
145 * in the configuration file.
146 *
147 * Return 0 if completes successfully, -1 on error
148 */
149int
150res_init(void)
151{
152
153 return (_res_init(1));
154}
155
156int
157_res_init(int usercall)
158{
159 struct stat sb;
160 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
161#ifdef INET6
162 struct __res_state_ext *_res_extp = _THREAD_PRIVATE(_res_ext, _res_ext,
163 &_res_ext);
164#endif
165 FILE *fp;
166 char *cp, **pp;
167 int n;
168 char buf[BUFSIZ];
169 int nserv = 0; /* number of nameserver records read from file */
170 int haveenv = 0;
171 int havesearch = 0;
172 size_t len;
173#ifdef RESOLVSORT
174 int nsort = 0;
175 char *net;
176#endif
177#ifndef RFC1535
178 int dots;
179#endif
180
181 if (!usercall && _resp->options & RES_INIT &&
182 _resp->reschktime >= time(NULL))
183 return (0);
184 _resp->reschktime = time(NULL) + __res_chktime;
185 if (stat(_PATH_RESCONF, &sb) != -1) {
186 if (!usercall && timespeccmp(&sb.st_mtimespec,
187 &_resp->restimespec, ==))
188 return (0);
189 else
190 _resp->restimespec = sb.st_mtimespec;
191 } else {
192 /*
193 * Lost the file, in chroot?
194 * Don't trash settings
195 */
196 if (!usercall && timespecisset(&_resp->restimespec))
197 return (0);
198 }
199
200
201 /*
202 * These three fields used to be statically initialized. This made
203 * it hard to use this code in a shared library. It is necessary,
204 * now that we're doing dynamic initialization here, that we preserve
205 * the old semantics: if an application modifies one of these three
206 * fields of _res before res_init() is called, res_init() will not
207 * alter them. Of course, if an application is setting them to
208 * _zero_ before calling res_init(), hoping to override what used
209 * to be the static default, we can't detect it and unexpected results
210 * will follow. Zero for any of these fields would make no sense,
211 * so one can safely assume that the applications were already getting
212 * unexpected results.
213 *
214 * _res.options is tricky since some apps were known to diddle the bits
215 * before res_init() was first called. We can't replicate that semantic
216 * with dynamic initialization (they may have turned bits off that are
217 * set in RES_DEFAULT). Our solution is to declare such applications
218 * "broken". They could fool us by setting RES_INIT but none do (yet).
219 */
220 if (!_resp->retrans)
221 _resp->retrans = RES_TIMEOUT;
222 if (!_resp->retry)
223 _resp->retry = 4;
224 if (!(_resp->options & RES_INIT))
225 _resp->options = RES_DEFAULT;
226
227#ifdef USELOOPBACK
228 _resp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
229#else
230 _resp->nsaddr.sin_addr.s_addr = INADDR_ANY;
231#endif
232 _resp->nsaddr.sin_family = AF_INET;
233 _resp->nsaddr.sin_port = htons(NAMESERVER_PORT);
234 _resp->nsaddr.sin_len = sizeof(struct sockaddr_in);
235#ifdef INET6
236 if (sizeof(_res_extp->nsaddr) >= _resp->nsaddr.sin_len)
237 memcpy(&_res_extp->nsaddr, &_resp->nsaddr, _resp->nsaddr.sin_len);
238#endif
239 _resp->nscount = 1;
240 _resp->ndots = 1;
241 _resp->pfcode = 0;
242 strlcpy(_resp->lookups, "f", sizeof _resp->lookups);
243
244 /* Allow user to override the local domain definition */
245 if (issetugid() == 0 && (cp = getenv("LOCALDOMAIN")) != NULL) {
246 strlcpy(_resp->defdname, cp, sizeof(_resp->defdname));
247 haveenv++;
248
249 /*
250 * Set search list to be blank-separated strings
251 * from rest of env value. Permits users of LOCALDOMAIN
252 * to still have a search list, and anyone to set the
253 * one that they want to use as an individual (even more
254 * important now that the rfc1535 stuff restricts searches)
255 */
256 cp = _resp->defdname;
257 pp = _resp->dnsrch;
258 *pp++ = cp;
259 for (n = 0; *cp && pp < _resp->dnsrch + MAXDNSRCH; cp++) {
260 if (*cp == '\n') /* silly backwards compat */
261 break;
262 else if (*cp == ' ' || *cp == '\t') {
263 *cp = 0;
264 n = 1;
265 } else if (n) {
266 *pp++ = cp;
267 n = 0;
268 havesearch = 1;
269 }
270 }
271 /* null terminate last domain if there are excess */
272 while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
273 cp++;
274 *cp = '\0';
275 *pp++ = 0;
276 }
277
278#define MATCH(line, name) \
279 (!strncmp(line, name, sizeof(name) - 1) && \
280 (line[sizeof(name) - 1] == ' ' || \
281 line[sizeof(name) - 1] == '\t'))
282
283 if ((fp = fopen(_PATH_RESCONF, "r")) != NULL) {
284 strlcpy(_resp->lookups, "bf", sizeof _resp->lookups);
285
286 /* read the config file */
287 buf[0] = '\0';
288 while ((cp = fgetln(fp, &len)) != NULL) {
289 /* skip lines that are too long or zero length */
290 if (len >= sizeof(buf) || len == 0)
291 continue;
292 (void)memcpy(buf, cp, len);
293 buf[len] = '\0';
294 /* skip comments */
295 if ((cp = strpbrk(buf, ";#")) != NULL)
296 *cp = '\0';
297 if (buf[0] == '\0')
298 continue;
299 /* read default domain name */
300 if (MATCH(buf, "domain")) {
301 if (haveenv) /* skip if have from environ */
302 continue;
303 cp = buf + sizeof("domain") - 1;
304 while (*cp == ' ' || *cp == '\t')
305 cp++;
306 if ((*cp == '\0') || (*cp == '\n'))
307 continue;
308 strlcpy(_resp->defdname, cp, sizeof(_resp->defdname));
309 if ((cp = strpbrk(_resp->defdname, " \t\n")) != NULL)
310 *cp = '\0';
311 havesearch = 0;
312 continue;
313 }
314 /* lookup types */
315 if (MATCH(buf, "lookup")) {
316 char *sp = NULL;
317
318 bzero(_resp->lookups, sizeof _resp->lookups);
319 cp = buf + sizeof("lookup") - 1;
320 for (n = 0;; cp++) {
321 if (n == MAXDNSLUS)
322 break;
323 if ((*cp == '\0') || (*cp == '\n')) {
324 if (sp) {
325 if (*sp=='y' || *sp=='b' || *sp=='f')
326 _resp->lookups[n++] = *sp;
327 sp = NULL;
328 }
329 break;
330 } else if ((*cp == ' ') || (*cp == '\t') || (*cp == ',')) {
331 if (sp) {
332 if (*sp=='y' || *sp=='b' || *sp=='f')
333 _resp->lookups[n++] = *sp;
334 sp = NULL;
335 }
336 } else if (sp == NULL)
337 sp = cp;
338 }
339 continue;
340 }
341 /* set search list */
342 if (MATCH(buf, "search")) {
343 if (haveenv) /* skip if have from environ */
344 continue;
345 cp = buf + sizeof("search") - 1;
346 while (*cp == ' ' || *cp == '\t')
347 cp++;
348 if ((*cp == '\0') || (*cp == '\n'))
349 continue;
350 strlcpy(_resp->defdname, cp, sizeof(_resp->defdname));
351 if ((cp = strchr(_resp->defdname, '\n')) != NULL)
352 *cp = '\0';
353 /*
354 * Set search list to be blank-separated strings
355 * on rest of line.
356 */
357 cp = _resp->defdname;
358 pp = _resp->dnsrch;
359 *pp++ = cp;
360 for (n = 0; *cp && pp < _resp->dnsrch + MAXDNSRCH; cp++) {
361 if (*cp == ' ' || *cp == '\t') {
362 *cp = 0;
363 n = 1;
364 } else if (n) {
365 *pp++ = cp;
366 n = 0;
367 }
368 }
369 /* null terminate last domain if there are excess */
370 while (*cp != '\0' && *cp != ' ' && *cp != '\t')
371 cp++;
372 *cp = '\0';
373 *pp++ = 0;
374 havesearch = 1;
375 continue;
376 }
377 /* read nameservers to query */
378 if (MATCH(buf, "nameserver") && nserv < MAXNS) {
379#ifdef INET6
380 char *q;
381 struct addrinfo hints, *res;
382 char pbuf[NI_MAXSERV];
383#else
384 struct in_addr a;
385#endif /* INET6 */
386
387 cp = buf + sizeof("nameserver") - 1;
388 while (*cp == ' ' || *cp == '\t')
389 cp++;
390#ifdef INET6
391 if ((*cp == '\0') || (*cp == '\n'))
392 continue;
393 for (q = cp; *q; q++) {
394 if (isspace(*q)) {
395 *q = '\0';
396 break;
397 }
398 }
399 memset(&hints, 0, sizeof(hints));
400 hints.ai_flags = AI_NUMERICHOST;
401 hints.ai_socktype = SOCK_DGRAM;
402 snprintf(pbuf, sizeof(pbuf), "%u", NAMESERVER_PORT);
403 res = NULL;
404 if (getaddrinfo(cp, pbuf, &hints, &res) == 0 &&
405 res->ai_next == NULL) {
406 if (res->ai_addrlen <= sizeof(_res_extp->nsaddr_list[nserv])) {
407 memcpy(&_res_extp->nsaddr_list[nserv], res->ai_addr,
408 res->ai_addrlen);
409 } else {
410 memset(&_res_extp->nsaddr_list[nserv], 0,
411 sizeof(_res_extp->nsaddr_list[nserv]));
412 }
413 if (res->ai_addrlen <= sizeof(_resp->nsaddr_list[nserv])) {
414 memcpy(&_resp->nsaddr_list[nserv], res->ai_addr,
415 res->ai_addrlen);
416 } else {
417 memset(&_resp->nsaddr_list[nserv], 0,
418 sizeof(_resp->nsaddr_list[nserv]));
419 }
420 nserv++;
421 }
422 if (res)
423 freeaddrinfo(res);
424#else /* INET6 */
425 if ((*cp != '\0') && (*cp != '\n') && inet_aton(cp, &a)) {
426 _resp->nsaddr_list[nserv].sin_addr = a;
427 _resp->nsaddr_list[nserv].sin_family = AF_INET;
428 _resp->nsaddr_list[nserv].sin_port =
429 htons(NAMESERVER_PORT);
430 _resp->nsaddr_list[nserv].sin_len =
431 sizeof(struct sockaddr_in);
432 nserv++;
433 }
434#endif /* INET6 */
435 continue;
436 }
437#ifdef RESOLVSORT
438 if (MATCH(buf, "sortlist")) {
439 struct in_addr a;
440#ifdef INET6
441 struct in6_addr a6;
442 int m, i;
443 u_char *u;
444#endif /* INET6 */
445
446 cp = buf + sizeof("sortlist") - 1;
447 while (nsort < MAXRESOLVSORT) {
448 while (*cp == ' ' || *cp == '\t')
449 cp++;
450 if (*cp == '\0' || *cp == '\n' || *cp == ';')
451 break;
452 net = cp;
453 while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
454 isascii(*cp) && !isspace(*cp))
455 cp++;
456 n = *cp;
457 *cp = 0;
458 if (inet_aton(net, &a)) {
459 _resp->sort_list[nsort].addr = a;
460 if (ISSORTMASK(n)) {
461 *cp++ = n;
462 net = cp;
463 while (*cp && *cp != ';' &&
464 isascii(*cp) && !isspace(*cp))
465 cp++;
466 n = *cp;
467 *cp = 0;
468 if (inet_aton(net, &a)) {
469 _resp->sort_list[nsort].mask = a.s_addr;
470 } else {
471 _resp->sort_list[nsort].mask =
472 net_mask(_resp->sort_list[nsort].addr);
473 }
474 } else {
475 _resp->sort_list[nsort].mask =
476 net_mask(_resp->sort_list[nsort].addr);
477 }
478#ifdef INET6
479 _res_extp->sort_list[nsort].af = AF_INET;
480 _res_extp->sort_list[nsort].addr.ina =
481 _resp->sort_list[nsort].addr;
482 _res_extp->sort_list[nsort].mask.ina.s_addr =
483 _resp->sort_list[nsort].mask;
484#endif /* INET6 */
485 nsort++;
486 }
487#ifdef INET6
488 else if (inet_pton(AF_INET6, net, &a6) == 1) {
489 _res_extp->sort_list[nsort].af = AF_INET6;
490 _res_extp->sort_list[nsort].addr.in6a = a6;
491 u = (u_char *)&_res_extp->sort_list[nsort].mask.in6a;
492 *cp++ = n;
493 net = cp;
494 while (*cp && *cp != ';' &&
495 isascii(*cp) && !isspace(*cp))
496 cp++;
497 m = n;
498 n = *cp;
499 *cp = 0;
500 switch (m) {
501 case '/':
502 m = atoi(net);
503 break;
504 case '&':
505 if (inet_pton(AF_INET6, net, u) == 1) {
506 m = -1;
507 break;
508 }
509 /*FALLTHRU*/
510 default:
511 m = sizeof(struct in6_addr) * NBBY;
512 break;
513 }
514 if (m >= 0) {
515 for (i = 0; i < sizeof(struct in6_addr); i++) {
516 if (m <= 0) {
517 *u = 0;
518 } else {
519 m -= NBBY;
520 *u = (u_char)~0;
521 if (m < 0)
522 *u <<= -m;
523 }
524 u++;
525 }
526 }
527 nsort++;
528 }
529#endif /* INET6 */
530 *cp = n;
531 }
532 continue;
533 }
534#endif
535 if (MATCH(buf, "options")) {
536 res_setoptions(buf + sizeof("options") - 1, "conf");
537 continue;
538 }
539 }
540 if (nserv > 1)
541 _resp->nscount = nserv;
542#ifdef RESOLVSORT
543 _resp->nsort = nsort;
544#endif
545 (void) fclose(fp);
546 }
547 if (_resp->defdname[0] == 0 &&
548 gethostname(buf, sizeof(_resp->defdname) - 1) == 0 &&
549 (cp = strchr(buf, '.')) != NULL)
550 {
551 strlcpy(_resp->defdname, cp + 1,
552 sizeof(_resp->defdname));
553 }
554
555 /* find components of local domain that might be searched */
556 if (havesearch == 0) {
557 pp = _resp->dnsrch;
558 *pp++ = _resp->defdname;
559 *pp = NULL;
560
561#ifndef RFC1535
562 dots = 0;
563 for (cp = _resp->defdname; *cp; cp++)
564 dots += (*cp == '.');
565
566 cp = _resp->defdname;
567 while (pp < _resp->dnsrch + MAXDFLSRCH) {
568 if (dots < LOCALDOMAINPARTS)
569 break;
570 cp = strchr(cp, '.') + 1; /* we know there is one */
571 *pp++ = cp;
572 dots--;
573 }
574 *pp = NULL;
575#ifdef DEBUG
576 if (_resp->options & RES_DEBUG) {
577 printf(";; res_init()... default dnsrch list:\n");
578 for (pp = _resp->dnsrch; *pp; pp++)
579 printf(";;\t%s\n", *pp);
580 printf(";;\t..END..\n");
581 }
582#endif /* DEBUG */
583#endif /* !RFC1535 */
584 }
585
586 if (issetugid())
587 _resp->options |= RES_NOALIASES;
588 else if ((cp = getenv("RES_OPTIONS")) != NULL)
589 res_setoptions(cp, "env");
590 _resp->options |= RES_INIT;
591 return (0);
592}
593
594/* ARGSUSED */
595static void
596res_setoptions(char *options, char *source)
597{
598 struct __res_state *_resp = _THREAD_PRIVATE(_res, _res, &_res);
599 char *cp = options;
600 char *endp;
601 long l;
602
603#ifdef DEBUG
604 if (_resp->options & RES_DEBUG)
605 printf(";; res_setoptions(\"%s\", \"%s\")...\n",
606 options, source);
607#endif
608 while (*cp) {
609 /* skip leading and inner runs of spaces */
610 while (*cp == ' ' || *cp == '\t')
611 cp++;
612 /* search for and process individual options */
613 if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
614 char *p = cp + sizeof("ndots:") - 1;
615 l = strtol(p, &endp, 10);
616 if (l >= 0 && endp != p &&
617 (*endp = '\0' || isspace(*endp))) {
618 if (l <= RES_MAXNDOTS)
619 _resp->ndots = l;
620 else
621 _resp->ndots = RES_MAXNDOTS;
622#ifdef DEBUG
623 if (_resp->options & RES_DEBUG)
624 printf(";;\tndots=%u\n", _resp->ndots);
625#endif
626 }
627 } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
628#ifdef DEBUG
629 if (!(_resp->options & RES_DEBUG)) {
630 printf(";; res_setoptions(\"%s\", \"%s\")..\n",
631 options, source);
632 _resp->options |= RES_DEBUG;
633 }
634 printf(";;\tdebug\n");
635#endif
636 } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
637 _resp->options |= RES_USE_INET6;
638 } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) {
639 _resp->options |= RES_INSECURE1;
640 } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) {
641 _resp->options |= RES_INSECURE2;
642 } else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) {
643 _resp->options |= RES_USE_EDNS0;
644 } else {
645 /* XXX - print a warning here? */
646 }
647 /* skip to next run of spaces */
648 while (*cp && *cp != ' ' && *cp != '\t')
649 cp++;
650 }
651}
652
653#ifdef RESOLVSORT
654/* XXX - should really support CIDR which means explicit masks always. */
655static u_int32_t
656net_mask(struct in_addr in) /* XXX - should really use system's version of this */
657{
658 u_int32_t i = ntohl(in.s_addr);
659
660 if (IN_CLASSA(i))
661 return (htonl(IN_CLASSA_NET));
662 else if (IN_CLASSB(i))
663 return (htonl(IN_CLASSB_NET));
664 return (htonl(IN_CLASSC_NET));
665}
666#endif