OpenCores
URL https://opencores.org/ocsvn/openrisc/openrisc/trunk

Subversion Repositories openrisc

[/] [openrisc/] [tags/] [gnu-src/] [newlib-1.18.0/] [newlib-1.18.0-or32-1.0rc2/] [newlib/] [libc/] [sys/] [linux/] [net/] [res_init.c] - Diff between revs 207 and 520

Only display areas with differences | Details | Blame | View Log

Rev 207 Rev 520
/*
/*
 * Copyright (c) 1985, 1989, 1993
 * Copyright (c) 1985, 1989, 1993
 *    The Regents of the University of California.  All rights reserved.
 *    The Regents of the University of California.  All rights reserved.
 *
 *
 * Redistribution and use in source and binary forms, with or without
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * modification, are permitted provided that the following conditions
 * are met:
 * are met:
 * 1. Redistributions of source code must retain the above copyright
 * 1. Redistributions of source code must retain the above copyright
 *    notice, this list of conditions and the following disclaimer.
 *    notice, this list of conditions and the following disclaimer.
 * 2. Redistributions in binary form must reproduce the above copyright
 * 2. Redistributions in binary form must reproduce the above copyright
 *    notice, this list of conditions and the following disclaimer in the
 *    notice, this list of conditions and the following disclaimer in the
 *    documentation and/or other materials provided with the distribution.
 *    documentation and/or other materials provided with the distribution.
 * 4. Neither the name of the University nor the names of 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
 *    may be used to endorse or promote products derived from this software
 *    without specific prior written permission.
 *    without specific prior written permission.
 *
 *
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
 * 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
 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
 * SUCH DAMAGE.
 * SUCH DAMAGE.
 */
 */
 
 
/*
/*
 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
 * Portions Copyright (c) 1993 by Digital Equipment Corporation.
 *
 *
 * Permission to use, copy, modify, and distribute this software for any
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies, and that
 * copyright notice and this permission notice appear in all copies, and that
 * the name of Digital Equipment Corporation not be used in advertising or
 * the name of Digital Equipment Corporation not be used in advertising or
 * publicity pertaining to distribution of the document or software without
 * publicity pertaining to distribution of the document or software without
 * specific, written prior permission.
 * specific, written prior permission.
 *
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
 * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS ALL
 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
 * WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
 * OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL EQUIPMENT
 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * 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
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 * SOFTWARE.
 */
 */
 
 
/*
/*
 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
 * Portions Copyright (c) 1996-1999 by Internet Software Consortium.
 *
 *
 * Permission to use, copy, modify, and distribute this software for any
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 * copyright notice and this permission notice appear in all copies.
 *
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * THE SOFTWARE IS PROVIDED "AS IS" AND INTERNET SOFTWARE CONSORTIUM DISCLAIMS
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL INTERNET SOFTWARE
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * CONSORTIUM BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
 * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS
 * 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
 * ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 * SOFTWARE.
 */
 */
 
 
#if defined(LIBC_SCCS) && !defined(lint)
#if defined(LIBC_SCCS) && !defined(lint)
static const char sccsid[] = "@(#)res_init.c    8.1 (Berkeley) 6/7/93";
static const char sccsid[] = "@(#)res_init.c    8.1 (Berkeley) 6/7/93";
static const char rcsid[] = "$BINDId: res_init.c,v 8.16 2000/05/09 07:10:12 vixie Exp $";
static const char rcsid[] = "$BINDId: res_init.c,v 8.16 2000/05/09 07:10:12 vixie Exp $";
#endif /* LIBC_SCCS and not lint */
#endif /* LIBC_SCCS and not lint */
 
 
#include <sys/types.h>
#include <sys/types.h>
#include <sys/param.h>
#include <sys/param.h>
#include <sys/socket.h>
#include <sys/socket.h>
#include <sys/time.h>
#include <sys/time.h>
 
 
#include <netinet/in.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <arpa/inet.h>
#include <arpa/nameser.h>
#include <arpa/nameser.h>
 
 
#include <ctype.h>
#include <ctype.h>
#include <stdio.h>
#include <stdio.h>
#include <stdio_ext.h>
#include <stdio_ext.h>
#include <stdlib.h>
#include <stdlib.h>
#include <string.h>
#include <string.h>
#include <unistd.h>
#include <unistd.h>
 
 
#include <not-cancel.h>
#include <not-cancel.h>
#include "local.h"
#include "local.h"
#include <resolv.h>
#include <resolv.h>
 
 
/* Options.  Should all be left alone. */
/* Options.  Should all be left alone. */
#define RESOLVSORT
#define RESOLVSORT
#define RFC1535
#define RFC1535
/* #undef DEBUG */
/* #undef DEBUG */
 
 
static void res_setoptions (res_state, const char *, const char *)
static void res_setoptions (res_state, const char *, const char *)
     internal_function;
     internal_function;
 
 
