⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 hostable.c

📁 汇编源代码大全
💻 C
📖 第 1 页 / 共 2 页
字号:

   while ( element < hit )
   {
      if (equali( hosts[element].hostname , name ))
         hit = element;
      else
         element++;
   }

/*--------------------------------------------------------------------*/
/*               If a new element, initialize the block               */
/*--------------------------------------------------------------------*/

   if (hit == HostElements)
   {
      memset( &hosts[hit] , 0, sizeof hosts[hit] );
      hosts[hit].hostname = newstr(name);
      checkref( hosts[hit].hostname );
      hosts[hit].anylogin = TRUE;   /* Allow generic login by default   */
      HostElements ++ ;
   } /* if */

   return &hosts[hit];

} /* inithost */

/*--------------------------------------------------------------------*/
/*    l o a d h o s t                                                 */
/*                                                                    */
/*    Initializes table of known host names for checkname             */
/*--------------------------------------------------------------------*/

static size_t loadhost()
{
   FILE *ff;
   char buf[BUFSIZ];
   char *token;
   char s_hostable[FILENAME_MAX]; /* full-name of hostable file        */
   size_t hit;

   struct HostTable *hostp;

/*--------------------------------------------------------------------*/
/*                      Validate the domain name                      */
/*--------------------------------------------------------------------*/

   token = strrchr(E_domain,'.');

   if (token == NULL)
   {
      printmsg(0,"Domain name \"%s\" is invalid, missing period",E_domain);
      panic();
   }

/*--------------------------------------------------------------------*/
/*                  Load the local host information                   */
/*--------------------------------------------------------------------*/

   hostp = inithost(E_nodename);
   hostp->hstatus  = localhost;
   hostp->realname = E_nodename; /* Don't let user alias our system
                                    name                             */

/*--------------------------------------------------------------------*/
/*                Now do the local domain information                 */
/*--------------------------------------------------------------------*/

   hostp = inithost(E_domain);

   if (hostp->via == NULL )   /* Not initialized?                    */
      hostp->via      = E_nodename;  /* Correct --> Route via local  */
   else
      panic();                /* "Houston, we a have problem" -
                                 Apollo 13                           */

   hostp->realname = E_nodename;

/*--------------------------------------------------------------------*/
/*    If we allow anonymous UUCP, load the dummy host we use for      */
/*    connections to such hosts                                       */
/*--------------------------------------------------------------------*/

   if ( E_anonymous != NULL )
   {
      hostp = inithost( ANONYMOUS_HOST );
      hostp->hstatus = nocall;
      hostp->via     = E_nodename;
      hostp->hstats  = malloc( sizeof *(hostp->hstats) );
      checkref( hostp->hstats );
      memset( hostp->hstats, 0, sizeof *(hostp->hstats) );
   } /* if */

/*--------------------------------------------------------------------*/
/*                  Load names from the systems file                  */
/*--------------------------------------------------------------------*/


   ff = FOPEN(E_systems, "r",TEXT_MODE);
   if (ff == NULL)
   {
      printerr(E_systems);
      panic();
   }

   while (! feof(ff))
   {
      if (fgets(buf,BUFSIZ,ff) == NULL)   /* Try to read a line      */
         break;                  /* Exit if end of file              */
      token = strtok(buf,WHITESPACE);
      if (token == NULL)         /* Any data?                        */
         continue;               /* No --> read another line         */
      if (token[0] == '#')
         continue;                  /* Line is a comment; loop again */

      if ( equali( token, E_nodename ))
      {
         printmsg(0,"Error: Local host %s must not be in SYSTEMS file",
                    E_nodename );
         panic();
      }

      hostp = inithost(token);

      if (hostp->hstatus == phantom)
      {
         hostp->hstatus = nocall;
         hostp->hstats  = malloc( sizeof *(hostp->hstats) );
         checkref( hostp->hstats );
         memset( hostp->hstats, 0, sizeof *(hostp->hstats) );
      }
   } /* while */

   fclose(ff);

/*--------------------------------------------------------------------*/
/*               Now the load the routing file, if any.               */
/*--------------------------------------------------------------------*/

   mkfilename(s_hostable, E_confdir, PATHS);

   if ((ff = FOPEN(s_hostable, "r",TEXT_MODE)) != NULL)
   {

      while (! feof(ff))
      {
         boolean freeit = FALSE;

         if (fgets(buf,BUFSIZ,ff) == NULL)   /* Try to read a line      */
            break;                  /* Exit if end of file              */
         token = strtok(buf,WHITESPACE);

         if (token == NULL)         /* Any data?                        */
            continue;               /* No --> read another line         */

         if (*token == '#')
            continue;               /* Line is a comment; loop again    */

         hostp = inithost(token);
         token = strtok(NULL,WHITESPACE);

         if ( token == NULL )
         {
            printmsg(0,"loadhost: Missing path name for host \"%s\"",
                        hostp->hostname);
            freeit = TRUE;
         }
/*--------------------------------------------------------------------*/
/*                              Gate way                              */
/*--------------------------------------------------------------------*/
         else if (equal(token,"|"))
         {
            token = strtok(NULL,"\n");

            if (( hostp->via != NULL ) || ( token == NULL ))
               freeit = TRUE;
            else {
               hostp->hstatus = gatewayed;

               while(isspace( *token ))   /* Drop leading white space only */
                  token++;

               if (*token == '\0')        /* Empty string?           */
                  freeit = TRUE;          /* Yes --> Flag for error  */
               else
                  hostp->via = token = newstr(token);
            } /* else if */

            if ( freeit )
               printmsg(0,"loadhost: Invalid/duplicate gateway for \"%s\"",
                     hostp->hostname );

         } /* else if */
/*--------------------------------------------------------------------*/
/*                               Alias                                */
/*--------------------------------------------------------------------*/
         else if (equal(token,"="))
         {
            token = strtok(NULL,WHITESPACE);

            if (( hostp->realname == NULL ) && (token != NULL))
               hostp->realname = token = newstr( token );
            else {
               printmsg(0,"loadhost: Invalid/duplicate alias of \"%s\"",
                     hostp->hostname );
               freeit = TRUE;
            } /* else */
         } /* else if (equal(token,"=")) */
/*--------------------------------------------------------------------*/
/*                           Routing entry                            */
/*--------------------------------------------------------------------*/
         else {

            if ( hostp->via == NULL )
               hostp->via = token = newstr( token );
            else {
               printmsg(0,"loadhost: Invalid/duplicate route for \"%s\"",
                     hostp->hostname );
               freeit = TRUE;
            } /* else */

         } /* else */


         if ( ! freeit )
         {
            checkref( token );

            if (*token == '*')       /* Wildcard on right side?    */
            {
               printmsg(0,
     "loadhost: Wildcard \"%s\" not allowed for real name of host \"%s\"",
         token, hostp->hostname);
               freeit = TRUE;
            } /* if (*token == '*') */
         } /* if ( ! freeit ) */

         if ( freeit )
         {
            if ( hostp->hstatus == phantom )
               HostElements--;            /* Ignore the routing entry   */
         }
      }  /* end while */

      fclose(ff);
   }
   else {
      if ( debuglevel > 2 )
         perror( s_hostable );
   }

/*--------------------------------------------------------------------*/
/*                   Provide default for fromdomain                   */
/*--------------------------------------------------------------------*/

   if (E_fdomain != NULL)     /* If fromdomain provided ...          */
   {
      hostp = inithost(E_fdomain);

      if (hostp->via == NULL)    /* Uninitialized?                   */
         hostp->via = E_mailserv;   /* Yes --> Use default route     */
   }
   else
      E_fdomain = E_domain;   /* Use domain as fromdomain            */

/*--------------------------------------------------------------------*/
/*    Shrink the table to whatever we actually need, then sort it     */
/*--------------------------------------------------------------------*/

   hosts = realloc(hosts, HostElements *  sizeof(*hosts));
   checkref(hosts);

   qsort(hosts, HostElements ,sizeof(hosts[0]) , hostcmp);

/*--------------------------------------------------------------------*/
/*    If the user did not define a local domain, then generate one    */
/*    based on our own domain name; the generated name will either    */
/*    be of the format ".a.b.c" (incuding the trailing period) or     */
/*    a null string.                                                  */
/*--------------------------------------------------------------------*/

   if ( E_localdomain == NULL )
   {
      E_localdomain = strchr(E_domain,'.');

      if (E_localdomain == NULL)
         E_localdomain = "UUCP";
      else {
         E_localdomain ++;    /* Step past the period                */

         if ( !equali(E_localdomain, "UUCP" ) &&
              (strchr( E_localdomain, '.' ) == NULL ))
                              /* Implied single level domain name?   */
            E_localdomain = E_domain;
                              /* Impossible, use both parts of name  */
      } /* else */

      printmsg(3,"loadhost: local domain defined as \"%s\"",
                 E_localdomain);

   } /* if */

   localdomainl = strlen(E_localdomain);

/*--------------------------------------------------------------------*/
/*    Amend for the sin of typing the domain wrong in the sample      */
/*    files for the old releases of UUPC/extended.                    */
/*--------------------------------------------------------------------*/

   if (equali(E_localdomain,"UUPC"))
   {
      printmsg(0,"inithost: UUPC is an invalid domain name! "
                 "Change it to UUCP");
      panic();
   }

/*--------------------------------------------------------------------*/
/*                      Display the final table                       */
/*--------------------------------------------------------------------*/

   for (hit = 0; hit < HostElements; hit++)
   {
      printmsg(8,"loadhost: entry[%02d] %-20s\tvia %s\talias %s",
                  hit,
                  hosts[hit].hostname,
                  (hosts[hit].via == NULL) ? "(self)" : hosts[hit].via,
                  (hosts[hit].realname == NULL)
                                    ? "(self)" : hosts[hit].realname);
   } /* for */

/*--------------------------------------------------------------------*/
/*                          Return to caller                          */
/*--------------------------------------------------------------------*/

   return (HostElements) ;
} /*loadhost*/


/*--------------------------------------------------------------------*/
/*    h o s t c m p                                                   */
/*                                                                    */
/*    Accepts indirect pointers to two strings and compares           */
/*    them using stricmp (case insensitive string compare)            */
/*--------------------------------------------------------------------*/

int hostcmp( const void *a , const void *b )
{
   return stricmp(((struct HostTable*) a)->hostname,
        ((struct HostTable*) b)->hostname);
}  /*hostcmp*/

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -