Diff for /libwww/Library/src/HTTCP.c between versions 2.17 and 2.18

version 2.17, 1994/06/09 20:45:44 version 2.18, 1994/06/13 15:18:37
Line 41 Line 41
 #define MAX_ACCEPT_POLL         30  #define MAX_ACCEPT_POLL         30
 #define FCNTL(r, s, t)          fcntl(r, s, t)  #define FCNTL(r, s, t)          fcntl(r, s, t)
   
   #ifndef RESOLV_CONF
   #define RESOLV_CONF "/etc/resolv.conf"
   #endif
   
 /* Globals */  /* Globals */
 PUBLIC unsigned int     HTConCacheSize = 512;    /* Number of cached servers */  PUBLIC unsigned int     HTConCacheSize = 512;    /* Number of cached servers */
   
Line 327  PRIVATE host_info *HTTCPCacheAddElement Line 331  PRIVATE host_info *HTTCPCacheAddElement
     if ((new = (host_info *) calloc(1, sizeof(host_info))) == NULL ||      if ((new = (host_info *) calloc(1, sizeof(host_info))) == NULL ||
         (new->addrlist = (char **)          (new->addrlist = (char **)
          calloc(1, sizeof element->h_addr_list)) == NULL)           calloc(1, sizeof element->h_addr_list)) == NULL)
         outofmem(__FILE__, "HTParseInet");          outofmem(__FILE__, "HTTCPCacheAddElement");
     new->hostname = host;      new->hostname = host;
   
     if ((homes = (sizeof element->h_addr_list) / element->h_length) > 1) {      if ((homes = (sizeof element->h_addr_list) / element->h_length) > 1) {
Line 421  PUBLIC int HTGetHostByName ARGS3(char *, Line 425  PUBLIC int HTGetHostByName ARGS3(char *,
         while ((pres = (host_info *) HTList_nextObject(cur)) != NULL) {          while ((pres = (host_info *) HTList_nextObject(cur)) != NULL) {
             if (pres->hostname == hostatom) {              if (pres->hostname == hostatom) {
                 if (TRACE)                  if (TRACE)
                     fprintf(stderr, "ParseInet... Host `%s\' found in cache.\n", host);                      fprintf(stderr, "HostByName.. Host `%s\' found in cache.\n", host);
                 break;                  break;
             }              }
         }          }
Line 452  PUBLIC int HTGetHostByName ARGS3(char *, Line 456  PUBLIC int HTGetHostByName ARGS3(char *,
             fprintf(stderr, "HTTCP: gethostbyname(%s)\n", host);              fprintf(stderr, "HTTCP: gethostbyname(%s)\n", host);
 #endif  #endif
         if ((hostelement = gethostbyname(host)) == NULL) {          if ((hostelement = gethostbyname(host)) == NULL) {
             if (TRACE) fprintf(stderr, "ParseInet... Can't find internet node name `%s'.\n", host);              if (TRACE) fprintf(stderr, "HostByName.. Can't find internet node name `%s'.\n", host);
             return -1;              return -1;
         }          }
                   
Line 608  PRIVATE void get_host_details NOARGS Line 612  PRIVATE void get_host_details NOARGS
           
     if (hostname) return;               /* Already done */      if (hostname) return;               /* Already done */
     gethostname(name, namelength);      /* Without domain */      gethostname(name, namelength);      /* Without domain */
     CTRACE(tfp, "TCP......... Local host name is %s\n", name);      if (TRACE) fprintf(stderr, "TCP......... Local host name is %s\n", name);
     StrAllocCopy(hostname, name);      StrAllocCopy(hostname, name);
   
 #ifndef DECNET  /* Decnet ain't got no damn name server 8#OO */  #ifndef DECNET  /* Decnet ain't got no damn name server 8#OO */
Line 620  PRIVATE void get_host_details NOARGS Line 624  PRIVATE void get_host_details NOARGS
         return;  /* Fail! */          return;  /* Fail! */
     }      }
     StrAllocCopy(hostname, phost->h_name);      StrAllocCopy(hostname, phost->h_name);
     CTRACE(tfp, "TCP......... Full local host name is %s\n", hostname);      if (TRACE)
           fprintf(stderr, "TCP......... Full local host name is %s\n", hostname);
   
 #ifdef NEED_HOST_ADDRESS                /* no -- needs name server! */  #ifdef NEED_HOST_ADDRESS                /* no -- needs name server! */
     memcpy(&HTHostAddress, &phost->h_addr, phost->h_length);      memcpy(&HTHostAddress, &phost->h_addr, phost->h_length);
Line 633  PRIVATE void get_host_details NOARGS Line 638  PRIVATE void get_host_details NOARGS
 #endif /* OLD_CODE */  #endif /* OLD_CODE */
   
 /*                                                              HTHostName  /*                                                              HTHostName
 **      Returns the name of this host. It first uses gethostname()  **      Returns the name of this host. It uses the following algoritm:
 **      and if it not finds any domain name then it tries getdomainname.  **
 **      If using the DNS and we are on a multi homed host, then the first  **      1) gethostname()
 **      entry is used.  **      2) if the hostname doesn't contain any '.' try to read
   **         /etc/resolv.conf. If there is no domain line in this file then
   **      3) Try getdomainname and do as the man pages say for resolv.conf (sun)
   **              If there is no domain line in this file, then it is derived
   **              from the domain name set by the domainname(1) command, usually
   **              by removing the first component. For example, if the domain-
   **              name is set to ``foo.podunk.edu'' then the default domain name
   **              used will be ``pudunk.edu''.
   **
   **      This is the same procedure as used by res_init() and sendmail.
 **  **
 **      Return: hostname on success else NULL  **      Return: hostname on success else NULL
 */  */
 PUBLIC CONST char * HTHostName NOARGS  PUBLIC CONST char * HTHostName NOARGS
 {  {
       BOOL got_it = NO;
       FILE *fp;
     char name[MAXHOSTNAMELEN+1];      char name[MAXHOSTNAMELEN+1];
     if (hostname)                                         /* If already done */      if (hostname) {                                       /* If already done */
         return hostname;          if (*hostname)
               return hostname;
           else
               return NULL;                    /* We couldn't get the last time */
       }
     *(name+MAXHOSTNAMELEN) = '\0';      *(name+MAXHOSTNAMELEN) = '\0';
     if (gethostname(name, MAXHOSTNAMELEN)) {         /* Maybe without domain */      if (gethostname(name, MAXHOSTNAMELEN)) {         /* Maybe without domain */
         if (TRACE)          if (TRACE)
             fprintf(stderr, "HostName.... Can't get host name\n");              fprintf(stderr, "HostName.... Can't get host name\n");
         return NULL;          return NULL;
     }      }
     CTRACE(tfp, "HostName.... Local host name is %s\n", name);      if (TRACE)
           fprintf(stderr, "HostName.... Local host name is %s\n", name);
     StrAllocCopy(hostname, name);      StrAllocCopy(hostname, name);
   
 #ifndef DECNET  /* Decnet ain't got no damn name server 8#OO */      /* Now try the resolver config file */
 #ifdef sun                                              /* Don't use the DNS */      if ((fp = fopen(RESOLV_CONF, "r")) != NULL) {
     if (getdomainname(name, MAXHOSTNAMELEN)) {          char buffer[80];
         if (TRACE)          *(buffer+79) = '\0';
             fprintf(stderr, "HostName.... Can't get domain name\n");          while (fgets(buffer, 79, fp)) {
         FREE(hostname);              if (!strncasecomp(buffer, "domain", 6)) {   
         return NULL;                  char *domainstr = buffer+6;
                   char *end;
                   while (*domainstr == ' ' || *domainstr == '\t')
                       domainstr++;
                   end = domainstr;
                   while (*end && !isspace(*end))
                       end++;
                   *end = '\0';
                   if (*domainstr) {
                       StrAllocCat(hostname, ".");
                       StrAllocCat(hostname, domainstr);
                       got_it = YES;
                       break;
                   }
               }
           }
           fclose(fp);
     }      }
   
     /* If the host name and the first part of the domain name are different      /* If everything else has failed then try getdomainname */
        then use the former as it is more exact (I guess) */      if (!got_it) {
     if (strncmp(name, hostname, (int) strlen(hostname))) {          if (getdomainname(name, MAXHOSTNAMELEN)) {
         char *domain = strchr(name, '.');              if (TRACE)
         if (!domain)                  fprintf(stderr, "HostName.... Can't get domain name\n");
             domain = name;              *hostname = '\0';
         StrAllocCat(hostname, domain);              return NULL;
           }
   
           /* If the host name and the first part of the domain name are different
              then use the former as it is more exact (I guess) */
           if (strncmp(name, hostname, (int) strlen(hostname))) {
               char *domain = strchr(name, '.');
               if (!domain)
                   domain = name;
               StrAllocCat(hostname, domain);
           }
     }      }
 #else                         /* Now we try to get information on the domain */      if (TRACE)
           fprintf(stderr, "HostName.... Full local host name is %s\n", hostname);
       return hostname;
   
   #ifndef DECNET  /* Decnet ain't got no damn name server 8#OO */
   #ifdef OLD_CODE
                                 /* Now we try to get information on the domain */
     {      {
         struct hostent *hostelement;          struct hostent *hostelement;
         if ((hostelement = gethostbyname(hostname)) == NULL) {          if ((hostelement = gethostbyname(hostname)) == NULL) {
Line 682  PUBLIC CONST char * HTHostName NOARGS Line 735  PUBLIC CONST char * HTHostName NOARGS
         }          }
         StrAllocCopy(hostname, (char *) hostelement->h_name);          StrAllocCopy(hostname, (char *) hostelement->h_name);
     }      }
 #endif /* DNS access */  #endif /* OLD_CODE */
 #endif /* not Decnet */  #endif /* not Decnet */
     CTRACE(tfp, "HostName.... Full local host name is %s\n", hostname);  
     return hostname;  
 }  }
   
   

Removed from v.2.17  
changed lines
  Added in v.2.18


Webmaster