#ifdef RESOLVSORT
#ifdef RESOLVSORT
static const char sort_mask_chars[] = "/&";
static const char sort_mask_chars[] = "/&";
#define ISSORTMASK(ch) (strchr(sort_mask_chars, ch) != NULL)
#define ISSORTMASK(ch) (strchr(sort_mask_chars, ch) != NULL)
static u_int32_t net_mask (struct in_addr) __THROW;
static u_int32_t net_mask (struct in_addr) __THROW;
#endif
#endif
 
 
#if !defined(isascii)   /* XXX - could be a function */
#if !defined(isascii)   /* XXX - could be a function */
# define isascii(c) (!(c & 0200))
# define isascii(c) (!(c & 0200))
#endif
#endif
 
 
#ifdef _LIBC
#ifdef _LIBC
unsigned long long int __res_initstamp attribute_hidden;
unsigned long long int __res_initstamp attribute_hidden;
#endif
#endif
 
 
/*
/*
 * Resolver state default settings.
 * Resolver state default settings.
 */
 */
 
 
/*
/*
 * Set up default settings.  If the configuration file exist, the values
 * Set up default settings.  If the configuration file exist, the values
 * there will have precedence.  Otherwise, the server address is set to
 * there will have precedence.  Otherwise, the server address is set to
 * INADDR_ANY and the default domain name comes from the gethostname().
 * 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
 * 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
 * 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
 * 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,
 * 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
 * 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
 * was later decided that since the recommended practice is to always
 * install local static routes through 127.0.0.1 for all your network
 * install local static routes through 127.0.0.1 for all your network
 * interfaces, that we could solve this problem without a code change.
 * interfaces, that we could solve this problem without a code change.
 *
 *
 * The configuration file should always be used, since it is the only way
 * 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
 * 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"
 * machine, you should say "nameserver 0.0.0.0" or "nameserver 127.0.0.1"
 * in the configuration file.
 * in the configuration file.
 *
 *
 * Return 0 if completes successfully, -1 on error
 * Return 0 if completes successfully, -1 on error
 */
 */
int
int
res_ninit(res_state statp) {
res_ninit(res_state statp) {
        extern int __res_vinit(res_state, int);
        extern int __res_vinit(res_state, int);
 
 
        return (__res_vinit(statp, 0));
        return (__res_vinit(statp, 0));
}
}
#ifdef _LIBC
#ifdef _LIBC
libc_hidden_def (__res_ninit)
libc_hidden_def (__res_ninit)
#endif
#endif
 
 
/* This function has to be reachable by res_data.c but not publically. */
/* This function has to be reachable by res_data.c but not publically. */
int
int
__res_vinit(res_state statp, int preinit) {
__res_vinit(res_state statp, int preinit) {
        register FILE *fp;
        register FILE *fp;
        register char *cp, **pp;
        register char *cp, **pp;
        register int n;
        register int n;
        char buf[BUFSIZ];
        char buf[BUFSIZ];
        int nserv = 0;    /* number of nameserver records read from file */
        int nserv = 0;    /* number of nameserver records read from file */
#ifdef _LIBC
#ifdef _LIBC
        int nservall = 0; /* number of NS records read, nserv IPv4 only */
        int nservall = 0; /* number of NS records read, nserv IPv4 only */
#endif
#endif
        int haveenv = 0;
        int haveenv = 0;
        int havesearch = 0;
        int havesearch = 0;
#ifdef RESOLVSORT
#ifdef RESOLVSORT
        int nsort = 0;
        int nsort = 0;
        char *net;
        char *net;
#endif
#endif
#ifndef RFC1535
#ifndef RFC1535
        int dots;
        int dots;
#endif
#endif
#ifdef _LIBC
#ifdef _LIBC
        statp->_u._ext.initstamp = __res_initstamp;
        statp->_u._ext.initstamp = __res_initstamp;
#endif
#endif
 
 
        if (!preinit) {
        if (!preinit) {
                statp->retrans = RES_TIMEOUT;
                statp->retrans = RES_TIMEOUT;
                statp->retry = RES_DFLRETRY;
                statp->retry = RES_DFLRETRY;
                statp->options = RES_DEFAULT;
                statp->options = RES_DEFAULT;
                statp->id = res_randomid();
                statp->id = res_randomid();
        }
        }
 
 
#ifdef USELOOPBACK
#ifdef USELOOPBACK
        statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
        statp->nsaddr.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
#else
#else
        statp->nsaddr.sin_addr.s_addr = INADDR_ANY;
        statp->nsaddr.sin_addr.s_addr = INADDR_ANY;
#endif
#endif
        statp->nsaddr.sin_family = AF_INET;
        statp->nsaddr.sin_family = AF_INET;
        statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
        statp->nsaddr.sin_port = htons(NAMESERVER_PORT);
        statp->nscount = 1;
        statp->nscount = 1;
        statp->ndots = 1;
        statp->ndots = 1;
        statp->pfcode = 0;
        statp->pfcode = 0;
        statp->_vcsock = -1;
        statp->_vcsock = -1;
        statp->_flags = 0;
        statp->_flags = 0;
        statp->qhook = NULL;
        statp->qhook = NULL;
        statp->rhook = NULL;
        statp->rhook = NULL;
        statp->_u._ext.nsinit = 0;
        statp->_u._ext.nsinit = 0;
        statp->_u._ext.nscount = 0;
        statp->_u._ext.nscount = 0;
#ifdef _LIBC
#ifdef _LIBC
        statp->_u._ext.nscount6 = 0;
        statp->_u._ext.nscount6 = 0;
        for (n = 0; n < MAXNS; n++) {
        for (n = 0; n < MAXNS; n++) {
                statp->_u._ext.nsaddrs[n] = NULL;
                statp->_u._ext.nsaddrs[n] = NULL;
                statp->_u._ext.nsmap[n] = MAXNS;
                statp->_u._ext.nsmap[n] = MAXNS;
        }
        }
#endif
#endif
 
 
        /* Allow user to override the local domain definition */
        /* Allow user to override the local domain definition */
        if ((cp = getenv("LOCALDOMAIN")) != NULL) {
        if ((cp = getenv("LOCALDOMAIN")) != NULL) {
                (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                (void)strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                haveenv++;
                haveenv++;
 
 
                /*
                /*
                 * Set search list to be blank-separated strings
                 * Set search list to be blank-separated strings
                 * from rest of env value.  Permits users of LOCALDOMAIN
                 * from rest of env value.  Permits users of LOCALDOMAIN
                 * to still have a search list, and anyone to set the
                 * to still have a search list, and anyone to set the
                 * one that they want to use as an individual (even more
                 * one that they want to use as an individual (even more
                 * important now that the rfc1535 stuff restricts searches)
                 * important now that the rfc1535 stuff restricts searches)
                 */
                 */
                cp = statp->defdname;
                cp = statp->defdname;
                pp = statp->dnsrch;
                pp = statp->dnsrch;
                *pp++ = cp;
                *pp++ = cp;
                for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
                for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
                        if (*cp == '\n')        /* silly backwards compat */
                        if (*cp == '\n')        /* silly backwards compat */
                                break;
                                break;
                        else if (*cp == ' ' || *cp == '\t') {
                        else if (*cp == ' ' || *cp == '\t') {
                                *cp = 0;
                                *cp = 0;
                                n = 1;
                                n = 1;
                        } else if (n) {
                        } else if (n) {
                                *pp++ = cp;
                                *pp++ = cp;
                                n = 0;
                                n = 0;
                                havesearch = 1;
                                havesearch = 1;
                        }
                        }
                }
                }
                /* null terminate last domain if there are excess */
                /* null terminate last domain if there are excess */
                while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
                while (*cp != '\0' && *cp != ' ' && *cp != '\t' && *cp != '\n')
                        cp++;
                        cp++;
                *cp = '\0';
                *cp = '\0';
                *pp++ = 0;
                *pp++ = 0;
        }
        }
 
 
#define MATCH(line, name) \
#define MATCH(line, name) \
        (!strncmp(line, name, sizeof(name) - 1) && \
        (!strncmp(line, name, sizeof(name) - 1) && \
        (line[sizeof(name) - 1] == ' ' || \
        (line[sizeof(name) - 1] == ' ' || \
         line[sizeof(name) - 1] == '\t'))
         line[sizeof(name) - 1] == '\t'))
 
 
        if ((fp = fopen(_PATH_RESCONF, "rc")) != NULL) {
        if ((fp = fopen(_PATH_RESCONF, "rc")) != NULL) {
                /* No threads use this stream.  */
                /* No threads use this stream.  */
                __fsetlocking (fp, FSETLOCKING_BYCALLER);
                __fsetlocking (fp, FSETLOCKING_BYCALLER);
            /* read the config file */
            /* read the config file */
            while (fgets(buf, sizeof(buf), fp) != NULL) {
            while (fgets(buf, sizeof(buf), fp) != NULL) {
                /* skip comments */
                /* skip comments */
                if (*buf == ';' || *buf == '#')
                if (*buf == ';' || *buf == '#')
                        continue;
                        continue;
                /* read default domain name */
                /* read default domain name */
                if (MATCH(buf, "domain")) {
                if (MATCH(buf, "domain")) {
                    if (haveenv)        /* skip if have from environ */
                    if (haveenv)        /* skip if have from environ */
                            continue;
                            continue;
                    cp = buf + sizeof("domain") - 1;
                    cp = buf + sizeof("domain") - 1;
                    while (*cp == ' ' || *cp == '\t')
                    while (*cp == ' ' || *cp == '\t')
                            cp++;
                            cp++;
                    if ((*cp == '\0') || (*cp == '\n'))
                    if ((*cp == '\0') || (*cp == '\n'))
                            continue;
                            continue;
                    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                    if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL)
                    if ((cp = strpbrk(statp->defdname, " \t\n")) != NULL)
                            *cp = '\0';
                            *cp = '\0';
                    havesearch = 0;
                    havesearch = 0;
                    continue;
                    continue;
                }
                }
                /* set search list */
                /* set search list */
                if (MATCH(buf, "search")) {
                if (MATCH(buf, "search")) {
                    if (haveenv)        /* skip if have from environ */
                    if (haveenv)        /* skip if have from environ */
                            continue;
                            continue;
                    cp = buf + sizeof("search") - 1;
                    cp = buf + sizeof("search") - 1;
                    while (*cp == ' ' || *cp == '\t')
                    while (*cp == ' ' || *cp == '\t')
                            cp++;
                            cp++;
                    if ((*cp == '\0') || (*cp == '\n'))
                    if ((*cp == '\0') || (*cp == '\n'))
                            continue;
                            continue;
                    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                    strncpy(statp->defdname, cp, sizeof(statp->defdname) - 1);
                    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                    statp->defdname[sizeof(statp->defdname) - 1] = '\0';
                    if ((cp = strchr(statp->defdname, '\n')) != NULL)
                    if ((cp = strchr(statp->defdname, '\n')) != NULL)
                            *cp = '\0';
                            *cp = '\0';
                    /*
                    /*
                     * Set search list to be blank-separated strings
                     * Set search list to be blank-separated strings
                     * on rest of line.
                     * on rest of line.
                     */
                     */
                    cp = statp->defdname;
                    cp = statp->defdname;
                    pp = statp->dnsrch;
                    pp = statp->dnsrch;
                    *pp++ = cp;
                    *pp++ = cp;
                    for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
                    for (n = 0; *cp && pp < statp->dnsrch + MAXDNSRCH; cp++) {
                            if (*cp == ' ' || *cp == '\t') {
                            if (*cp == ' ' || *cp == '\t') {
                                    *cp = 0;
                                    *cp = 0;
                                    n = 1;
                                    n = 1;
                            } else if (n) {
                            } else if (n) {
                                    *pp++ = cp;
                                    *pp++ = cp;
                                    n = 0;
                                    n = 0;
                            }
                            }
                    }
                    }
                    /* null terminate last domain if there are excess */
                    /* null terminate last domain if there are excess */
                    while (*cp != '\0' && *cp != ' ' && *cp != '\t')
                    while (*cp != '\0' && *cp != ' ' && *cp != '\t')
                            cp++;
                            cp++;
                    *cp = '\0';
                    *cp = '\0';
                    *pp++ = 0;
                    *pp++ = 0;
                    havesearch = 1;
                    havesearch = 1;
                    continue;
                    continue;
                }
                }
                /* read nameservers to query */
                /* read nameservers to query */
#ifdef _LIBC
#ifdef _LIBC
                if (MATCH(buf, "nameserver") && nservall < MAXNS) {
                if (MATCH(buf, "nameserver") && nservall < MAXNS) {
#else
#else
                if (MATCH(buf, "nameserver") && nserv < MAXNS) {
                if (MATCH(buf, "nameserver") && nserv < MAXNS) {
#endif
#endif
                    struct in_addr a;
                    struct in_addr a;
 
 
                    cp = buf + sizeof("nameserver") - 1;
                    cp = buf + sizeof("nameserver") - 1;
                    while (*cp == ' ' || *cp == '\t')
                    while (*cp == ' ' || *cp == '\t')
                        cp++;
                        cp++;
                    if ((*cp != '\0') && (*cp != '\n')
                    if ((*cp != '\0') && (*cp != '\n')
                        && inet_aton(cp, &a)) {
                        && inet_aton(cp, &a)) {
                        statp->nsaddr_list[nserv].sin_addr = a;
                        statp->nsaddr_list[nserv].sin_addr = a;
                        statp->nsaddr_list[nserv].sin_family = AF_INET;
                        statp->nsaddr_list[nserv].sin_family = AF_INET;
                        statp->nsaddr_list[nserv].sin_port =
                        statp->nsaddr_list[nserv].sin_port =
                                htons(NAMESERVER_PORT);
                                htons(NAMESERVER_PORT);
                        nserv++;
                        nserv++;
#ifdef _LIBC
#ifdef _LIBC
                        nservall++;
                        nservall++;
                    } else {
                    } else {
                        struct in6_addr a6;
                        struct in6_addr a6;
                        char *el;
                        char *el;
 
 
                        if ((el = strchr(cp, '\n')) != NULL)
                        if ((el = strchr(cp, '\n')) != NULL)
                            *el = '\0';
                            *el = '\0';
                        if ((*cp != '\0') &&
                        if ((*cp != '\0') &&
                            (inet_pton(AF_INET6, cp, &a6) > 0)) {
                            (inet_pton(AF_INET6, cp, &a6) > 0)) {
                            struct sockaddr_in6 *sa6;
                            struct sockaddr_in6 *sa6;
 
 
                            sa6 = malloc(sizeof(*sa6));
                            sa6 = malloc(sizeof(*sa6));
                            if (sa6 != NULL) {
                            if (sa6 != NULL) {
                                sa6->sin6_addr = a6;
                                sa6->sin6_addr = a6;
                                sa6->sin6_family = AF_INET6;
                                sa6->sin6_family = AF_INET6;
                                sa6->sin6_port = htons(NAMESERVER_PORT);
                                sa6->sin6_port = htons(NAMESERVER_PORT);
                                statp->_u._ext.nsaddrs[nservall] = sa6;
                                statp->_u._ext.nsaddrs[nservall] = sa6;
                                statp->_u._ext.nssocks[nservall] = -1;
                                statp->_u._ext.nssocks[nservall] = -1;
                                statp->_u._ext.nsmap[nservall] = MAXNS + 1;
                                statp->_u._ext.nsmap[nservall] = MAXNS + 1;
                                nservall++;
                                nservall++;
                            }
                            }
                        }
                        }
#endif
#endif
                    }
                    }
                    continue;
                    continue;
                }
                }
#ifdef RESOLVSORT
#ifdef RESOLVSORT
                if (MATCH(buf, "sortlist")) {
                if (MATCH(buf, "sortlist")) {
                    struct in_addr a;
                    struct in_addr a;
 
 
                    cp = buf + sizeof("sortlist") - 1;
                    cp = buf + sizeof("sortlist") - 1;
                    while (nsort < MAXRESOLVSORT) {
                    while (nsort < MAXRESOLVSORT) {
                        while (*cp == ' ' || *cp == '\t')
                        while (*cp == ' ' || *cp == '\t')
                            cp++;
                            cp++;
                        if (*cp == '\0' || *cp == '\n' || *cp == ';')
                        if (*cp == '\0' || *cp == '\n' || *cp == ';')
                            break;
                            break;
                        net = cp;
                        net = cp;
                        while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
                        while (*cp && !ISSORTMASK(*cp) && *cp != ';' &&
                               isascii(*cp) && !isspace(*cp))
                               isascii(*cp) && !isspace(*cp))
                                cp++;
                                cp++;
                        n = *cp;
                        n = *cp;
                        *cp = 0;
                        *cp = 0;
                        if (inet_aton(net, &a)) {
                        if (inet_aton(net, &a)) {
                            statp->sort_list[nsort].addr = a;
                            statp->sort_list[nsort].addr = a;
                            if (ISSORTMASK(n)) {
                            if (ISSORTMASK(n)) {
                                *cp++ = n;
                                *cp++ = n;
                                net = cp;
                                net = cp;
                                while (*cp && *cp != ';' &&
                                while (*cp && *cp != ';' &&
                                        isascii(*cp) && !isspace(*cp))
                                        isascii(*cp) && !isspace(*cp))
                                    cp++;
                                    cp++;
                                n = *cp;
                                n = *cp;
                                *cp = 0;
                                *cp = 0;
                                if (inet_aton(net, &a)) {
                                if (inet_aton(net, &a)) {
                                    statp->sort_list[nsort].mask = a.s_addr;
                                    statp->sort_list[nsort].mask = a.s_addr;
                                } else {
                                } else {
                                    statp->sort_list[nsort].mask =
                                    statp->sort_list[nsort].mask =
                                        net_mask(statp->sort_list[nsort].addr);
                                        net_mask(statp->sort_list[nsort].addr);
                                }
                                }
                            } else {
                            } else {
                                statp->sort_list[nsort].mask =
                                statp->sort_list[nsort].mask =
                                    net_mask(statp->sort_list[nsort].addr);
                                    net_mask(statp->sort_list[nsort].addr);
                            }
                            }
                            nsort++;
                            nsort++;
                        }
                        }
                        *cp = n;
                        *cp = n;
                    }
                    }
                    continue;
                    continue;
                }
                }
#endif
#endif
                if (MATCH(buf, "options")) {
                if (MATCH(buf, "options")) {
                    res_setoptions(statp, buf + sizeof("options") - 1, "conf");
                    res_setoptions(statp, buf + sizeof("options") - 1, "conf");
                    continue;
                    continue;
                }
                }
            }
            }
            if (nserv > 1)
            if (nserv > 1)
                statp->nscount = nserv;
                statp->nscount = nserv;
#ifdef _LIBC
#ifdef _LIBC
            if (nservall - nserv > 0)
            if (nservall - nserv > 0)
                statp->_u._ext.nscount6 = nservall - nserv;
                statp->_u._ext.nscount6 = nservall - nserv;
#endif
#endif
#ifdef RESOLVSORT
#ifdef RESOLVSORT
            statp->nsort = nsort;
            statp->nsort = nsort;
#endif
#endif
            (void) fclose(fp);
            (void) fclose(fp);
        }
        }
        if (statp->defdname[0] == 0 &&
        if (statp->defdname[0] == 0 &&
            __gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
            __gethostname(buf, sizeof(statp->defdname) - 1) == 0 &&
            (cp = strchr(buf, '.')) != NULL)
            (cp = strchr(buf, '.')) != NULL)
                strcpy(statp->defdname, cp + 1);
                strcpy(statp->defdname, cp + 1);
 
 
        /* find components of local domain that might be searched */
        /* find components of local domain that might be searched */
        if (havesearch == 0) {
        if (havesearch == 0) {
                pp = statp->dnsrch;
                pp = statp->dnsrch;
                *pp++ = statp->defdname;
                *pp++ = statp->defdname;
                *pp = NULL;
                *pp = NULL;
 
 
#ifndef RFC1535
#ifndef RFC1535
                dots = 0;
                dots = 0;
                for (cp = statp->defdname; *cp; cp++)
                for (cp = statp->defdname; *cp; cp++)
                        dots += (*cp == '.');
                        dots += (*cp == '.');
 
 
                cp = statp->defdname;
                cp = statp->defdname;
                while (pp < statp->dnsrch + MAXDFLSRCH) {
                while (pp < statp->dnsrch + MAXDFLSRCH) {
                        if (dots < LOCALDOMAINPARTS)
                        if (dots < LOCALDOMAINPARTS)
                                break;
                                break;
                        cp = memchr(cp, '.') + 1;    /* we know there is one */
                        cp = memchr(cp, '.') + 1;    /* we know there is one */
                        *pp++ = cp;
                        *pp++ = cp;
                        dots--;
                        dots--;
                }
                }
                *pp = NULL;
                *pp = NULL;
#ifdef DEBUG
#ifdef DEBUG
                if (statp->options & RES_DEBUG) {
                if (statp->options & RES_DEBUG) {
                        printf(";; res_init()... default dnsrch list:\n");
                        printf(";; res_init()... default dnsrch list:\n");
                        for (pp = statp->dnsrch; *pp; pp++)
                        for (pp = statp->dnsrch; *pp; pp++)
                                printf(";;\t%s\n", *pp);
                                printf(";;\t%s\n", *pp);
                        printf(";;\t..END..\n");
                        printf(";;\t..END..\n");
                }
                }
#endif
#endif
#endif /* !RFC1535 */
#endif /* !RFC1535 */
        }
        }
 
 
        if ((cp = getenv("RES_OPTIONS")) != NULL)
        if ((cp = getenv("RES_OPTIONS")) != NULL)
                res_setoptions(statp, cp, "env");
                res_setoptions(statp, cp, "env");
        statp->options |= RES_INIT;
        statp->options |= RES_INIT;
        return (0);
        return (0);
}
}
 
 
static void
static void
internal_function
internal_function
res_setoptions(res_state statp, const char *options, const char *source) {
res_setoptions(res_state statp, const char *options, const char *source) {
        const char *cp = options;
        const char *cp = options;
        int i;
        int i;
 
 
#ifdef DEBUG
#ifdef DEBUG
        if (statp->options & RES_DEBUG)
        if (statp->options & RES_DEBUG)
                printf(";; res_setoptions(\"%s\", \"%s\")...\n",
                printf(";; res_setoptions(\"%s\", \"%s\")...\n",
                       options, source);
                       options, source);
#endif
#endif
        while (*cp) {
        while (*cp) {
                /* skip leading and inner runs of spaces */
                /* skip leading and inner runs of spaces */
                while (*cp == ' ' || *cp == '\t')
                while (*cp == ' ' || *cp == '\t')
                        cp++;
                        cp++;
                /* search for and process individual options */
                /* search for and process individual options */
                if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
                if (!strncmp(cp, "ndots:", sizeof("ndots:") - 1)) {
                        i = atoi(cp + sizeof("ndots:") - 1);
                        i = atoi(cp + sizeof("ndots:") - 1);
                        if (i <= RES_MAXNDOTS)
                        if (i <= RES_MAXNDOTS)
                                statp->ndots = i;
                                statp->ndots = i;
                        else
                        else
                                statp->ndots = RES_MAXNDOTS;
                                statp->ndots = RES_MAXNDOTS;
#ifdef DEBUG
#ifdef DEBUG
                        if (statp->options & RES_DEBUG)
                        if (statp->options & RES_DEBUG)
                                printf(";;\tndots=%d\n", statp->ndots);
                                printf(";;\tndots=%d\n", statp->ndots);
#endif
#endif
                } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
                } else if (!strncmp(cp, "timeout:", sizeof("timeout:") - 1)) {
                        i = atoi(cp + sizeof("timeout:") - 1);
                        i = atoi(cp + sizeof("timeout:") - 1);
                        if (i <= RES_MAXRETRANS)
                        if (i <= RES_MAXRETRANS)
                                statp->retrans = i;
                                statp->retrans = i;
                        else
                        else
                                statp->retrans = RES_MAXRETRANS;
                                statp->retrans = RES_MAXRETRANS;
                } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
                } else if (!strncmp(cp, "attempts:", sizeof("attempts:") - 1)){
                        i = atoi(cp + sizeof("attempts:") - 1);
                        i = atoi(cp + sizeof("attempts:") - 1);
                        if (i <= RES_MAXRETRY)
                        if (i <= RES_MAXRETRY)
                                statp->retry = i;
                                statp->retry = i;
                        else
                        else
                                statp->retry = RES_MAXRETRY;
                                statp->retry = RES_MAXRETRY;
                } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
                } else if (!strncmp(cp, "debug", sizeof("debug") - 1)) {
#ifdef DEBUG
#ifdef DEBUG
                        if (!(statp->options & RES_DEBUG)) {
                        if (!(statp->options & RES_DEBUG)) {
                                printf(";; res_setoptions(\"%s\", \"%s\")..\n",
                                printf(";; res_setoptions(\"%s\", \"%s\")..\n",
                                       options, source);
                                       options, source);
                                statp->options |= RES_DEBUG;
                                statp->options |= RES_DEBUG;
                        }
                        }
                        printf(";;\tdebug\n");
                        printf(";;\tdebug\n");
#endif
#endif
                } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
                } else if (!strncmp(cp, "inet6", sizeof("inet6") - 1)) {
                        statp->options |= RES_USE_INET6;
                        statp->options |= RES_USE_INET6;
                } else if (!strncmp(cp, "ip6-bytestring",
                } else if (!strncmp(cp, "ip6-bytestring",
                                    sizeof("ip6-bytestring") - 1)) {
                                    sizeof("ip6-bytestring") - 1)) {
                        statp->options |= RES_USEBSTRING;
                        statp->options |= RES_USEBSTRING;
                } else if (!strncmp(cp, "no-ip6-dotint",
                } else if (!strncmp(cp, "no-ip6-dotint",
                                    sizeof("no-ip6-dotint") - 1)) {
                                    sizeof("no-ip6-dotint") - 1)) {
                        statp->options |= RES_NOIP6DOTINT;
                        statp->options |= RES_NOIP6DOTINT;
                } else if (!strncmp(cp, "ip6-dotint",
                } else if (!strncmp(cp, "ip6-dotint",
                                    sizeof("ip6-dotint") - 1)) {
                                    sizeof("ip6-dotint") - 1)) {
                        statp->options &= ~RES_NOIP6DOTINT;
                        statp->options &= ~RES_NOIP6DOTINT;
                } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
                } else if (!strncmp(cp, "rotate", sizeof("rotate") - 1)) {
                        statp->options |= RES_ROTATE;
                        statp->options |= RES_ROTATE;
                } else if (!strncmp(cp, "no-check-names",
                } else if (!strncmp(cp, "no-check-names",
                                    sizeof("no-check-names") - 1)) {
                                    sizeof("no-check-names") - 1)) {
                        statp->options |= RES_NOCHECKNAME;
                        statp->options |= RES_NOCHECKNAME;
                } else {
                } else {
                        /* XXX - print a warning here? */
                        /* XXX - print a warning here? */
                }
                }
                /* skip to next run of spaces */
                /* skip to next run of spaces */
                while (*cp && *cp != ' ' && *cp != '\t')
                while (*cp && *cp != ' ' && *cp != '\t')
                        cp++;
                        cp++;
        }
        }
}
}
 
 
#ifdef RESOLVSORT
#ifdef RESOLVSORT
/* XXX - should really support CIDR which means explicit masks always. */
/* XXX - should really support CIDR which means explicit masks always. */
static u_int32_t
static u_int32_t
net_mask(in)            /* XXX - should really use system's version of this */
net_mask(in)            /* XXX - should really use system's version of this */
        struct in_addr in;
        struct in_addr in;
{
{
        register u_int32_t i = ntohl(in.s_addr);
        register u_int32_t i = ntohl(in.s_addr);
 
 
        if (IN_CLASSA(i))
        if (IN_CLASSA(i))
                return (htonl(IN_CLASSA_NET));
                return (htonl(IN_CLASSA_NET));
        else if (IN_CLASSB(i))
        else if (IN_CLASSB(i))
                return (htonl(IN_CLASSB_NET));
                return (htonl(IN_CLASSB_NET));
        return (htonl(IN_CLASSC_NET));
        return (htonl(IN_CLASSC_NET));
}
}
#endif
#endif
 
 
u_int
u_int
res_randomid(void) {
res_randomid(void) {
        struct timeval now;
        struct timeval now;
 
 
        gettimeofday(&now, NULL);
        gettimeofday(&now, NULL);
        return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
        return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
}
}
#ifdef _LIBC
#ifdef _LIBC
libc_hidden_def (__res_randomid)
libc_hidden_def (__res_randomid)
#endif
#endif
 
 
 
 
/*
/*
 * This routine is for closing the socket if a virtual circuit is used and
 * 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()
 * the program wants to close it.  This provides support for endhostent()
 * which expects to close the socket.
 * which expects to close the socket.
 *
 *
 * This routine is not expected to be user visible.
 * This routine is not expected to be user visible.
 */
 */
