[BACK]Return to res_init.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / lib / libc / resolv

Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.

Diff for /src/lib/libc/resolv/res_init.c between version 1.8 and 1.9

version 1.8, 2006/03/19 03:10:08 version 1.9, 2007/01/27 22:26:44
Line 74 
Line 74 
 #if defined(LIBC_SCCS) && !defined(lint)  #if defined(LIBC_SCCS) && !defined(lint)
 #ifdef notdef  #ifdef notdef
 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[] = "Id: res_init.c,v 1.9.2.5.4.2 2004/03/16 12:34:18 marka Exp";  static const char rcsid[] = "Id: res_init.c,v 1.16.18.5 2006/08/30 23:23:13 marka Exp";
 #else  #else
 __RCSID("$NetBSD$");  __RCSID("$NetBSD$");
 #endif  #endif
Line 120  __weak_alias(res_setservers,__res_setser
Line 120  __weak_alias(res_setservers,__res_setser
   
 #include "res_private.h"  #include "res_private.h"
   
 /* Options.  Should all be left alone. */  /*% Options.  Should all be left alone. */
   #define RESOLVSORT
 #ifndef DEBUG  #ifndef DEBUG
 #define DEBUG  #define DEBUG
 #endif  #endif
   
   #ifdef SOLARIS2
   #include <sys/systeminfo.h>
   #endif
   
 static void res_setoptions __P((res_state, const char *, const char *));  static void res_setoptions __P((res_state, const char *, const char *));
   
 static const char sort_mask[] = "/&";  static const char sort_mask[] = "/&";
 #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)  #define ISSORTMASK(ch) (strchr(sort_mask, ch) != NULL)
 static u_int32_t net_mask __P((struct in_addr));  static u_int32_t net_mask __P((struct in_addr));
   
 #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
   
Line 139  static u_int32_t net_mask __P((struct in
Line 144  static u_int32_t net_mask __P((struct in
  * 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().
Line 167  res_ninit(res_state statp) {
Line 172  res_ninit(res_state statp) {
         return (__res_vinit(statp, 0));          return (__res_vinit(statp, 0));
 }  }
   
 /* 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 */
         int haveenv = 0;          int haveenv = 0;
         int havesearch = 0;          int havesearch = 0;
         int nsort = 0;          int nsort = 0;
Line 182  __res_vinit(res_state statp, int preinit
Line 187  __res_vinit(res_state statp, int preinit
         int dots;          int dots;
         union res_sockaddr_union u[2];          union res_sockaddr_union u[2];
   
           if (statp->_u._ext.ext != NULL)
                   res_ndestroy(statp);
   
         if (!preinit) {          if (!preinit) {
                 statp->retrans = RES_TIMEOUT;                  statp->retrans = RES_TIMEOUT;
                 statp->retry = RES_DFLRETRY;                  statp->retry = RES_DFLRETRY;
Line 189  __res_vinit(res_state statp, int preinit
Line 197  __res_vinit(res_state statp, int preinit
                 statp->id = res_randomid();                  statp->id = res_randomid();
         }          }
   
         if ((statp->options & RES_INIT) != 0U)  
                 res_ndestroy(statp);  
   
         memset(u, 0, sizeof(u));          memset(u, 0, sizeof(u));
 #ifdef USELOOPBACK  #ifdef USELOOPBACK
         u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);          u[nserv].sin.sin_addr = inet_makeaddr(IN_LOOPBACKNET, 1);
Line 231  __res_vinit(res_state statp, int preinit
Line 236  __res_vinit(res_state statp, int preinit
                 statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr;                  statp->_u._ext.ext->nsaddrs[0].sin = statp->nsaddr;
                 strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa");                  strcpy(statp->_u._ext.ext->nsuffix, "ip6.arpa");
                 strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int");                  strcpy(statp->_u._ext.ext->nsuffix2, "ip6.int");
         }          } else
                   return (-1);
   #ifdef RESOLVSORT
         statp->nsort = 0;          statp->nsort = 0;
         res_setservers(statp, u, nserv);          res_setservers(statp, u, nserv);
   
   #ifdef  SOLARIS2
           /*
            * The old libresolv derived the defaultdomain from NIS/NIS+.
            * We want to keep this behaviour
            */
           {
                   char buf[sizeof(statp->defdname)], *cp;
                   int ret;
   
                   if ((ret = sysinfo(SI_SRPC_DOMAIN, buf, sizeof(buf))) > 0 &&
                           (unsigned int)ret <= sizeof(buf)) {
                           if (buf[0] == '+')
                                   buf[0] = '.';
                           cp = strchr(buf, '.');
                           cp = (cp == NULL) ? buf : (cp + 1);
                           if (strlen(cp) >= sizeof(statp->defdname))
                                   goto freedata;
                           strcpy(statp->defdname, cp);
                   }
           }
   #endif  /* SOLARIS2 */
   
         /* 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);
Line 252  __res_vinit(res_state statp, int preinit
Line 281  __res_vinit(res_state statp, int preinit
                 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;
Line 284  __res_vinit(res_state statp, int preinit
Line 313  __res_vinit(res_state statp, int preinit
                         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')
Line 300  __res_vinit(res_state statp, int preinit
Line 329  __res_vinit(res_state statp, int preinit
                 }                  }
                 /* 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')
Line 450  __res_vinit(res_state statp, int preinit
Line 479  __res_vinit(res_state statp, int preinit
                 while (pp < statp->dnsrch + MAXDFLSRCH) {                  while (pp < statp->dnsrch + MAXDFLSRCH) {
                         if (dots < LOCALDOMAINPARTS)                          if (dots < LOCALDOMAINPARTS)
                                 break;                                  break;
                         cp = strchr(cp, '.') + 1;    /* we know there is one */                          cp = strchr(cp, '.') + 1;    /*%< we know there is one */
                         *pp++ = cp;                          *pp++ = cp;
                         dots--;                          dots--;
                 }                  }
Line 469  __res_vinit(res_state statp, int preinit
Line 498  __res_vinit(res_state statp, int preinit
                 res_setoptions(statp, cp, "env");                  res_setoptions(statp, cp, "env");
         statp->options |= RES_INIT;          statp->options |= RES_INIT;
         return (0);          return (0);
   
   #ifdef  SOLARIS2
    freedata:
           if (statp->_u._ext.ext != NULL) {
                   free(statp->_u._ext.ext);
                   statp->_u._ext.ext = NULL;
           }
           return (-1);
   #endif
 }  }
   
 static void  static void
Line 508  res_setoptions(res_state statp, const ch
Line 546  res_setoptions(res_state statp, const ch
                         if (statp->options & RES_DEBUG)                          if (statp->options & RES_DEBUG)
                                 printf(";;\ttimeout=%d\n", statp->retrans);                                  printf(";;\ttimeout=%d\n", statp->retrans);
 #endif  #endif
   #ifdef  SOLARIS2
                   } else if (!strncmp(cp, "retrans:", sizeof("retrans:") - 1)) {
                           /*
                            * For backward compatibility, 'retrans' is
                            * supported as an alias for 'timeout', though
                            * without an imposed maximum.
                            */
                           statp->retrans = atoi(cp + sizeof("retrans:") - 1);
                   } else if (!strncmp(cp, "retry:", sizeof("retry:") - 1)){
                           /*
                            * For backward compatibility, 'retry' is
                            * supported as an alias for 'attempts', though
                            * without an imposed maximum.
                            */
                           statp->retry = atoi(cp + sizeof("retry:") - 1);
   #endif  /* SOLARIS2 */
                 } 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)
Line 586  res_setoptions(res_state statp, const ch
Line 640  res_setoptions(res_state statp, const ch
   
 /* 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);
Line 606  res_randomid(void) {
Line 660  res_randomid(void) {
         return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));          return (0xffff & (now.tv_sec ^ now.tv_usec ^ getpid()));
 }  }
   
 /*  /*%
  * 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.
Line 751  res_getservers(res_state statp, union re
Line 805  res_getservers(res_state statp, union re
         }          }
         return (statp->nscount);          return (statp->nscount);
 }  }
   
   /*! \file */

Legend:
Removed from v.1.8  
changed lines
  Added in v.1.9

CVSweb <webmaster@jp.NetBSD.org>