2 * Copyright (c) 1985, 1989, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. All advertising materials mentioning features or use of this software
14 * must display the following acknowledgement:
15 * This product includes software developed by the University of
16 * California, Berkeley and its contributors.
17 * 4. 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.
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
35 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
37 * Permission to use, copy, modify, and distribute this software for any
38 * purpose with or without fee is hereby granted, provided that the above
39 * copyright notice and this permission notice appear in all copies, and that
40 * the name of Digital Equipment Corporation not be used in advertising or
41 * publicity pertaining to distribution of the document or software without
42 * specific, written prior permission.
44 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
45 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
46 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
47 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
48 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
49 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
50 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
55 * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
56 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
58 * Permission to use, copy, modify, and distribute this software for any
59 * purpose with or without fee is hereby granted, provided that the above
60 * copyright notice and this permission notice appear in all copies.
62 * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
63 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
64 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
65 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
66 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
67 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
68 * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
71 #if defined(LIBC_SCCS) && !defined(lint)
72 static const char sccsid
[] = "@(#)res_init.c 8.1 (Berkeley) 6/7/93";
73 static const char rcsid
[] = "$Id: res_init.c,v 1.23 2007/07/09 01:43:23 marka Exp $";
74 #endif /* LIBC_SCCS and not lint */
76 #include "port_before.h"
79 #include "namespace.h"
81 #include <sys/types.h>
82 #include <sys/param.h>
83 #include <sys/socket.h>
86 #include <netinet/in.h>
87 #include <arpa/inet.h>
88 #include <arpa/nameser.h>
97 #include "un-namespace.h"
100 #include "port_after.h"
102 /* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
105 #include "res_private.h"
107 /*% Options. Should all be left alone. */
112 #include <sys/systeminfo.h>
115 static void res_setoptions
__P((res_state
, const char *, const char *));
118 static const char sort_mask
[] = "/&";
119 #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
120 static u_int32_t net_mask
__P((struct in_addr
));
123 #if !defined(isascii) /*%< XXX - could be a function */
124 # define isascii(c) (!(c & 0200))
128 * Resolver state default settings.
132 * Set up default settings. If the configuration file exist, the values
133 * there will have precedence. Otherwise, the server address is set to
134 * INADDR_ANY and the default domain name comes from the gethostname().
136 * An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
137 * rather than INADDR_ANY ("0.0.0.0") as the default name server address
138 * since it was noted that INADDR_ANY actually meant ``the first interface
139 * you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
140 * it had to be "up" in order for you to reach your own name server. It
141 * was later decided that since the recommended practice is to always
142 * install local static routes through 127.0.0.1 for all your network
143 * interfaces, that we could solve this problem without a code change.
145 * The configuration file should always be used, since it is the only way
146 * to specify a default domain. If you are running a server on your local
147 * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
148 * in the configuration file.
150 * Return 0 if completes successfully, -1 on error
153 res_ninit(res_state statp
) {
154 extern int __res_vinit(res_state
, int);
156 return (__res_vinit(statp
, 0));
159 /*% This function has to be reachable by res_data.c but not publically. */
161 __res_vinit(res_state statp
, int preinit
) {
163 register char *cp
, **pp
;
166 int nserv
= 0; /*%< number of nameserver records read from file */
174 union res_sockaddr_union u
[2];
177 RES_SET_H_ERRNO(statp
, 0);
178 if (statp
->_u
._ext
.ext
!= NULL
)
182 statp
->retrans
= RES_TIMEOUT
;
183 statp
->retry
= RES_DFLRETRY
;
184 statp
->options
= RES_DEFAULT
;
185 statp
->id
= res_randomid();
188 memset(u
, 0, sizeof(u
));
190 u
[nserv
].sin
.sin_addr
= inet_makeaddr(IN_LOOPBACKNET
, 1);
192 u
[nserv
].sin
.sin_addr
.s_addr
= INADDR_ANY
;
194 u
[nserv
].sin
.sin_family
= AF_INET
;
195 u
[nserv
].sin
.sin_port
= htons(NAMESERVER_PORT
);
197 u
[nserv
].sin
.sin_len
= sizeof(struct sockaddr_in
);
200 #ifdef HAS_INET6_STRUCTS
202 u
[nserv
].sin6
.sin6_addr
= in6addr_loopback
;
204 u
[nserv
].sin6
.sin6_addr
= in6addr_any
;
206 u
[nserv
].sin6
.sin6_family
= AF_INET6
;
207 u
[nserv
].sin6
.sin6_port
= htons(NAMESERVER_PORT
);
209 u
[nserv
].sin6
.sin6_len
= sizeof(struct sockaddr_in6
);
220 statp
->_u
._ext
.nscount
= 0;
221 statp
->_u
._ext
.ext
= malloc(sizeof(*statp
->_u
._ext
.ext
));
222 if (statp
->_u
._ext
.ext
!= NULL
) {
223 memset(statp
->_u
._ext
.ext
, 0, sizeof(*statp
->_u
._ext
.ext
));
224 statp
->_u
._ext
.ext
->nsaddrs
[0].sin
= statp
->nsaddr
;
225 strcpy(statp
->_u
._ext
.ext
->nsuffix
, "ip6.arpa");
226 strcpy(statp
->_u
._ext
.ext
->nsuffix2
, "ip6.int");
229 * Historically res_init() rarely, if at all, failed.
230 * Examples and applications exist which do not check
231 * our return code. Furthermore several applications
232 * simply call us to get the systems domainname. So
233 * rather then immediately fail here we store the
234 * failure, which is returned later, in h_errno. And
235 * prevent the collection of 'nameserver' information
236 * by setting maxns to 0. Thus applications that fail
237 * to check our return code wont be able to make
240 RES_SET_H_ERRNO(statp
, NETDB_INTERNAL
);
246 res_setservers(statp
, u
, nserv
);
250 * The old libresolv derived the defaultdomain from NIS/NIS+.
251 * We want to keep this behaviour
254 char buf
[sizeof(statp
->defdname
)], *cp
;
257 if ((ret
= sysinfo(SI_SRPC_DOMAIN
, buf
, sizeof(buf
))) > 0 &&
258 (unsigned int)ret
<= sizeof(buf
)) {
261 cp
= strchr(buf
, '.');
262 cp
= (cp
== NULL
) ? buf
: (cp
+ 1);
263 strncpy(statp
->defdname
, cp
,
264 sizeof(statp
->defdname
) - 1);
265 statp
->defdname
[sizeof(statp
->defdname
) - 1] = '\0';
268 #endif /* SOLARIS2 */
270 /* Allow user to override the local domain definition */
271 if ((cp
= getenv("LOCALDOMAIN")) != NULL
) {
272 (void)strncpy(statp
->defdname
, cp
, sizeof(statp
->defdname
) - 1);
273 statp
->defdname
[sizeof(statp
->defdname
) - 1] = '\0';
277 * Set search list to be blank-separated strings
278 * from rest of env value. Permits users of LOCALDOMAIN
279 * to still have a search list, and anyone to set the
280 * one that they want to use as an individual (even more
281 * important now that the rfc1535 stuff restricts searches)
283 cp
= statp
->defdname
;
286 for (n
= 0; *cp
&& pp
< statp
->dnsrch
+ MAXDNSRCH
; cp
++) {
287 if (*cp
== '\n') /*%< silly backwards compat */
289 else if (*cp
== ' ' || *cp
== '\t') {
298 /* null terminate last domain if there are excess */
299 while (*cp
!= '\0' && *cp
!= ' ' && *cp
!= '\t' && *cp
!= '\n')
305 #define MATCH(line, name) \
306 (!strncmp(line, name, sizeof(name) - 1) && \
307 (line[sizeof(name) - 1] == ' ' || \
308 line[sizeof(name) - 1] == '\t'))
311 if ((fp
= fopen(_PATH_RESCONF
, "r")) != NULL
) {
312 /* read the config file */
313 while (fgets(buf
, sizeof(buf
), fp
) != NULL
) {
315 if (*buf
== ';' || *buf
== '#')
317 /* read default domain name */
318 if (MATCH(buf
, "domain")) {
319 if (haveenv
) /*%< skip if have from environ */
321 cp
= buf
+ sizeof("domain") - 1;
322 while (*cp
== ' ' || *cp
== '\t')
324 if ((*cp
== '\0') || (*cp
== '\n'))
326 strncpy(statp
->defdname
, cp
, sizeof(statp
->defdname
) - 1);
327 statp
->defdname
[sizeof(statp
->defdname
) - 1] = '\0';
328 if ((cp
= strpbrk(statp
->defdname
, " \t\n")) != NULL
)
333 /* set search list */
334 if (MATCH(buf
, "search")) {
335 if (haveenv
) /*%< skip if have from environ */
337 cp
= buf
+ sizeof("search") - 1;
338 while (*cp
== ' ' || *cp
== '\t')
340 if ((*cp
== '\0') || (*cp
== '\n'))
342 strncpy(statp
->defdname
, cp
, sizeof(statp
->defdname
) - 1);
343 statp
->defdname
[sizeof(statp
->defdname
) - 1] = '\0';
344 if ((cp
= strchr(statp
->defdname
, '\n')) != NULL
)
347 * Set search list to be blank-separated strings
350 cp
= statp
->defdname
;
353 for (n
= 0; *cp
&& pp
< statp
->dnsrch
+ MAXDNSRCH
; cp
++) {
354 if (*cp
== ' ' || *cp
== '\t') {
362 /* null terminate last domain if there are excess */
363 while (*cp
!= '\0' && *cp
!= ' ' && *cp
!= '\t')
370 /* read nameservers to query */
371 if (MATCH(buf
, "nameserver") && nserv
< maxns
) {
372 struct addrinfo hints
, *ai
;
373 char sbuf
[NI_MAXSERV
];
374 const size_t minsiz
=
375 sizeof(statp
->_u
._ext
.ext
->nsaddrs
[0]);
377 cp
= buf
+ sizeof("nameserver") - 1;
378 while (*cp
== ' ' || *cp
== '\t')
380 cp
[strcspn(cp
, ";# \t\n")] = '\0';
381 if ((*cp
!= '\0') && (*cp
!= '\n')) {
382 memset(&hints
, 0, sizeof(hints
));
383 hints
.ai_family
= PF_UNSPEC
;
384 hints
.ai_socktype
= SOCK_DGRAM
; /*dummy*/
385 hints
.ai_flags
= AI_NUMERICHOST
;
386 sprintf(sbuf
, "%u", NAMESERVER_PORT
);
387 if (getaddrinfo(cp
, sbuf
, &hints
, &ai
) == 0 &&
388 ai
->ai_addrlen
<= minsiz
) {
389 if (statp
->_u
._ext
.ext
!= NULL
) {
390 memcpy(&statp
->_u
._ext
.ext
->nsaddrs
[nserv
],
391 ai
->ai_addr
, ai
->ai_addrlen
);
393 if (ai
->ai_addrlen
<=
394 sizeof(statp
->nsaddr_list
[nserv
])) {
395 memcpy(&statp
->nsaddr_list
[nserv
],
396 ai
->ai_addr
, ai
->ai_addrlen
);
398 statp
->nsaddr_list
[nserv
].sin_family
= 0;
406 if (MATCH(buf
, "sortlist")) {
409 cp
= buf
+ sizeof("sortlist") - 1;
410 while (nsort
< MAXRESOLVSORT
) {
411 while (*cp
== ' ' || *cp
== '\t')
413 if (*cp
== '\0' || *cp
== '\n' || *cp
== ';')
416 while (*cp
&& !ISSORTMASK(*cp
) && *cp
!= ';' &&
417 isascii(*cp
) && !isspace((unsigned char)*cp
))
421 if (inet_aton(net
, &a
)) {
422 statp
->sort_list
[nsort
].addr
= a
;
426 while (*cp
&& *cp
!= ';' &&
428 !isspace((unsigned char)*cp
))
432 if (inet_aton(net
, &a
)) {
433 statp
->sort_list
[nsort
].mask
= a
.s_addr
;
435 statp
->sort_list
[nsort
].mask
=
436 net_mask(statp
->sort_list
[nsort
].addr
);
439 statp
->sort_list
[nsort
].mask
=
440 net_mask(statp
->sort_list
[nsort
].addr
);
449 if (MATCH(buf
, "options")) {
450 res_setoptions(statp
, buf
+ sizeof("options") - 1, "conf");
455 statp
->nscount
= nserv
;
457 statp
->nsort
= nsort
;
462 * Last chance to get a nameserver. This should not normally
465 #ifdef NO_RESOLV_CONF
467 nserv
= get_nameservers(statp
);
470 if (statp
->defdname
[0] == 0 &&
471 gethostname(buf
, sizeof(statp
->defdname
) - 1) == 0 &&
472 (cp
= strchr(buf
, '.')) != NULL
)
473 strcpy(statp
->defdname
, cp
+ 1);
475 /* find components of local domain that might be searched */
476 if (havesearch
== 0) {
478 *pp
++ = statp
->defdname
;
482 for (cp
= statp
->defdname
; *cp
; cp
++)
483 dots
+= (*cp
== '.');
485 cp
= statp
->defdname
;
486 while (pp
< statp
->dnsrch
+ MAXDFLSRCH
) {
487 if (dots
< LOCALDOMAINPARTS
)
489 cp
= strchr(cp
, '.') + 1; /*%< we know there is one */
495 if (statp
->options
& RES_DEBUG
) {
496 printf(";; res_init()... default dnsrch list:\n");
497 for (pp
= statp
->dnsrch
; *pp
; pp
++)
498 printf(";;\t%s\n", *pp
);
499 printf(";;\t..END..\n");
504 if ((cp
= getenv("RES_OPTIONS")) != NULL
)
505 res_setoptions(statp
, cp
, "env");
506 statp
->options
|= RES_INIT
;
507 return (statp
->res_h_errno
);
511 res_setoptions(res_state statp
, const char *options
, const char *source
)
513 const char *cp
= options
;
516 struct __res_state_ext
*ext
= statp
->_u
._ext
.ext
;
520 if (statp
->options
& RES_DEBUG
)
521 printf(";; res_setoptions(\"%s\", \"%s\")...\n",
525 /* skip leading and inner runs of spaces */
526 while (*cp
== ' ' || *cp
== '\t')
528 /* search for and process individual options */
529 if (!strncmp(cp
, "ndots:", sizeof("ndots:") - 1)) {
530 i
= atoi(cp
+ sizeof("ndots:") - 1);
531 if (i
<= RES_MAXNDOTS
)
534 statp
->ndots
= RES_MAXNDOTS
;
536 if (statp
->options
& RES_DEBUG
)
537 printf(";;\tndots=%d\n", statp
->ndots
);
539 } else if (!strncmp(cp
, "timeout:", sizeof("timeout:") - 1)) {
540 i
= atoi(cp
+ sizeof("timeout:") - 1);
541 if (i
<= RES_MAXRETRANS
)
544 statp
->retrans
= RES_MAXRETRANS
;
546 if (statp
->options
& RES_DEBUG
)
547 printf(";;\ttimeout=%d\n", statp
->retrans
);
550 } else if (!strncmp(cp
, "retrans:", sizeof("retrans:") - 1)) {
552 * For backward compatibility, 'retrans' is
553 * supported as an alias for 'timeout', though
554 * without an imposed maximum.
556 statp
->retrans
= atoi(cp
+ sizeof("retrans:") - 1);
557 } else if (!strncmp(cp
, "retry:", sizeof("retry:") - 1)){
559 * For backward compatibility, 'retry' is
560 * supported as an alias for 'attempts', though
561 * without an imposed maximum.
563 statp
->retry
= atoi(cp
+ sizeof("retry:") - 1);
564 #endif /* SOLARIS2 */
565 } else if (!strncmp(cp
, "attempts:", sizeof("attempts:") - 1)){
566 i
= atoi(cp
+ sizeof("attempts:") - 1);
567 if (i
<= RES_MAXRETRY
)
570 statp
->retry
= RES_MAXRETRY
;
572 if (statp
->options
& RES_DEBUG
)
573 printf(";;\tattempts=%d\n", statp
->retry
);
575 } else if (!strncmp(cp
, "debug", sizeof("debug") - 1)) {
577 if (!(statp
->options
& RES_DEBUG
)) {
578 printf(";; res_setoptions(\"%s\", \"%s\")..\n",
580 statp
->options
|= RES_DEBUG
;
582 printf(";;\tdebug\n");
584 } else if (!strncmp(cp
, "no_tld_query",
585 sizeof("no_tld_query") - 1) ||
586 !strncmp(cp
, "no-tld-query",
587 sizeof("no-tld-query") - 1)) {
588 statp
->options
|= RES_NOTLDQUERY
;
589 } else if (!strncmp(cp
, "inet6", sizeof("inet6") - 1)) {
590 statp
->options
|= RES_USE_INET6
;
591 } else if (!strncmp(cp
, "rotate", sizeof("rotate") - 1)) {
592 statp
->options
|= RES_ROTATE
;
593 } else if (!strncmp(cp
, "no-check-names",
594 sizeof("no-check-names") - 1)) {
595 statp
->options
|= RES_NOCHECKNAME
;
598 else if (!strncmp(cp
, "edns0", sizeof("edns0") - 1)) {
599 statp
->options
|= RES_USE_EDNS0
;
603 else if (!strncmp(cp
, "dname", sizeof("dname") - 1)) {
604 statp
->options
|= RES_USE_DNAME
;
606 else if (!strncmp(cp
, "nibble:", sizeof("nibble:") - 1)) {
609 cp
+= sizeof("nibble:") - 1;
610 i
= MIN(strcspn(cp
, " \t"), sizeof(ext
->nsuffix
) - 1);
611 strncpy(ext
->nsuffix
, cp
, i
);
612 ext
->nsuffix
[i
] = '\0';
614 else if (!strncmp(cp
, "nibble2:", sizeof("nibble2:") - 1)) {
617 cp
+= sizeof("nibble2:") - 1;
618 i
= MIN(strcspn(cp
, " \t"), sizeof(ext
->nsuffix2
) - 1);
619 strncpy(ext
->nsuffix2
, cp
, i
);
620 ext
->nsuffix2
[i
] = '\0';
622 else if (!strncmp(cp
, "v6revmode:", sizeof("v6revmode:") - 1)) {
623 cp
+= sizeof("v6revmode:") - 1;
624 /* "nibble" and "bitstring" used to be valid */
625 if (!strncmp(cp
, "single", sizeof("single") - 1)) {
626 statp
->options
|= RES_NO_NIBBLE2
;
627 } else if (!strncmp(cp
, "both", sizeof("both") - 1)) {
634 /* XXX - print a warning here? */
639 /* skip to next run of spaces */
640 while (*cp
&& *cp
!= ' ' && *cp
!= '\t')
646 /* XXX - should really support CIDR which means explicit masks always. */
648 net_mask(in
) /*!< XXX - should really use system's version of this */
651 register u_int32_t i
= ntohl(in
.s_addr
);
654 return (htonl(IN_CLASSA_NET
));
655 else if (IN_CLASSB(i
))
656 return (htonl(IN_CLASSB_NET
));
657 return (htonl(IN_CLASSC_NET
));
665 gettimeofday(&now
, NULL
);
666 return (0xffff & (now
.tv_sec
^ now
.tv_usec
^ getpid()));
670 * This routine is for closing the socket if a virtual circuit is used and
671 * the program wants to close it. This provides support for endhostent()
672 * which expects to close the socket.
674 * This routine is not expected to be user visible.
677 res_nclose(res_state statp
) {
680 if (statp
->_vcsock
>= 0) {
682 (void) close(statp
->_vcsock
);
684 _close(statp
->_vcsock
);
687 statp
->_flags
&= ~(RES_F_VC
| RES_F_CONN
);
689 for (ns
= 0; ns
< statp
->_u
._ext
.nscount
; ns
++) {
690 if (statp
->_u
._ext
.nssocks
[ns
] != -1) {
692 (void) close(statp
->_u
._ext
.nssocks
[ns
]);
694 _close(statp
->_u
._ext
.nssocks
[ns
]);
696 statp
->_u
._ext
.nssocks
[ns
] = -1;
702 res_ndestroy(res_state statp
) {
704 if (statp
->_u
._ext
.ext
!= NULL
)
705 free(statp
->_u
._ext
.ext
);
706 statp
->options
&= ~RES_INIT
;
707 statp
->_u
._ext
.ext
= NULL
;
712 res_get_nibblesuffix(res_state statp
) {
713 if (statp
->_u
._ext
.ext
)
714 return (statp
->_u
._ext
.ext
->nsuffix
);
719 res_get_nibblesuffix2(res_state statp
) {
720 if (statp
->_u
._ext
.ext
)
721 return (statp
->_u
._ext
.ext
->nsuffix2
);
727 res_setservers(res_state statp
, const union res_sockaddr_union
*set
, int cnt
) {
731 /* close open servers */
734 /* cause rtt times to be forgotten */
735 statp
->_u
._ext
.nscount
= 0;
738 for (i
= 0; i
< cnt
&& nserv
< MAXNS
; i
++) {
739 switch (set
->sin
.sin_family
) {
741 size
= sizeof(set
->sin
);
742 if (statp
->_u
._ext
.ext
)
743 memcpy(&statp
->_u
._ext
.ext
->nsaddrs
[nserv
],
745 if (size
<= sizeof(statp
->nsaddr_list
[nserv
]))
746 memcpy(&statp
->nsaddr_list
[nserv
],
749 statp
->nsaddr_list
[nserv
].sin_family
= 0;
753 #ifdef HAS_INET6_STRUCTS
755 size
= sizeof(set
->sin6
);
756 if (statp
->_u
._ext
.ext
)
757 memcpy(&statp
->_u
._ext
.ext
->nsaddrs
[nserv
],
759 if (size
<= sizeof(statp
->nsaddr_list
[nserv
]))
760 memcpy(&statp
->nsaddr_list
[nserv
],
763 statp
->nsaddr_list
[nserv
].sin_family
= 0;
773 statp
->nscount
= nserv
;
778 res_getservers(res_state statp
, union res_sockaddr_union
*set
, int cnt
) {
783 for (i
= 0; i
< statp
->nscount
&& i
< cnt
; i
++) {
784 if (statp
->_u
._ext
.ext
)
785 family
= statp
->_u
._ext
.ext
->nsaddrs
[i
].sin
.sin_family
;
787 family
= statp
->nsaddr_list
[i
].sin_family
;
791 size
= sizeof(set
->sin
);
792 if (statp
->_u
._ext
.ext
)
794 &statp
->_u
._ext
.ext
->nsaddrs
[i
],
797 memcpy(&set
->sin
, &statp
->nsaddr_list
[i
],
801 #ifdef HAS_INET6_STRUCTS
803 size
= sizeof(set
->sin6
);
804 if (statp
->_u
._ext
.ext
)
806 &statp
->_u
._ext
.ext
->nsaddrs
[i
],
809 memcpy(&set
->sin6
, &statp
->nsaddr_list
[i
],
815 set
->sin
.sin_family
= 0;
820 return (statp
->nscount
);