void
void
res_nclose(res_state statp) {
res_nclose(res_state statp) {
        int ns;
        int ns;
 
 
        if (statp->_vcsock >= 0) {
        if (statp->_vcsock >= 0) {
                close_not_cancel_no_status(statp->_vcsock);
                close_not_cancel_no_status(statp->_vcsock);
                statp->_vcsock = -1;
                statp->_vcsock = -1;
                statp->_flags &= ~(RES_F_VC | RES_F_CONN);
                statp->_flags &= ~(RES_F_VC | RES_F_CONN);
        }
        }
#ifdef _LIBC
#ifdef _LIBC
        for (ns = 0; ns < MAXNS; ns++)
        for (ns = 0; ns < MAXNS; ns++)
#else
#else
        for (ns = 0; ns < statp->_u._ext.nscount; ns++)
        for (ns = 0; ns < statp->_u._ext.nscount; ns++)
#endif
#endif
                if (statp->_u._ext.nsaddrs[ns]
                if (statp->_u._ext.nsaddrs[ns]
                    && statp->_u._ext.nssocks[ns] != -1) {
                    && statp->_u._ext.nssocks[ns] != -1) {
                        close_not_cancel_no_status(statp->_u._ext.nssocks[ns]);
                        close_not_cancel_no_status(statp->_u._ext.nssocks[ns]);
                        statp->_u._ext.nssocks[ns] = -1;
                        statp->_u._ext.nssocks[ns] = -1;
                }
                }
        statp->_u._ext.nsinit = 0;
        statp->_u._ext.nsinit = 0;
}
}
#ifdef _LIBC
#ifdef _LIBC
libc_hidden_def (__res_nclose)
libc_hidden_def (__res_nclose)
#endif
#endif
 
 
#ifdef _LIBC
#ifdef _LIBC
# ifdef _LIBC_REENTRANT
# ifdef _LIBC_REENTRANT
/* This is called when a thread is exiting to free resources held in _res.  */
/* This is called when a thread is exiting to free resources held in _res.  */
static void __attribute__ ((section ("__libc_thread_freeres_fn")))
static void __attribute__ ((section ("__libc_thread_freeres_fn")))
res_thread_freeres (void)
res_thread_freeres (void)
{
{
  if (_res.nscount == 0)
  if (_res.nscount == 0)
    /* Never called res_ninit.  */
    /* Never called res_ninit.  */
    return;
    return;
 
 
  __res_nclose (&_res);         /* Close any VC sockets.  */
  __res_nclose (&_res);         /* Close any VC sockets.  */
 
 
  for (int ns = 0; ns < MAXNS; ns++)
  for (int ns = 0; ns < MAXNS; ns++)
    if (_res._u._ext.nsaddrs[ns] != NULL)
    if (_res._u._ext.nsaddrs[ns] != NULL)
      {
      {
        free (_res._u._ext.nsaddrs[ns]);
        free (_res._u._ext.nsaddrs[ns]);
        _res._u._ext.nsaddrs[ns] = NULL;
        _res._u._ext.nsaddrs[ns] = NULL;
      }
      }
 
 
  /* Make sure we do a full re-initialization the next time.  */
  /* Make sure we do a full re-initialization the next time.  */
  _res.options = 0;
  _res.options = 0;
}
}
text_set_element (__libc_thread_subfreeres, res_thread_freeres);
text_set_element (__libc_thread_subfreeres, res_thread_freeres);
text_set_element (__libc_subfreeres, res_thread_freeres);
text_set_element (__libc_subfreeres, res_thread_freeres);
# endif
# endif
#endif
#endif
 
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.