Lines Matching +full:resolver +full:- +full:to +full:- +full:digital

1 /*-
2 * SPDX-License-Identifier: (BSD-3-Clause AND ISC)
16 * may be used to endorse or promote products derived from this software
20 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
33 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
35 * Permission to use, copy, modify, and distribute this software for any
38 * the name of Digital Equipment Corporation not be used in advertising or
39 * publicity pertaining to distribution of the document or software without
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
54 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
56 * Permission to use, copy, modify, and distribute this software for any
61 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
102 #include "un-namespace.h"
129 #if !defined(isascii) /*%< XXX - could be a function */
134 * Resolver state default settings.
139 * there will have precedence. Otherwise, the server address is set to
142 * An interim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
146 * it had to be "up" in order for you to reach your own name server. It
147 * was later decided that since the recommended practice is to always
152 * to specify a default domain. If you are running a server on your local
156 * Return 0 if completes successfully, -1 on error
165 /*% This function has to be reachable by res_data.c but not publicly. */
184 if (statp->_u._ext.ext != NULL) in __res_vinit()
188 statp->retrans = RES_TIMEOUT; in __res_vinit()
189 statp->retry = RES_DFLRETRY; in __res_vinit()
190 statp->options = RES_DEFAULT; in __res_vinit()
193 statp->_rnd = malloc(16); in __res_vinit()
195 statp->id = res_nrandomid(statp); in __res_vinit()
214 statp->nscount = 0; in __res_vinit()
215 statp->ndots = 1; in __res_vinit()
216 statp->pfcode = 0; in __res_vinit()
217 statp->_vcsock = -1; in __res_vinit()
218 statp->_flags = 0; in __res_vinit()
219 statp->qhook = NULL; in __res_vinit()
220 statp->rhook = NULL; in __res_vinit()
221 statp->_u._ext.nscount = 0; in __res_vinit()
222 statp->_u._ext.ext = malloc(sizeof(*statp->_u._ext.ext)); in __res_vinit()
223 if (statp->_u._ext.ext != NULL) { in __res_vinit()
224 memset(statp->_u._ext.ext, 0, sizeof(*statp->_u._ext.ext)); in __res_vinit()
225 statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr; in __res_vinit()
226 strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa"); in __res_vinit()
227 strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int"); in __res_vinit()
228 statp->_u._ext.ext->reload_period = 2; in __res_vinit()
234 * simply call us to get the systems domainname. So in __res_vinit()
238 * by setting maxns to 0. Thus applications that fail in __res_vinit()
239 * to check our return code wont be able to make in __res_vinit()
246 statp->nsort = 0; in __res_vinit()
253 * We want to keep this behaviour in __res_vinit()
256 char buf[sizeof(statp->defdname)], *cp; in __res_vinit()
265 strncpy(statp->defdname, cp, in __res_vinit()
266 sizeof(statp->defdname) - 1); in __res_vinit()
267 statp->defdname[sizeof(statp->defdname) - 1] = '\0'; in __res_vinit()
272 /* Allow user to override the local domain definition */ in __res_vinit()
274 (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); in __res_vinit()
275 statp->defdname[sizeof(statp->defdname) - 1] = '\0'; in __res_vinit()
279 * Set search list to be blank-separated strings in __res_vinit()
281 * to still have a search list, and anyone to set the in __res_vinit()
282 * one that they want to use as an individual (even more in __res_vinit()
285 cp = statp->defdname; in __res_vinit()
286 pp = statp->dnsrch; in __res_vinit()
288 for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { in __res_vinit()
308 (!strncmp(line, name, sizeof(name) - 1) && \ in __res_vinit()
309 (line[sizeof(name) - 1] == ' ' || \ in __res_vinit()
310 line[sizeof(name) - 1] == '\t')) in __res_vinit()
317 if (statp->_u._ext.ext != NULL) { in __res_vinit()
319 statp->_u._ext.ext->conf_mtim = sb.st_mtim; in __res_vinit()
321 statp->_u._ext.ext->conf_stat = now.tv_sec; in __res_vinit()
335 cp = buf + sizeof("domain") - 1; in __res_vinit()
340 strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); in __res_vinit()
341 statp->defdname[sizeof(statp->defdname) - 1] = '\0'; in __res_vinit()
342 if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL) in __res_vinit()
351 cp = buf + sizeof("search") - 1; in __res_vinit()
356 strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1); in __res_vinit()
357 statp->defdname[sizeof(statp->defdname) - 1] = '\0'; in __res_vinit()
358 if ((cp = strchr(statp->defdname, '\n')) != NULL) in __res_vinit()
361 * Set search list to be blank-separated strings in __res_vinit()
364 cp = statp->defdname; in __res_vinit()
365 pp = statp->dnsrch; in __res_vinit()
367 for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) { in __res_vinit()
384 /* read nameservers to query */ in __res_vinit()
389 sizeof(statp->_u._ext.ext->nsaddrs[0]); in __res_vinit()
391 cp = buf + sizeof("nameserver") - 1; in __res_vinit()
402 if (ai->ai_addrlen <= minsiz) { in __res_vinit()
403 if (statp->_u._ext.ext != NULL) { in __res_vinit()
404 memcpy(&statp->_u._ext.ext->nsaddrs[nserv], in __res_vinit()
405 ai->ai_addr, ai->ai_addrlen); in __res_vinit()
407 if (ai->ai_addrlen <= in __res_vinit()
408 sizeof(statp->nsaddr_list[nserv])) { in __res_vinit()
409 memcpy(&statp->nsaddr_list[nserv], in __res_vinit()
410 ai->ai_addr, ai->ai_addrlen); in __res_vinit()
412 statp->nsaddr_list[nserv].sin_family = 0; in __res_vinit()
426 struct __res_state_ext *ext = statp->_u._ext.ext; in __res_vinit()
428 cp = buf + sizeof("sortlist") - 1; in __res_vinit()
441 statp->sort_list[nsort].addr = a; in __res_vinit()
452 statp->sort_list[nsort].mask = a.s_addr; in __res_vinit()
454 statp->sort_list[nsort].mask = in __res_vinit()
455 net_mask(statp->sort_list[nsort].addr); in __res_vinit()
458 statp->sort_list[nsort].mask = in __res_vinit()
459 net_mask(statp->sort_list[nsort].addr); in __res_vinit()
461 ext->sort_list[nsort].af = AF_INET; in __res_vinit()
462 ext->sort_list[nsort].addr.ina = in __res_vinit()
463 statp->sort_list[nsort].addr; in __res_vinit()
464 ext->sort_list[nsort].mask.ina.s_addr = in __res_vinit()
465 statp->sort_list[nsort].mask; in __res_vinit()
470 ext->sort_list[nsort].af = AF_INET6; in __res_vinit()
471 ext->sort_list[nsort].addr.in6a = a6; in __res_vinit()
472 u = (u_char *)&ext->sort_list[nsort].mask.in6a; in __res_vinit()
487 m = -1; in __res_vinit()
500 m -= CHAR_BIT; in __res_vinit()
503 *u <<= -m; in __res_vinit()
508 statp->sort_list[nsort].addr.s_addr = in __res_vinit()
510 statp->sort_list[nsort].mask = in __res_vinit()
520 res_setoptions(statp, buf + sizeof("options") - 1, "conf"); in __res_vinit()
525 statp->nscount = nserv; in __res_vinit()
527 statp->nsort = nsort; in __res_vinit()
532 * Last chance to get a nameserver. This should not normally in __res_vinit()
540 if (statp->defdname[0] == 0 && in __res_vinit()
541 gethostname(buf, sizeof(statp->defdname) - 1) == 0 && in __res_vinit()
543 strcpy(statp->defdname, cp + 1); in __res_vinit()
547 pp = statp->dnsrch; in __res_vinit()
548 *pp++ = statp->defdname; in __res_vinit()
552 for (cp = statp->defdname; *cp; cp++) in __res_vinit()
555 cp = statp->defdname; in __res_vinit()
556 while (pp < statp->dnsrch + MAXDFLSRCH) { in __res_vinit()
561 dots--; in __res_vinit()
565 if (statp->options & RES_DEBUG) { in __res_vinit()
567 for (pp = statp->dnsrch; *pp; pp++) in __res_vinit()
575 statp->options |= RES_NOALIASES; in __res_vinit()
578 statp->options |= RES_INIT; in __res_vinit()
579 return (statp->res_h_errno); in __res_vinit()
587 struct __res_state_ext *ext = statp->_u._ext.ext; in res_setoptions()
590 if (statp->options & RES_DEBUG) in res_setoptions()
599 if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) { in res_setoptions()
600 i = atoi(cp + sizeof("ndots:") - 1); in res_setoptions()
602 statp->ndots = i; in res_setoptions()
604 statp->ndots = RES_MAXNDOTS; in res_setoptions()
606 if (statp->options & RES_DEBUG) in res_setoptions()
607 printf(";;\tndots=%d\n", statp->ndots); in res_setoptions()
609 } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) { in res_setoptions()
610 i = atoi(cp + sizeof("timeout:") - 1); in res_setoptions()
612 statp->retrans = i; in res_setoptions()
614 statp->retrans = RES_MAXRETRANS; in res_setoptions()
616 if (statp->options & RES_DEBUG) in res_setoptions()
617 printf(";;\ttimeout=%d\n", statp->retrans); in res_setoptions()
620 } else if (!strncmp(cp, "retrans:", sizeof("retrans:") - 1)) { in res_setoptions()
626 statp->retrans = atoi(cp + sizeof("retrans:") - 1); in res_setoptions()
627 } else if (!strncmp(cp, "retry:", sizeof("retry:") - 1)){ in res_setoptions()
633 statp->retry = atoi(cp + sizeof("retry:") - 1); in res_setoptions()
635 } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){ in res_setoptions()
636 i = atoi(cp + sizeof("attempts:") - 1); in res_setoptions()
638 statp->retry = i; in res_setoptions()
640 statp->retry = RES_MAXRETRY; in res_setoptions()
642 if (statp->options & RES_DEBUG) in res_setoptions()
643 printf(";;\tattempts=%d\n", statp->retry); in res_setoptions()
645 } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) { in res_setoptions()
647 if (!(statp->options & RES_DEBUG)) { in res_setoptions()
650 statp->options |= RES_DEBUG; in res_setoptions()
655 sizeof("no_tld_query") - 1) || in res_setoptions()
656 !strncmp(cp, "no-tld-query", in res_setoptions()
657 sizeof("no-tld-query") - 1)) { in res_setoptions()
658 statp->options |= RES_NOTLDQUERY; in res_setoptions()
659 } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) { in res_setoptions()
660 statp->options |= RES_USE_INET6; in res_setoptions()
661 } else if (!strncmp(cp, "insecure1", sizeof("insecure1") - 1)) { in res_setoptions()
662 statp->options |= RES_INSECURE1; in res_setoptions()
663 } else if (!strncmp(cp, "insecure2", sizeof("insecure2") - 1)) { in res_setoptions()
664 statp->options |= RES_INSECURE2; in res_setoptions()
665 } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) { in res_setoptions()
666 statp->options |= RES_ROTATE; in res_setoptions()
667 } else if (!strncmp(cp, "usevc", sizeof("usevc") - 1)) { in res_setoptions()
668 statp->options |= RES_USEVC; in res_setoptions()
669 } else if (!strncmp(cp, "no-check-names", in res_setoptions()
670 sizeof("no-check-names") - 1)) { in res_setoptions()
671 statp->options |= RES_NOCHECKNAME; in res_setoptions()
672 } else if (!strncmp(cp, "reload-period:", in res_setoptions()
673 sizeof("reload-period:") - 1)) { in res_setoptions()
675 ext->reload_period = (u_short) in res_setoptions()
676 atoi(cp + sizeof("reload-period:") - 1); in res_setoptions()
680 else if (!strncmp(cp, "edns0", sizeof("edns0") - 1)) { in res_setoptions()
681 statp->options |= RES_USE_EDNS0; in res_setoptions()
685 else if (!strncmp(cp, "dname", sizeof("dname") - 1)) { in res_setoptions()
686 statp->options |= RES_USE_DNAME; in res_setoptions()
688 else if (!strncmp(cp, "nibble:", sizeof("nibble:") - 1)) { in res_setoptions()
691 cp += sizeof("nibble:") - 1; in res_setoptions()
692 i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix) - 1); in res_setoptions()
693 strncpy(ext->nsuffix, cp, i); in res_setoptions()
694 ext->nsuffix[i] = '\0'; in res_setoptions()
696 else if (!strncmp(cp, "nibble2:", sizeof("nibble2:") - 1)) { in res_setoptions()
699 cp += sizeof("nibble2:") - 1; in res_setoptions()
700 i = MIN(strcspn(cp, " \t"), sizeof(ext->nsuffix2) - 1); in res_setoptions()
701 strncpy(ext->nsuffix2, cp, i); in res_setoptions()
702 ext->nsuffix2[i] = '\0'; in res_setoptions()
704 else if (!strncmp(cp, "v6revmode:", sizeof("v6revmode:") - 1)) { in res_setoptions()
705 cp += sizeof("v6revmode:") - 1; in res_setoptions()
706 /* "nibble" and "bitstring" used to be valid */ in res_setoptions()
707 if (!strncmp(cp, "single", sizeof("single") - 1)) { in res_setoptions()
708 statp->options |= RES_NO_NIBBLE2; in res_setoptions()
709 } else if (!strncmp(cp, "both", sizeof("both") - 1)) { in res_setoptions()
710 statp->options &= in res_setoptions()
716 /* XXX - print a warning here? */ in res_setoptions()
721 /* skip to next run of spaces */ in res_setoptions()
728 /* XXX - should really support CIDR which means explicit masks always. */
730 net_mask(struct in_addr in) /*!< XXX - should really use system's version of this */ in net_mask()
750 u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd; in res_rndinit()
768 u_char *rnd = statp->_rnd == NULL ? srnd : statp->_rnd; in res_nrandomid()
788 * the program wants to close it. This provides support for endhostent()
789 * which expects to close the socket.
791 * This routine is not expected to be user visible.
797 if (statp->_vcsock >= 0) { in res_nclose()
798 (void) _close(statp->_vcsock); in res_nclose()
799 statp->_vcsock = -1; in res_nclose()
800 statp->_flags &= ~(RES_F_VC | RES_F_CONN); in res_nclose()
802 for (ns = 0; ns < statp->_u._ext.nscount; ns++) { in res_nclose()
803 if (statp->_u._ext.nssocks[ns] != -1) { in res_nclose()
804 (void) _close(statp->_u._ext.nssocks[ns]); in res_nclose()
805 statp->_u._ext.nssocks[ns] = -1; in res_nclose()
813 if (statp->_u._ext.ext != NULL) { in res_ndestroy()
814 free(statp->_u._ext.ext); in res_ndestroy()
815 statp->_u._ext.ext = NULL; in res_ndestroy()
817 if (statp->_rnd != NULL) { in res_ndestroy()
818 free(statp->_rnd); in res_ndestroy()
819 statp->_rnd = NULL; in res_ndestroy()
821 statp->options &= ~RES_INIT; in res_ndestroy()
827 if (statp->_u._ext.ext) in res_get_nibblesuffix()
828 return (statp->_u._ext.ext->nsuffix); in res_get_nibblesuffix()
834 if (statp->_u._ext.ext) in res_get_nibblesuffix2()
835 return (statp->_u._ext.ext->nsuffix2); in res_get_nibblesuffix2()
848 /* cause rtt times to be forgotten */ in res_setservers()
849 statp->_u._ext.nscount = 0; in res_setservers()
853 switch (set->sin.sin_family) { in res_setservers()
855 size = sizeof(set->sin); in res_setservers()
856 if (statp->_u._ext.ext) in res_setservers()
857 memcpy(&statp->_u._ext.ext->nsaddrs[nserv], in res_setservers()
858 &set->sin, size); in res_setservers()
859 if (size <= sizeof(statp->nsaddr_list[nserv])) in res_setservers()
860 memcpy(&statp->nsaddr_list[nserv], in res_setservers()
861 &set->sin, size); in res_setservers()
863 statp->nsaddr_list[nserv].sin_family = 0; in res_setservers()
869 size = sizeof(set->sin6); in res_setservers()
870 if (statp->_u._ext.ext) in res_setservers()
871 memcpy(&statp->_u._ext.ext->nsaddrs[nserv], in res_setservers()
872 &set->sin6, size); in res_setservers()
873 if (size <= sizeof(statp->nsaddr_list[nserv])) in res_setservers()
874 memcpy(&statp->nsaddr_list[nserv], in res_setservers()
875 &set->sin6, size); in res_setservers()
877 statp->nsaddr_list[nserv].sin_family = 0; in res_setservers()
887 statp->nscount = nserv; in res_setservers()
897 for (i = 0; i < statp->nscount && i < cnt; i++) { in res_getservers()
898 if (statp->_u._ext.ext) in res_getservers()
899 family = statp->_u._ext.ext->nsaddrs[i].sin.sin_family; in res_getservers()
901 family = statp->nsaddr_list[i].sin_family; in res_getservers()
905 size = sizeof(set->sin); in res_getservers()
906 if (statp->_u._ext.ext) in res_getservers()
907 memcpy(&set->sin, in res_getservers()
908 &statp->_u._ext.ext->nsaddrs[i], in res_getservers()
911 memcpy(&set->sin, &statp->nsaddr_list[i], in res_getservers()
917 size = sizeof(set->sin6); in res_getservers()
918 if (statp->_u._ext.ext) in res_getservers()
919 memcpy(&set->sin6, in res_getservers()
920 &statp->_u._ext.ext->nsaddrs[i], in res_getservers()
923 memcpy(&set->sin6, &statp->nsaddr_list[i], in res_getservers()
929 set->sin.sin_family = 0; in res_getservers()
934 return (statp->nscount); in res_getservers()