/*
*/
/*
* Copyright (c) 1985, 1989, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
/*
* Portions Copyright (c) 1993 by Digital Equipment Corporation.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies, and that
* the name of Digital Equipment Corporation not be used in advertising or
* publicity pertaining to distribution of the document or software without
* specific, written prior permission.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
* WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
* OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL DIGITAL EQUIPMENT
* CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
* DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
* PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
* ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
* SOFTWARE.
*/
/*
* Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
* Portions Copyright (c) 1996-1999 by Internet Software Consortium.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
* copyright notice and this permission notice appear in all copies.
*
* THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
* WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
* MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL ISC BE LIABLE FOR
* ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
* WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
* OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
#endif /* LIBC_SCCS and not lint */
#include "port_before.h"
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <netdb.h>
#ifndef HAVE_MD5
#else
# ifdef SOLARIS2
# endif
#endif
#ifndef _MD5_H_
#endif
#include "port_after.h"
/* ensure that sockaddr_in6 and IN6ADDR_ANY_INIT are declared / defined */
#include <resolv.h>
/* ISC purposely put port_after.h before <resolv.h> to force in6 stuff
* (above) so we explicitly include port_resolv.h here */
#include "port_resolv.h"
#include "res_private.h"
/*% Options. Should all be left alone. */
#define RESOLVSORT
#define DEBUG
#ifdef SUNW_INITCHKIF
#include <netinet/if_ether.h>
#endif /* SUNW_INITCHKIF */
#ifdef SOLARIS2
#include <sys/systeminfo.h>
#endif
#ifdef RESOLVSORT
#endif
#if !defined(isascii) /*%< XXX - could be a function */
#endif
/*
* Resolver state default settings.
*/
/*%
* Set up default settings. If the configuration file exist, the values
* there will have precedence. Otherwise, the server address is set to
* INADDR_ANY and the default domain name comes from the gethostname().
*
* An interrim version of this code (BIND 4.9, pre-4.4BSD) used 127.0.0.1
* rather than INADDR_ANY ("0.0.0.0") as the default name server address
* since it was noted that INADDR_ANY actually meant ``the first interface
* you "ifconfig"'d at boot time'' and if this was a SLIP or PPP interface,
* it had to be "up" in order for you to reach your own name server. It
* was later decided that since the recommended practice is to always
* install local static routes through 127.0.0.1 for all your network
* interfaces, that we could solve this problem without a code change.
*
* The configuration file should always be used, since it is the only way
* to specify a default domain. If you are running a server on your local
* machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
* in the configuration file.
*
* Return 0 if completes successfully, -1 on error
*/
int
extern int __res_vinit(res_state, int);
return (__res_vinit(statp, 0));
}
/*% This function has to be reachable by res_data.c but not publically. */
int
register int n;
int haveenv = 0;
int havesearch = 0;
#ifdef RESOLVSORT
int nsort = 0;
char *net;
#endif
int dots;
union res_sockaddr_union u[2];
RES_SET_H_ERRNO(statp, 0);
if (!preinit) {
}
memset(u, 0, sizeof(u));
#ifdef USELOOPBACK
#else
#endif
#ifdef HAVE_SA_LEN
#endif
nserv++;
#ifdef HAS_INET6_STRUCTS
#ifdef USELOOPBACK
#else
#endif
#ifdef HAVE_SA_LEN
#endif
nserv++;
#endif
} else {
/*
* Historically res_init() rarely, if at all, failed.
* Examples and applications exist which do not check
* our return code. Furthermore several applications
* simply call us to get the systems domainname. So
* rather then immediately fail here we store the
* failure, which is returned later, in h_errno. And
* prevent the collection of 'nameserver' information
* by setting maxns to 0. Thus applications that fail
* to check our return code wont be able to make
* queries anyhow.
*/
maxns = 0;
}
#ifdef RESOLVSORT
#endif
#ifdef SUNW_INITCHKIF
/*
* Short circuit res_init() if no non-loopback interfaces are up. This is
* done to avoid boot delays if "dns" comes before "files" in nsswitch.conf.
* An additional fix has been added to this code, to count all external
* interfaces, which includes the IPv6 interfaces. If no external interfaces
* are found, an additional check is carried out to determine if any deprecated
* interfaces are up.
*/
{
int s;
perror("res_init: socket");
goto freedata;
}
close(s);
goto freedata;
}
if (lifn.lifn_count == 0) {
/*
* Check if there are any deprecated interfaces up
*/
lifn.lifn_flags = 0;
close(s);
goto freedata;
}
close(s);
goto freedata;
}
lifc.lifc_flags = 0;
close(s);
goto freedata;
}
for (i = 0; i < lifn.lifn_count; ++i) {
close(s);
goto freedata;
}
int_up = 1;
break;
}
}
if (!int_up) {
close(s);
goto freedata;
}
}
close(s);
}
#endif /* SUNW_INITCHKIF */
#ifdef SOLARIS2
/*
* We want to keep this behaviour
*/
{
int ret;
if (buf[0] == '+')
buf[0] = '.';
}
}
#endif /* SOLARIS2 */
/* Allow user to override the local domain definition */
haveenv++;
/*
* Set search list to be blank-separated strings
* from rest of env value. Permits users of LOCALDOMAIN
* to still have a search list, and anyone to set the
* one that they want to use as an individual (even more
* important now that the rfc1535 stuff restricts searches)
*/
break;
*cp = 0;
n = 1;
} else if (n) {
n = 0;
havesearch = 1;
}
}
/* null terminate last domain if there are excess */
cp++;
*cp = '\0';
*pp++ = 0;
}
nserv = 0;
/* read the config file */
/* skip comments */
continue;
/* read default domain name */
if (haveenv) /*%< skip if have from environ */
continue;
cp++;
continue;
*cp = '\0';
havesearch = 0;
continue;
}
/* set search list */
if (haveenv) /*%< skip if have from environ */
continue;
cp++;
continue;
*cp = '\0';
/*
* Set search list to be blank-separated strings
* on rest of line.
*/
*cp = 0;
n = 1;
} else if (n) {
n = 0;
}
}
/* null terminate last domain if there are excess */
cp++;
*cp = '\0';
*pp++ = 0;
havesearch = 1;
continue;
}
/* read nameservers to query */
cp++;
}
if (ai->ai_addrlen <=
} else
nserv++;
}
}
continue;
}
#ifdef RESOLVSORT
struct in_addr a;
while (nsort < MAXRESOLVSORT) {
cp++;
break;
cp++;
n = *cp;
*cp = 0;
if (ISSORTMASK(n)) {
*cp++ = n;
cp++;
n = *cp;
*cp = 0;
} else {
}
} else {
}
nsort++;
}
*cp = n;
}
continue;
}
#endif
continue;
}
}
if (nserv > 0)
#ifdef RESOLVSORT
#endif
}
/*
* Last chance to get a nameserver. This should not normally
* be necessary
*/
#ifdef NO_RESOLV_CONF
if(nserv == 0)
#endif
/* find components of local domain that might be searched */
if (havesearch == 0) {
dots = 0;
if (dots < LOCALDOMAINPARTS)
break;
dots--;
}
#ifdef DEBUG
printf(";; res_init()... default dnsrch list:\n");
printf(";;\t..END..\n");
}
#endif
}
return (statp->res_h_errno);
#ifdef SUNW_INITCHKIF
}
return (-1);
#endif /* SUNW_INITCHKIF */
}
static void
{
int i;
#ifdef DEBUG
printf(";; res_setoptions(\"%s\", \"%s\")...\n",
#endif
while (*cp) {
/* skip leading and inner runs of spaces */
cp++;
/* search for and process individual options */
if (i <= RES_MAXNDOTS)
else
#ifdef DEBUG
#endif
if (i <= RES_MAXRETRANS)
else
#ifdef DEBUG
#endif
#ifdef SOLARIS2
/*
* For backward compatibility, 'retrans' is
* supported as an alias for 'timeout', though
* without an imposed maximum.
*/
/*
* For backward compatibility, 'retry' is
* supported as an alias for 'attempts', though
* without an imposed maximum.
*/
#endif /* SOLARIS2 */
if (i <= RES_MAXRETRY)
else
#ifdef DEBUG
#endif
#ifdef DEBUG
printf(";; res_setoptions(\"%s\", \"%s\")..\n",
}
printf(";;\tdebug\n");
#endif
sizeof("no_tld_query") - 1) ||
sizeof("no-tld-query") - 1)) {
sizeof("no-check-names") - 1)) {
}
#ifdef RES_USE_EDNS0
}
#endif
}
goto skip;
}
goto skip;
}
/* "nibble" and "bitstring" used to be valid */
}
}
else {
/* XXX - print a warning here? */
}
skip:
/* skip to next run of spaces */
cp++;
}
}
#ifdef RESOLVSORT
/* XXX - should really support CIDR which means explicit masks always. */
static u_int32_t
{
if (IN_CLASSA(i))
return (htonl(IN_CLASSA_NET));
else if (IN_CLASSB(i))
return (htonl(IN_CLASSB_NET));
return (htonl(IN_CLASSC_NET));
}
#endif
void
{
}
#ifndef HAVE_MD5
#else
#endif
}
/*%
* This routine is for closing the socket if a virtual circuit is used and
* the program wants to close it. This provides support for endhostent()
* which expects to close the socket.
*
* This routine is not expected to be user visible.
*/
void
int ns;
}
}
}
}
void
}
const char *
return ("ip6.arpa");
}
const char *
return ("ip6.int");
}
void
int i, nserv;
/* close open servers */
/* cause rtt times to be forgotten */
nserv = 0;
case AF_INET:
else
nserv++;
break;
#ifdef HAS_INET6_STRUCTS
case AF_INET6:
else
nserv++;
break;
#endif
default:
break;
}
set++;
}
}
int
int i;
else
switch (family) {
case AF_INET:
size);
else
size);
break;
#ifdef HAS_INET6_STRUCTS
case AF_INET6:
size);
else
size);
break;
#endif
default:
break;
}
set++;
}
}
/*! \file */