home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / ncsat.cpt / Telnet2.5 final / tcpip / confile.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-07-10  |  34.9 KB  |  1,566 lines

  1. /*
  2. *   Confile.c
  3. *   Split from util.c 5/88
  4. *   Reads and stores the appropriate information for the config file
  5. *
  6. *   version 2, full session layer, TK started 6/17/87
  7. *
  8. ****************************************************************************
  9. *                                                                          *
  10. *      part of:                                                            *
  11. *      Network kernel for NCSA Telnet                                      *
  12. *      by Tim Krauskopf                                                    *
  13. *                                                                          *
  14. *      National Center for Supercomputing Applications                     *
  15. *      152 Computing Applications Building                                 *
  16. *      605 E. Springfield Ave.                                             *
  17. *      Champaign, IL  61820                                                *
  18. *                                                                          *
  19. *    Copyright (c) 1987, Board of Trustees of the University of Illinois   *
  20. *                                                                          *
  21. ****************************************************************************
  22. */
  23. #include <stdio.h>
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <Memory.h>
  27. #include <CType.h>
  28.  
  29. #include "protocol.h"
  30. #include "hostform.h"
  31. #include "tools.h"
  32. #include "macutil.h"
  33. #include "util.h"
  34. #include "user.h"
  35. #include "dlayer.h"
  36.  
  37. #define NUMSPECS 135    /* NCSA 2.5 */
  38.  
  39. char                             /* special function types */
  40.             *neterrstring();
  41. int32 time();                    /* don't forget this sucker! */
  42.  
  43. static struct machinfo *Smachlist,*Smptr;
  44. struct machinfo *Sns=NULL;
  45.  
  46. static unsigned char *Smachfile = {"config.tel"},
  47.             Sflags[NUMSPECS-95],    /* which parms we have or have not */
  48.             *Sspace;
  49.  
  50. struct config Scon = {
  51.         0,0,0,0,
  52.         0,
  53.         3,
  54.         127,0,0,1,
  55.         "",
  56.         7,1,0x70,
  57.         "MacTCP",    /* NCSA 2.5 */
  58.         "ega",
  59.         0,        /* BYU 2.4.9 - BIOS anyone? */
  60.         1,        /* BYU 2.4.9 - enable tek graphics */
  61.         0,        /* BYU 2.4.9 - disable ftp */
  62.         1,        /* BYU 2.4.9 - enable rcp */
  63.         0,        /* BYU 2.4.9 - no command keys */
  64.         "DEC-VT100",
  65.         "*",
  66.         NULL,
  67.         NULL,
  68.         NULL,
  69.         NULL,
  70.         NULL,
  71.         NULL,
  72.         1,
  73.         4,
  74.         3,
  75.         -1,
  76.         120,
  77.         0x0d000,
  78.         0x0300,
  79.         0
  80. };
  81.  
  82. int
  83. Sxxnf[3] = NFDEF,
  84. Sxxnb[3] = NBDEF,
  85. Sxxbf[3] = BFDEF,
  86. Sxxbb[3] = BBDEF,
  87. Sxxuf[3] = UFDEF,
  88. Sxxub[3] = UBDEF;
  89.  
  90. static int
  91.         mno=0,                    /* how many machines in host file */
  92.         lineno,                    /* line number in hosts file */
  93.         position,                /* position for scanning string */
  94.         constate,                /* state for config file parser */
  95.         inquote;                /* flag, inside quotes now */
  96.  
  97. int TekFound=0;
  98.  
  99. /*
  100. *   States for config file reading state machine.
  101. *   One for each type of keyword and some for controlling.
  102. */
  103.  
  104. #define    CONNAME    101
  105. #define CONHOST    102
  106. #define CONIP    103
  107. #define CONGATE    104
  108. #define CONCOLOR 105
  109. #define CONBKSP    106
  110. #define CONBKSC    107
  111. #define CONRETR    108
  112. #define CONWIND    109
  113. #define CONSEG    110
  114. #define CONMTU    111
  115. #define CONNS    112
  116. #define CONTO    113
  117. #define CONCRMAP 114
  118. #define CONDUP  115
  119. #define CONWRAP 116
  120. #define CONWIDE 117
  121. #define CONFONT 118
  122. #define CONFSIZE 119
  123. #define CONNF 120
  124. #define CONNB 121
  125. #define CONBF 122
  126. #define CONBB 123
  127. #define CONUF 124
  128. #define CONUB 125
  129. #define CONRF 126
  130. #define CONRB 127
  131. #define CONCLMODE 128
  132. #define CONPORT 129
  133. #define CONLINES 130
  134. #define CONLKEYS 131
  135. /*
  136. *  above this line are per machine entries, below are configuration entries
  137. */
  138. #define CONMYIP    132
  139. #define CONHPF  133
  140. #define CONPSF  134
  141. #define CONTEKF 135
  142. #define CONJTIME 136
  143. #define CONME    137
  144. #define CONCCOL    138
  145. #define CONHW    139
  146. #define CONADDR    140
  147. #define CONIOA    141
  148. #define CONDEF  142
  149. #define CONCKEYS 143
  150. #define CONINT    144
  151. #define CONBIOS    145
  152. #define CONTEK    146
  153. #define CONVIDEO    147
  154. #define CONFTP    148
  155. #define CONRCP    149
  156. #define CONPASS    150
  157. #define CONCAP    151
  158. #define CONTTYPE    152
  159. #define CONNSTYPE     153
  160. #define CONFROM    154
  161. #define CONARPTO 155
  162. #define CONZONE 156
  163. #define CONNDOM  157
  164. #define CONDOMTO 158
  165. #define CONBLOCK 159
  166. #define    CONMASK    160
  167. #define CONTEKT    161            /* BYU 2.4.9 - corresponds to offset 32 in Sflags[] */
  168. #define CONLINEMODE 162        /* BYU 2.4.9 - corresponds to offset 33 in Sflags[] */
  169. #define CONEIGHTBIT 163        /* BYU 2.4.9 - corresponds to offset 34 in Sflags[] */
  170. #define CONFORCESAVE 164    /* NCSA 2.5: force lines to be saved */
  171.  
  172. char *Skeyw[] = {
  173.         "",    
  174.         "name",                            /* name of session */
  175.         "host",                            /* name of host */
  176.         "hostip",                        /* IP number */
  177.         "gateway",                        /* gateway level */
  178.         "color",                        /* color code  ==5== */
  179.         "erase",                        /* value to use for backspace */
  180.         "scrollback",                    /* how many lines to backscroll */
  181.         "retrans",                        /* initial retrans time */
  182.         "rwin",                            /* window to allow for this host */
  183.         "maxseg",                        /* maximum transfer size (in) ==10== */
  184.         "mtu",                            /* transfer unit (out) */
  185.         "nameserver",                    /* name server level */
  186.         "contime",                        /* timeout for opening connection */
  187.         "crmap",                        /* map for Berkeley 4.3 compatibility */
  188.         "duplex",                        /* half duplex for IBM machines */
  189.         "vtwrap",                        /* should VT wrap? */
  190.         "vtwidth",                        /* width of VT100 screen */
  191.         "font",                            /* font to use, when given a choice */
  192.         "fsize",                        /* font size, in points */
  193.         "nfcolor",                        /* normal foreground color */
  194.         "nbcolor",                        /* normal background color */
  195.         "bfcolor",                        /* blink foreground color */
  196.         "bbcolor",                        /* blink background color */
  197.         "ufcolor",                        /* underline foreground color */
  198.         "ubcolor",                        /* underline background color */
  199.         "rfcolor",                        /* reverse foreground color */
  200.         "rbcolor",                        /* reverse background color */
  201.         "clearsave",                    /* clear screen saves lines */
  202.         "port",                            /* TCP port to go for */
  203.         "vtlines",                        /* number of lines for the VT100 window */
  204.         "localkeys",                    /* keys to use for int,susp,resume */
  205. /*
  206. *  following are one-time entries, above are part of the data structure
  207. */
  208.         "myip",                            /* local machine's IP # */
  209.         "hpfile",                        /* HPGL output file */
  210.         "psfile",                        /* postscript output file */
  211.         "tekfile",                        /* tektronix output file */
  212.         "timeslice",                    /* timer slice for multi-tasking */
  213.         "myname",                        /* identifying info ==15==*/
  214.         "concolor",                        /* console colors */
  215.         "hardware",                        /* network hardware */
  216.         "address",                        /* Address of hardware */
  217.         "ioaddr",                        /* ioaddress of hardware */
  218.         "domain",                        /* default domain for lookup */
  219.         "commandkeys",                    /* use command keys on mac */
  220.         "interrupt",                    /* interrupt request 3 or 5 */
  221.         "bios",                            /* use BIOS screen */
  222.         "tek",                            /* tektronix graphics ==20==*/
  223.         "video",                        /* type of video hardware */
  224.         "ftp",                            /* enable ftp? */
  225.         "rcp",                            /* enable rcp? */
  226.         "passfile",                        /* password file name */
  227.         "capfile",                        /* capture file name */
  228.         "termtype",                        /* terminal type */
  229.         "nameservertype",                /* nameserver type */
  230.         "copyfrom",                        /* copy from another machine */
  231.         "arptime",                        /* time-out for ARPs */
  232.         "zone",                            /* NBP zone for Macs */
  233.         "domainretry",                    /* # of retries */
  234.         "domaintime",                    /* time-out for DOMAIN */
  235.         "block",                        /* blocking for network update */
  236.         "netmask",                        /* subnetting mask */
  237.         "tektype",                        /* the TEK emulation:0 for 4014, 1 for 4105 */
  238.         "linemode",                        /* enable line mode? */        /* BYU 2.4.9 */
  239.         "eightbit",                        /* display 8 bit font */    /* BYU 2.4.9 */
  240.         "forcesave",                    /* NCSA 2.5 */
  241.         ""
  242.     };
  243.  
  244.  
  245.  
  246. /************************************************************************/
  247. /*  Sgetconfig
  248. *   copy the configuration information into the user's data structure
  249. *   directly.  The user can do with it what he feels like.
  250. */
  251. void Sgetconfig
  252.   (
  253.     struct config *cp
  254.   )
  255.     {
  256.  
  257.     movenbytes(cp,&Scon,sizeof(struct config));
  258. }
  259.  
  260. /************************************************************************/
  261. /*  Serrline
  262. *   prints the line number of the host file error and posts the event
  263. *   for the line number error and posts the hosts file error.
  264. */
  265.  
  266. void Serrline
  267.   (
  268.     int n
  269.   )
  270.     {
  271.     char *p;
  272.  
  273.     p = neterrstring(-1);
  274.     sprintf(p,"Config file: error in line %4d",lineno+1);
  275.     netposterr(-1);
  276.  
  277.     netposterr(n);
  278. }
  279.  
  280. /**************************************************************************/
  281. /*  Sissep
  282. *   is the character a valid separator for the hosts file?
  283. *   separators are white space, special chars and :;=
  284. *
  285. */
  286. int Sissep
  287.   (
  288.     int c
  289.   )
  290.     {
  291.     if (c < 33)
  292.         return(1);
  293.     if (c == ':' || c == ';' || c == '=')
  294.         return(1);
  295.     return(0);
  296. }
  297.  
  298. /************************************************************************/
  299. /*  ncstrcmp
  300. *   No case string compare.
  301. *   Only returns 0=match, 1=no match, does not compare greater or less
  302. *   There is a tiny bit of overlap with the | 32 trick, but shouldn't be
  303. *   a problem.  It causes some different symbols to match.
  304. */
  305. ncstrcmp(sa,sb)
  306.     char *sa,*sb;
  307.     {
  308.  
  309.     while (*sa && *sa < 33)        /* don't compare leading spaces */
  310.         sa++;
  311.     while (*sb && *sb < 33)
  312.         sb++;
  313.  
  314.     while (*sa && *sb) {
  315.         if ((*sa != *sb) && ((*sa | 32) != (*sb | 32)))
  316.             return(1);
  317.         sa++;sb++;
  318.     }
  319.     if (!*sa && !*sb)        /* if both at end of string */
  320.         return(0);
  321.     else
  322.         return(1);
  323. }
  324.  
  325. struct machinfo 
  326. *Shostlook(hname)
  327.     char *hname;
  328.     {
  329.     struct machinfo *m;
  330.     m = Smachlist;
  331.     while (m != NULL) {
  332.  
  333.         if (m->sname && !ncstrcmp(hname,m->sname)) 
  334.             return(m);
  335.  
  336.         m = m->next;
  337.     }
  338.  
  339.     m = Smachlist;
  340.     while (m != NULL) {
  341.         if (m->hname && !ncstrcmp(hname,m->hname))
  342.             return(m);
  343.  
  344.         m = m->next;
  345.     }
  346.  
  347.     return(NULL);
  348.  
  349. }
  350.  
  351. /************************************************************************/
  352. /*  Scopyfrom
  353. *   Look at the Sflags array to determine which elements to copy from
  354. *   a previous machine's entries.  If a machine name as been given as
  355. *   "default", the state machine will fill in the fields from that
  356. *   machine's entries.
  357. *
  358. *   If the machine name to copyfrom is not present in the list, set the
  359. *   program default values for each field.
  360. */
  361. void Scopyfrom
  362.   (
  363.     char *s
  364.   )
  365.     {
  366.     struct machinfo *m;
  367.     int i,j;
  368.  
  369.     m = Shostlook(s);            /* search list */
  370.  
  371.     for (i=3; i <= NUMSPECS-100; i++)         /* through list of parms */
  372.         if (!Sflags[i]) {
  373.             j=i;
  374.             if (i==32) j=61;
  375.             else if (i==33) j=62;            /* BYU 2.4.9 */
  376.             else if (i==34) j=63;            /* BYU 2.4.9 */
  377.             else if (i==35) j=64;            /* NCSA 2.5 */
  378.  
  379.             if (m) switch (100+j) {
  380.                 case CONHOST:
  381.                     Smptr->hname = m->hname;
  382.                     break;
  383.                 case CONIP:
  384.                     movebytes(Smptr->hostip,m->hostip,4);
  385.                     Smptr->mstat = m->mstat;
  386.                     break;
  387.                 case CONGATE:            /* gateways cannot be copied from */
  388.                     Smptr->gateway = 0;
  389.                     break;
  390.                 case CONNS:                    /* can't copy nameservers either */
  391.                     Smptr->nameserv = 0;
  392.                     break;
  393.  
  394.                 case CONBKSP:
  395.                     Smptr->bksp = m->bksp;
  396.                     break;
  397.                 case CONBKSC:
  398.                     Smptr->bkscroll = m->bkscroll;
  399.                     break;
  400.                 case CONCLMODE:
  401.                     Smptr->clearsave = m->clearsave;
  402.                     break;
  403.                 case CONLINEMODE:                        /* BYU 2.4.9 */
  404.                     Smptr->linemode = m->linemode;        /* BYU 2.4.9 */
  405.                     break;                                /* BYU 2.4.9 */
  406.                 case CONEIGHTBIT:                        /* BYU 2.4.9 */
  407.                     Smptr->eightbit = m->eightbit;        /* BYU 2.4.9 */
  408.                     break;                                /* BYU 2.4.9 */
  409.                 case CONFORCESAVE:                        /* NCSA 2.5 final */
  410.                     Smptr->forcesave = m->forcesave;    /* NCSA 2.5 final */
  411.                     break;                                /* NCSA 2.5 final */
  412.                 case CONRETR:
  413.                     Smptr->retrans = m->retrans;
  414.                     break;
  415.                 case CONWIND:
  416.                     Smptr->window = m->window;
  417.                     break;
  418.                 case CONSEG:
  419.                     Smptr->maxseg = m->maxseg;
  420.                     break;
  421.                 case CONMTU:
  422.                     Smptr->mtu = m->mtu;
  423.                     break;
  424.  
  425.                 case CONTO:
  426.                     Smptr->conto = m->conto;
  427.                     break;
  428.                 case CONCRMAP:
  429.                     Smptr->crmap = m->crmap;
  430.                     break;
  431.                 case CONDUP:
  432.                     Smptr->halfdup = m->halfdup;
  433.                     break;
  434.                 case CONTEKT:
  435.                     Smptr->tektype = m->tektype;
  436.                     break;
  437.                 case CONWRAP:
  438.                     Smptr->vtwrap = m->vtwrap;
  439.                     break;
  440.                 case CONWIDE:
  441.                     Smptr->vtwidth = m->vtwidth;
  442.                     break;
  443.                 case CONLINES:
  444.                     Smptr->nlines = m->nlines;
  445.                     break;
  446.  
  447.                 case CONNF:
  448.                     movebytes(Smptr->nfcolor,m->nfcolor,3*sizeof(int));
  449.                     break;
  450.                 case CONNB:
  451.                     movebytes(Smptr->nbcolor, m->nbcolor,3*sizeof(int));
  452.                     break;
  453.                 case CONBF:
  454.                     movebytes(Smptr->bfcolor,m->bfcolor,3*sizeof(int));
  455.                     break;
  456.                 case CONBB:
  457.                     movebytes(Smptr->bbcolor,m->bbcolor,3*sizeof(int));
  458.                     break;
  459.                 case CONUF:
  460.                     movebytes(Smptr->ufcolor,m->ufcolor,3*sizeof(int));
  461.                     break;
  462.                 case CONUB:
  463.                     movebytes(Smptr->ubcolor,m->ubcolor,3*sizeof(int));
  464.                     break;
  465.  
  466.                 case CONLKEYS:
  467.                     Smptr->ckey = m->ckey;
  468.                     Smptr->skey = m->skey;
  469.                     Smptr->qkey = m->qkey;
  470.                     break;
  471.  
  472.                 case CONFONT:
  473.                     Smptr->font = m->font;
  474.                     break;
  475.                 case CONFSIZE:
  476.                     Smptr->fsize = m->fsize;
  477.                     break;
  478.                 case CONPORT:
  479.                     Smptr->port = m->port;
  480.                     break;
  481.  
  482.                 default:
  483.                     break;
  484.             }
  485.             else
  486.             switch (100+j) {        /* m=NULL, install default values */
  487.                 case CONHOST:
  488.                     Smptr->hname = NULL;
  489.                     break;
  490.                 case CONIP:
  491.                     Smptr->mstat = NOIP;
  492.                     break;
  493.                 case CONGATE:            /* gateways cannot be copied from */
  494.                     Smptr->gateway = 0;
  495.                     break;
  496.                 case CONBKSP:
  497.                     Smptr->bksp = 127;
  498.                     break;
  499.                 case CONBKSC:
  500.                     Smptr->bkscroll = 0;
  501.                     break;
  502.                 case CONCLMODE:
  503.                     Smptr->clearsave = 1;
  504.                     break;
  505.                 case CONLINEMODE:                        /* BYU 2.4.9 */
  506.                     Smptr->linemode = 1;                /* BYU 2.4.9 */
  507.                     break;                                /* BYU 2.4.9 */
  508.                 case CONEIGHTBIT:                        /* BYU 2.4.9 */
  509.                     Smptr->eightbit = 1;                /* BYU 2.4.9 */
  510.                     break;                                /* BYU 2.4.9 */
  511.                 case CONRETR:
  512.                     Smptr->retrans = SMINRTO;
  513.                     break;
  514.                 case CONWIND:
  515. #ifdef MAC
  516.                     Smptr->window = 512;
  517. #else
  518.                     Smptr->window = DEFWINDOW;
  519. #endif
  520.                     break;
  521.                 case CONSEG:
  522. #ifdef MAC
  523.                     Smptr->maxseg = 512;
  524. #else
  525.                     Smptr->maxseg = DEFSEG;
  526. #endif
  527.                     break;
  528.                 case CONMTU:
  529. #ifdef MAC
  530.                     Smptr->mtu = 512;
  531. #else
  532.                     Smptr->mtu = TSENDSIZE;
  533. #endif
  534.                     break;
  535.  
  536.                 case CONNS:                    /* can't copy nameservers either */
  537.                     Smptr->nameserv = 0;
  538.                     break;
  539.         
  540.                 case CONTO:
  541.                     Smptr->conto = CONNWAITTIME;
  542.                     break;
  543.  
  544.                 case CONCRMAP:
  545.                     Smptr->crmap = 10;
  546.                     break;
  547.  
  548.                 case CONDUP:
  549.                     Smptr->halfdup = 0;
  550.                     break;
  551.                 case CONWRAP:
  552.                     Smptr->vtwrap = 0;
  553.                     break;
  554.                 case CONWIDE:
  555.                     Smptr->vtwidth = 80;
  556.                     break;
  557.                 case CONTEKT:
  558.                     Smptr->tektype = 0;
  559.                     break;
  560.                 case CONLINES:
  561.                     Smptr->nlines = 24;        /* overall default to 24 lines */
  562.                     break;
  563.  
  564.                 case CONNF:
  565.                     movebytes(Smptr->nfcolor,Sxxnf,3*sizeof(int));
  566.                     break;
  567.                 case CONNB:
  568.                     movebytes(Smptr->nbcolor,Sxxnb,3*sizeof(int));
  569.                     break;
  570.                 case CONBF:
  571.                     movebytes(Smptr->bfcolor,Sxxbf,3*sizeof(int));
  572.                     break;
  573.                 case CONBB:
  574.                     movebytes(Smptr->bbcolor,Sxxbb,3*sizeof(int));
  575.                     break;
  576.                 case CONUF:
  577.                     movebytes(Smptr->ufcolor,Sxxuf,3*sizeof(int));
  578.                     break;
  579.                 case CONUB:
  580.                     movebytes(Smptr->ubcolor,Sxxub,3*sizeof(int));
  581.                     break;
  582.  
  583.                 case CONLKEYS:
  584.                     Smptr->ckey = 3;            /* Ctrl-C */
  585.                     Smptr->skey = 19;            /* Ctrl-S */
  586.                     Smptr->qkey = 17;            /* Ctrl-Q */
  587.                     break;
  588.  
  589.                 case CONFONT:
  590.                     Smptr->font = "Monaco";
  591.                     break;
  592.                 case CONFSIZE:
  593.                     Smptr->fsize = 9;
  594.                     break;
  595.                 case CONPORT:
  596.                     Smptr->port = 23;            /* the telnet port */
  597.                     break;
  598.                 case CONFORCESAVE:                /* NCSA 2.5 */
  599.                     Smptr->forcesave = 0;        /* NCSA 2.5 */
  600.                     break;                        /* NCSA 2.5 */
  601.  
  602.                 default:
  603.                     break;
  604.             }
  605.         }
  606.  
  607.     Sflags[0] = 1;                    /* set that this machine was copied */
  608. } /* Scopyfrom */
  609.  
  610. /************************************************************************/
  611. /*  Sconfile
  612. *   take the characters read from the file and parse them for keywords
  613. *   which require configuration action.
  614. */
  615. int Sconfile
  616.   (
  617.     char *s
  618.   )
  619.     {
  620.     int i,a,b,c,d;
  621.  
  622.     switch (constate) {
  623.         case 0:                                /* lookup keyword */
  624.             if (!(*s))                        /* empty token */
  625.                 return(0);
  626.  
  627.  
  628.             for (i=1; *Skeyw[i] && ncstrcmp(Skeyw[i],s); i++)
  629.                     ;
  630.             if (!(*Skeyw[i])) {            /* not in list */
  631.                 Serrline(902);
  632.                 return(0);                /* don't die - helps backward compatibility */
  633.             }
  634.             constate = 100+i;    /* change to state for keyword */
  635. /*
  636. *  check if this is a machine specific parm without a machine to
  637. *  give it to.  "name" being the only machine specific parm allowed, of course
  638. */
  639.             if (Smptr == NULL && constate > 101 && constate <= NUMSPECS) {
  640.                 Serrline(905);
  641.                 return(1);
  642.             }
  643.             break;
  644.  
  645.         case CONNAME:
  646. /*
  647. *  allocate space for upcoming parameters
  648. */
  649.             if (Smachlist == NULL) {
  650.                 Smachlist = (struct machinfo *)NewPtr(sizeof(struct machinfo));
  651.                 Smptr = Smachlist;
  652.                 Smptr->sname = NULL;
  653.                 Smptr->hname = NULL;
  654.             }
  655.             else {
  656.                 if (!Sflags[0]) {
  657.                     if (ncstrcmp("default",Smptr->sname))
  658.                         Scopyfrom("default");
  659.                     else
  660.                         Scopyfrom("==");    /* to make sure 'default' gets set */
  661.                 }
  662.                 Smptr->next = 
  663.                     (struct machinfo *)NewPtr(sizeof(struct machinfo));
  664.                 Smptr = Smptr->next;
  665.             }
  666.             Smptr->next = NULL;
  667.             Smptr->hname = NULL;                /* guarantee to be null */
  668.             (Ptr) Smptr->sname = NewPtr(position);    /* size of name string */
  669.             strcpy(Smptr->sname,s);                /* keep name field */
  670.             constate = 0;                        /* back to new keyword */
  671.             for (i=0; i<NUMSPECS-99; i++)
  672.                 Sflags[i] = 0;                    /* we have no parms */
  673.             Smptr->mno = ++mno;                    /* new machine number */
  674.             break;
  675.  
  676.         case CONHOST:                            /* also a name */
  677.             (Ptr) Smptr->hname = NewPtr(position);
  678.             strcpy(Smptr->hname,s);
  679.             constate = 0;
  680.             Sflags[CONHOST-100] = 1;
  681.             break;
  682.  
  683.         case CONIP:                                /* IP number for host */
  684.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  685.                 Serrline(906);
  686.                 return(3);
  687.             }
  688.             Smptr->hostip[0]=a; Smptr->hostip[1] =b;     /* keep number */
  689.             Smptr->hostip[2]=c; Smptr->hostip[3] =d;
  690.             Smptr->mstat = HFILE;
  691.             constate = 0;
  692.             Sflags[CONIP-100] = 1;
  693.             break;
  694.  
  695.         case CONGATE:
  696.             Smptr->gateway = atoi(s);            /* gateway level */
  697.             constate = 0;
  698.             Sflags[CONGATE-100] = 1;
  699.             break;
  700.  
  701.         case CONCOLOR:                    /* support old format */
  702.             Smptr->nfcolor[0] = s[1]-48;
  703.             Smptr->nbcolor[0] = s[0]-48;
  704.             Smptr->bfcolor[0] = s[5]-48;
  705.             Smptr->bbcolor[0] = s[4]-48;
  706.             Smptr->ufcolor[0] = s[3]-48;
  707.             Smptr->ubcolor[0] = s[2]-48;
  708.             constate = 0;
  709.             Sflags[CONNF-100] = 1;        /* sets them all at one shot */
  710.             Sflags[CONNB-100] = 1;
  711.             Sflags[CONBF-100] = 1;
  712.             Sflags[CONBB-100] = 1;
  713.             Sflags[CONUF-100] = 1;
  714.             Sflags[CONUB-100] = 1;
  715.             break;
  716.  
  717.         case CONNF:                        /* foreground normal color */
  718.             if (Scolorset(Smptr->nfcolor,s))
  719.                 Sflags[CONNF-100] = 1;
  720.             constate = 0;
  721.             break;
  722.         case CONNB:                        /* background normal color */
  723.             if (Scolorset(Smptr->nbcolor,s))
  724.                 Sflags[CONNB-100] = 1;
  725.             constate = 0;
  726.             break;
  727.         case CONRF:
  728.         case CONBF:                        /* blink foreg color */
  729.             if (Scolorset(Smptr->bfcolor,s))
  730.                 Sflags[CONBF-100] = 1;    /* in copyfrom, r's are really b's */
  731.             constate = 0;
  732.             break;
  733.         case CONRB:
  734.         case CONBB:                        /* blink bg color */
  735.             if (Scolorset(Smptr->bbcolor,s))
  736.                 Sflags[CONBB-100] = 1;
  737.             constate = 0;
  738.             break;
  739.         case CONUF:                        /* foreground underline color */
  740.             if (Scolorset(Smptr->ufcolor,s))
  741.                 Sflags[CONUF-100] = 1;
  742.             constate = 0;
  743.             break;
  744.         case CONUB:                        /* bg underline color */
  745.             if (Scolorset(Smptr->ubcolor,s))
  746.                 Sflags[CONUB-100] = 1;
  747.             constate = 0;
  748.             break;
  749.  
  750.         case CONLKEYS:                    /* local key bindings */
  751.             { int a,b,c;
  752.                 if (3!=sscanf(s,"{%d,%d,%d}", &a, &b, &c))
  753.                     Smptr->ckey = Smptr->skey = Smptr->qkey = 0;    /* default = off */
  754.                 else {
  755.                     Smptr->ckey = a;
  756.                     Smptr->skey = b;
  757.                     Smptr->qkey = c;
  758.                 }
  759.             }
  760.             Sflags[CONLKEYS-100] = 1;
  761.             constate = 0;
  762.             break;
  763.  
  764.         case CONBKSP:
  765.             if (!ncstrcmp(s,"backspace"))
  766.                 Smptr->bksp = 8;
  767.             else
  768.                 Smptr->bksp = 127;
  769.             constate = 0;
  770.             Sflags[CONBKSP-100] = 1;
  771.             break;
  772.  
  773.         case CONBKSC:
  774.             Smptr->bkscroll = atoi(s);
  775.             constate = 0;
  776.             Sflags[CONBKSC-100] = 1;
  777.             break;
  778.  
  779.         case CONRETR:
  780.             Smptr->retrans = atoi(s);
  781.             constate = 0;
  782.             Sflags[CONRETR-100] = 1;
  783.             break;
  784.  
  785.         case CONWIND:
  786.             Smptr->window = atoi(s);
  787.             constate = 0;
  788.             Sflags[CONWIND-100] = 1;
  789.             break;
  790.  
  791.         case CONSEG:
  792.             Smptr->maxseg = atoi(s);
  793.             constate = 0;
  794.             Sflags[CONSEG-100] = 1;
  795.             break;
  796.  
  797.         case CONMTU:
  798.             Smptr->mtu = atoi(s);
  799.             constate = 0;
  800.             Sflags[CONMTU-100] = 1;
  801.             break;
  802.  
  803.         case CONNS:
  804.             Smptr->nameserv = atoi(s);
  805.             if (!Sns || (Sns->nameserv > Smptr->nameserv))    /* keep NS */
  806.                 Sns = Smptr;
  807.             constate = 0;
  808.             Sflags[CONNS-100] = 1;
  809.             break;
  810.  
  811.         case CONTO:
  812.             i = atoi(s);
  813.             if (i > 2) {
  814.                 Smptr->conto = i;
  815.                 Sflags[CONTO-100] = 1;
  816.             }
  817.             constate = 0;
  818.             break;
  819.  
  820.         case CONCRMAP:
  821.             if (!ncstrcmp(s,"4.3BSDCRNUL")) 
  822.                 Smptr->crmap = 0;
  823.             else
  824.                 Smptr->crmap = 10;
  825.             Sflags[CONCRMAP-100] = 1;
  826.             constate = 0;
  827.             break;
  828.  
  829.         case CONDUP:
  830.             if (!ncstrcmp(s,"half")) {
  831.                 Smptr->halfdup = 1;
  832.                 Sflags[CONDUP-100] = 1;
  833.             }
  834.             constate = 0;
  835.             break;
  836.  
  837.         case CONWRAP:
  838.             if ('Y' == toupper(s[0])) 
  839.                 Smptr->vtwrap = 1;
  840.             else
  841.                 Smptr->vtwrap = 0;
  842.             Sflags[CONWRAP-100] = 1;
  843.             constate = 0;
  844.             break;
  845.  
  846.         case CONCLMODE:
  847.             if ('N' == toupper(s[0])) 
  848.                 Smptr->clearsave = 0;
  849.             else
  850.                 Smptr->clearsave = 1;
  851.             Sflags[CONCLMODE-100] = 1;
  852.             constate = 0;
  853.             break;
  854.  
  855.         case CONFONT:
  856.             (Ptr) Smptr->font = NewPtr(position);
  857.             strcpy(Smptr->font,s);
  858.             Sflags[CONFONT-100] = 1;
  859.             constate = 0;
  860.             break;
  861.  
  862.         case CONFSIZE:
  863.             Smptr->fsize = atoi(s);
  864.             Sflags[CONFSIZE-100] = 1;
  865.             constate = 0;
  866.             break;
  867.  
  868.         case CONWIDE:
  869.             if (132 == atoi(s)) 
  870.                 Smptr->vtwidth = 132;
  871.             else
  872.                 Smptr->vtwidth = 80;
  873.  
  874.             Sflags[CONWIDE-100] = 1;
  875.             constate = 0;
  876.             break;
  877.  
  878.         case CONTEKT:
  879.             if (!ncstrcmp(s,"4014"))            /* NCSA 2.5 */
  880.                 Smptr->tektype = 0;                /* NCSA 2.5 */
  881.             else if (!ncstrcmp(s,"4105"))        /* NCSA 2.5 */
  882.                 Smptr->tektype = 1;                /* NCSA 2.5 */
  883.             else if (!ncstrcmp(s,"none"))        /* NCSA 2.5 */
  884.                 Smptr->tektype = -1;            /* NCSA 2.5 */
  885.  
  886.             Sflags[32] = 1;
  887.             TekFound=1;
  888.             constate = 0;
  889.             break;
  890.  
  891.         case CONLINES:
  892.             i = atoi(s);
  893.             if (i > 6 && i < 100)
  894.                 Smptr->nlines = i;
  895.             else
  896.                 Smptr->nlines = 24;            /* default is 24 lines */
  897.             Sflags[CONLINES-100] = 1;
  898.             constate = 0;
  899.             break;
  900.  
  901.         case CONPORT:                        /* File name for Tek dump */
  902.             i = atoi(s);
  903.             if (i < 1)
  904.                 i = 23;
  905.             Smptr->port = i;
  906.             Sflags[CONPORT-100] = 1;
  907.             constate = 0;
  908.             break;
  909.  
  910. /*
  911. *  now the one-time entries
  912. *  Generally this information goes into the "Scon" structure for later
  913. *  retrieval by other routines.
  914. *
  915. */
  916. #ifdef PC
  917.         case CONMASK:
  918.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  919.                 Serrline(907);
  920.                 return(3);
  921.             }
  922.             Scon.netmask[0]=a; Scon.netmask[1] =b;     
  923.             Scon.netmask[2]=c; Scon.netmask[3] =d;
  924.             Scon.havemask=1;
  925.             constate = 0;
  926.             break;
  927.  
  928.         case CONMYIP:
  929.             constate = 0;
  930.             if (!ncstrcmp(s,"rarp")) {
  931.                 movebytes(Scon.myipnum,s,4);
  932.                 netsetip("RARP");
  933.                 break;
  934.             }
  935.             if ( 4 != sscanf(s,"%d.%d.%d.%d",&a,&b,&c,&d)) {
  936.                 Serrline(908);
  937.                 return(3);
  938.             }
  939.             Scon.myipnum[0]=a; Scon.myipnum[1] =b;     /* put number back in s */
  940.             Scon.myipnum[2]=c; Scon.myipnum[3] =d;
  941.             netsetip(Scon.myipnum);        /* make permanent set */
  942.             break;
  943. #endif
  944.         case CONME:                /* what my name is  */
  945.             strncpy(Scon.me,s,30);
  946.             Scon.me[30] = '\0';
  947.             constate = 0;
  948.             break;
  949.  
  950.         case CONHW:                /* what hardware are we using? */
  951.             i = strlen(s);
  952.             if (i > 9) i = 9;
  953.             s[i] = '\0';
  954.             i--;
  955.             while (i--)
  956.                 s[i] = tolower(s[i]);
  957.             strcpy(Scon.hw,s);
  958.             constate = 0;
  959.             break;
  960.  
  961. #ifdef PC
  962.         case CONINT:            /* what IRQ to use */
  963.             sscanf(s,"%x",&i);
  964.             Scon.irqnum = i;
  965.             constate = 0;
  966.             break;
  967.  
  968.         case CONBIOS:
  969.             if (toupper(*s) == 'Y') {
  970.                 Scwritemode(0);
  971.                 Scon.bios = 1;
  972.             }
  973.             constate = 0;
  974.             break;
  975.  
  976.         case CONADDR:                /* segment address for board */
  977.             sscanf(s,"%x",&i);
  978.             Scon.address = i;
  979.             constate = 0;
  980.             break;
  981.  
  982.         case CONIOA:                /* io address for board */
  983.             sscanf(s,"%x",&i);
  984.             Scon.ioaddr = i;
  985.             constate = 0;
  986.             break;
  987. #endif
  988. #ifdef MAC
  989.         case CONCKEYS:
  990.             if (toupper(*s) == 'Y') {
  991.                 Scon.comkeys = 1;
  992.             }
  993.             constate = 0;
  994.             break;
  995.  
  996.         case CONZONE:
  997.             Scon.zone = NewPtr(position);    /* space for name */
  998.             strcpy(Scon.zone,s);            /* copy it in */
  999.             constate = 0;
  1000.             break;
  1001.  
  1002.         case CONJTIME:                /* Time slice */
  1003.             i = atoi(s);
  1004.             if (i > 1)
  1005.                 Scon.timesl = i;
  1006.             constate = 0;
  1007.             break;
  1008. #endif        
  1009.  
  1010.         case CONTEK:
  1011.             if (toupper(*s) == 'N') {
  1012.                 Stekmode(0);
  1013.                 Scon.tek = 0;
  1014.             }
  1015.             constate = 0;
  1016.             break;
  1017.  
  1018.         case CONVIDEO:
  1019.             i = strlen(s);
  1020.             if (i > 9) i = 9;
  1021.             s[i] = '\0';
  1022.             strcpy(Scon.video,s);
  1023.             i--;
  1024.             while (i--)
  1025.                 s[i] = tolower(s[i]);
  1026.             constate = 0;
  1027.             break;
  1028.  
  1029.         case CONTTYPE:
  1030.             (Ptr) Scon.termtype = NewPtr(position);
  1031.             strcpy(Scon.termtype,s);
  1032.             constate = 0;
  1033.             break;
  1034.  
  1035.         case CONCCOL:
  1036.             for (i=0; i<3; i++)
  1037.                 Scon.color[i] = ((s[i*2]-48)<<4) + (s[i*2+1]-48);
  1038.             constate = 0;
  1039.             break;
  1040.  
  1041.         case CONFTP:
  1042.             if (toupper(*s) == 'N') 
  1043.                 Scon.ftp = 0;    
  1044.             else                            /* BYU 2.4.10 */
  1045.                 Scon.ftp = 1;                /* BYU 2.4.10 */
  1046.             constate = 0;
  1047.             break;
  1048.  
  1049.         case CONRCP:
  1050.             if (toupper(*s) == 'N')
  1051.                 Scon.rcp = 0;
  1052.             constate = 0;
  1053.             break;
  1054.  
  1055.         case CONPASS:
  1056.             (Ptr) Scon.pass = NewPtr(position);    /* space for name */
  1057.             strcpy(Scon.pass,s);            /* copy it in */
  1058.             constate = 0;
  1059.             break;
  1060.  
  1061.         case CONDEF:                        /* default domain */
  1062.             (Ptr) Scon.defdom = NewPtr(position);    /* space for name */
  1063.             strcpy(Scon.defdom,s);            /* copy it in */
  1064.             constate = 0;
  1065.             break;
  1066.  
  1067.         case CONCAP:                        /* capture file name */
  1068.             Snewcap(s);
  1069.             constate = 0;
  1070.             break;
  1071.  
  1072.         case CONFROM:                        /* copy the rest from another */
  1073.                                             /* entry in the table */
  1074.             Scopyfrom(s);
  1075.             Sflags[0] = 1;                    /* indicate did copy from */
  1076.             constate = 0;
  1077.             break;
  1078.  
  1079.         case CONARPTO:                        /* need to lengthen arp time-out (secs) */
  1080.             i = atoi(s);
  1081.             if (i > 0)
  1082.                 netarptime(i);
  1083.             constate = 0;                    /* don't forget me! */
  1084.             break;
  1085.  
  1086.         case CONBLOCK:                        /* blocking factor for text */
  1087.             i = atoi(s);
  1088.             if (i > 4096) i = 4096;
  1089.             if (i > 0)
  1090.                 Scon.textblock = i;
  1091.             constate = 0;                    /* don't forget me! */
  1092.             break;
  1093.  
  1094.         case CONDOMTO:                        /* DOMAIN timeout value */
  1095.             i = atoi(s);
  1096.             if (i > 1)
  1097.                 Scon.domto = i;
  1098.             constate = 0;
  1099.             break;
  1100.  
  1101.         case CONNDOM:                        /* DOMAIN number of retries */
  1102.             i = atoi(s);
  1103.             if (i > 1)
  1104.                 Scon.ndom = i;
  1105.             constate = 0;
  1106.             break;
  1107.  
  1108.         case CONHPF:                /* File name for HP dump */
  1109.             Snewhpfile(s);
  1110.             constate = 0;
  1111.             break;
  1112.  
  1113.         case CONPSF:                /* File name for PS dump */
  1114.             Snewpsfile(s);
  1115.             constate = 0;
  1116.             break;
  1117.  
  1118.         case CONTEKF:                /* File name for Tek dump */
  1119.             Snewtekfile(s);
  1120.             constate = 0;
  1121.             break;
  1122.  
  1123.         case CONLINEMODE:                /* BYU 2.4.9 */
  1124.             if (toupper(*s) == 'N')     /* BYU 2.4.9 */
  1125.                 Smptr->linemode = 0;    /* BYU 2.4.9 */
  1126.             else                        /* BYU 2.4.9 */
  1127.                 Smptr->linemode = 1;    /* BYU 2.4.9 */
  1128.             Sflags[33] = 1;                /* BYU 2.4.9 */
  1129.             constate = 0;                /* BYU 2.4.9 */
  1130.             break;                        /* BYU 2.4.9 */
  1131.  
  1132.         case CONEIGHTBIT:                /* BYU 2.4.9 */
  1133.             if (toupper(*s) == 'N')     /* BYU 2.4.9 */
  1134.                 Smptr->eightbit = 0;    /* BYU 2.4.9 */
  1135.             else                        /* BYU 2.4.9 */
  1136.                 Smptr->eightbit = 1;    /* BYU 2.4.9 */
  1137.             Sflags[34] = 1;                /* BYU 2.4.9 */
  1138.             constate = 0;                /* BYU 2.4.9 */
  1139.             break;                        /* BYU 2.4.9 */
  1140.  
  1141.         case CONFORCESAVE:                /* NCSA 2.5 */
  1142.             if (toupper(*s) == 'N')     /* NCSA 2.5 */
  1143.                 Smptr->forcesave = 0;    /* NCSA 2.5 */
  1144.             else                        /* NCSA 2.5 */
  1145.                 Smptr->forcesave = 1;    /* NCSA 2.5 */
  1146.             Sflags[35] = 1;                /* NCSA 2.5 final */
  1147.             constate = 0;                /* NCSA 2.5 */
  1148.             break;                        /* NCSA 2.5 */
  1149.  
  1150.         default:
  1151.             constate = 0;
  1152.             break;
  1153.     }
  1154.  
  1155.     return(0);
  1156. } /* Sconfile */
  1157.  
  1158. /************************************************************************/
  1159. /* Scontoken
  1160. *  tokenize the strings which get passed to Sconfile.
  1161. *  Handles quotes and uses separators:  <33, ;:=
  1162. */
  1163. int Scontoken
  1164.   (
  1165.     int c
  1166.   )
  1167.     {
  1168.     int retval;
  1169.  
  1170.     if (c == EOF) {
  1171.         Sspace[position++] = '\0';
  1172.         Sconfile(Sspace);
  1173.         if (!Sflags[0]) {            /* make sure last entry gets copied */
  1174.             if (ncstrcmp("default",Smptr->sname))
  1175.                 Scopyfrom("default");
  1176.             else
  1177.                 Scopyfrom("==");
  1178.         }
  1179.         return(-1);
  1180.     }
  1181.  
  1182.     if (!position && Sissep(c))        /* skip over junk before token */
  1183.         return(0);
  1184.  
  1185.     if (inquote || !Sissep(c)) {
  1186.  
  1187.         if (position > 200) {
  1188.             Serrline(903);
  1189.             return(1);
  1190.         }
  1191. /*
  1192. *  check for quotes, a little mixed up here, could be reorganized
  1193. */
  1194.         if (c == '"' ) {
  1195.             if (!inquote) {            /* beginning of quotes */
  1196.                 inquote = 1;
  1197.                 return(0);
  1198.             }
  1199.             else
  1200.                 inquote = 0;        /* turn off flag and drop through */
  1201.  
  1202.         }
  1203.         else {                        
  1204.             if (c == '\012' || c == '\015') {        /* check for EOL inside quotes */    /* BYU 2.4.18 */
  1205.                 Serrline(904);
  1206.                 return(1);
  1207.             }
  1208.             Sspace[position++] = c;    /* include in current string */
  1209.             return(0);
  1210.         }
  1211.                 
  1212.     }
  1213.  
  1214.     Sspace[position++] = '\0';
  1215.  
  1216.     retval = Sconfile(Sspace);            /* pass the token along */
  1217.  
  1218.     position = 0;
  1219.     inquote = 0;
  1220.     Sspace[0] = '\0';
  1221.  
  1222.     return(retval);
  1223. }
  1224.  
  1225. /************************************************************************/
  1226. /*  Sreadhosts
  1227. *   read in the hosts file into our in-memory data structure.
  1228. *   Handle everything by keyword, see docs for specifications about file.
  1229. */
  1230. int Sreadhosts
  1231.   (
  1232.     void
  1233.   )
  1234.     {
  1235.     FILE *fp;
  1236.     int c,retval;
  1237.  
  1238.     Smachlist = Smptr = NULL;
  1239.     mno = 0;
  1240.  
  1241.     Sspace = NewPtr(256);                /* get room for gathering stuff */
  1242.     if (Sspace == NULL) {
  1243.         Serrline(901);
  1244.         return(1);
  1245.     }
  1246.     position = constate = inquote = lineno = 0;   /* state vars */    
  1247.  
  1248.     if (NULL == (fp = fopen(Smachfile,"r")))    /* BYU - 9 lines from Scott@NCSA. */
  1249.         {
  1250.         sysdir();
  1251.         if (NULL == (fp = fopen(Smachfile,"r"))) 
  1252.             {        
  1253.             Serrline(900);
  1254.             return (1);
  1255.             }
  1256.         setmydir();        /* BYU - get back to default dir */
  1257.         }
  1258.  
  1259.     retval = 0;
  1260.     while (!retval) {
  1261.         c = fgetc(fp);
  1262.         if (c == '#' && !inquote) {
  1263.             while (c != EOF && c != '\n' && c != '\r')        /* skip to EOL */
  1264.                 c = fgetc(fp);
  1265.         }
  1266.         if (c == '\n' || c == '\r')
  1267.             lineno++;
  1268.         retval = Scontoken(c);
  1269.     }
  1270.  
  1271.     fclose(fp);
  1272.     DisposPtr(Sspace);
  1273.  
  1274.     Smadd("default");                /* make sure name is in list */
  1275.  
  1276.     if (retval == EOF)                /* EOF is normal end */
  1277.         return(0);
  1278.     else
  1279.         return(retval);
  1280.  
  1281. }
  1282.  
  1283. /************************************************************************/
  1284. /*  Smadd
  1285. *   Add a machine to the list. Increments machine number of machine.
  1286. *   Puts in parameters copied from the "default" entry.
  1287. *
  1288. */
  1289. struct machinfo 
  1290. *Smadd(mname)
  1291.     char *mname;
  1292.     {
  1293.     int i;
  1294.     struct machinfo *m;
  1295. /*
  1296. *  First, do we have the name already?
  1297. */
  1298.     m = Shostlook(mname);
  1299.     if (m)
  1300.         return(m);
  1301. /*
  1302. *   Don't have name, add another record
  1303. */
  1304.     Smptr = (struct machinfo *)NewPtr(sizeof(struct machinfo));
  1305.     if (Smptr == NULL)
  1306.         return(NULL);
  1307.  
  1308.     for (i=0; i < NUMSPECS-99; i++)
  1309.         Sflags[i] = 0;                    /* we have no parms */
  1310.     Scopyfrom("default");
  1311.  
  1312.     Smptr->sname = NULL;
  1313.     (Ptr) Smptr->hname = NewPtr(strlen(mname)+1);
  1314.     if (Smptr->hname)
  1315.         strcpy(Smptr->hname,mname);        /* copy in name of machine */
  1316.     Smptr->mno = ++mno;
  1317.     Smptr->mstat = NOIP;
  1318.  
  1319.     Smptr->next = Smachlist;            /* add to front of machlist */
  1320.     Smachlist = Smptr;
  1321.  
  1322.     return(Smptr);
  1323.  
  1324. }
  1325.  
  1326.  
  1327. /************************************************************************/
  1328. /* Shostfile
  1329. *   if the user wants to change the host file name from 'config.tel' to
  1330. *   something else.
  1331. */
  1332. void Shostfile
  1333.   (
  1334.     char *ptr
  1335.   )
  1336.   {
  1337.     Smachfile = ptr;    
  1338. /*
  1339. *  note that the area with the file name must stay allocated for
  1340. *  later reference, typically it is in some argv[] parm.
  1341. */
  1342.   }
  1343.  
  1344. /************************************************************************/
  1345. /*  get host by name
  1346. *   Given the name of a host machine, search our database to see if we
  1347. *   have that host ip number.  Search first the name field, and then the
  1348. *   hostname field.
  1349. *   Returns the pointer to the correct record, or pointer to the default
  1350. *   record if the number is not available
  1351. */
  1352. struct machinfo *Sgethost(machine)
  1353.     char *machine;
  1354.     {
  1355.     int i,j,k,l;
  1356.     unsigned char ipto[4],myipnum[4],xmask[4];
  1357.     unsigned long hnum;
  1358.     struct machinfo *m;
  1359.  
  1360.     m = NULL;
  1361. /*
  1362. *  First, check for the pound sign character which means we should use
  1363. *  the current netmask to build an IP number for the local network.
  1364. *  Take the host number, install it in the ipto[] array.  Then mask
  1365. *  in my IP number's network portion to build the final IP address.
  1366. */
  1367.  
  1368.     if ('#' == machine[0]) {        /* on my local network */
  1369.         netgetip(myipnum);
  1370.         netgetmask(xmask);            /* mask of network portion of IP # */
  1371.  
  1372.         sscanf(&machine[1],"%ld",&hnum);/* host number for local network */
  1373.         for (i=3; i >= 0; i--) {
  1374.             ipto[i] = hnum & 255L;    /* take off a byte */
  1375.             hnum >>= 8;                /* shift it over */
  1376.         }
  1377.  
  1378.         for (i=0; i < 4; i++) 
  1379.             ipto[i] |= (myipnum[i] & xmask[i]);        /* mask new one in */
  1380.  
  1381.     }
  1382. /*
  1383. *  next, is it an IP number?  We take it if the number is in four
  1384. *  parts, separated by periods.
  1385. */
  1386.     else 
  1387.     if (4 == sscanf(machine,"%d.%d.%d.%d",&i,&j,&k,&l)) {    /* given ip num */
  1388.         ipto[0] = i;
  1389.         ipto[1] = j;
  1390.         ipto[2] = k;
  1391.         ipto[3] = l;
  1392.     }
  1393. /*
  1394. *  lastly, it must be a name, first check the local host table
  1395. *  A first number of 127 means that it doesn't have an IP number, but
  1396. *  is in the table (strange occurrence)
  1397. */
  1398.     else {                                    /* look it up */
  1399.  
  1400.         m = Shostlook(machine);
  1401.         if (m == NULL) {
  1402.             netposterr(805);                /* informative */
  1403.             return(NULL);
  1404.         } 
  1405.         if (m->mstat < HAVEIP) {
  1406.             netposterr(806);                /* informative */
  1407.             return(NULL);
  1408.         }
  1409.     }
  1410.  
  1411.     if (!m) {
  1412.         m = Shostlook("default");
  1413.         movebytes(m->hostip,ipto,4);        /* copy in newest host # */
  1414.         m->mstat = HAVEIP;                    /* we have the IP # */
  1415.     }
  1416.  
  1417.     return(m);
  1418. }
  1419.  
  1420. /************************************************************************/
  1421. /*  Slooknum
  1422. *   get the host record by machine number, used primarily in DOMAIN name
  1423. *   lookup.
  1424. */
  1425. struct machinfo 
  1426. *Slooknum(num)
  1427.     int num;
  1428.     {
  1429.     struct machinfo *m;
  1430.  
  1431.     m = Smachlist;
  1432.     while (m) {
  1433.         if (m->mno == num)
  1434.             return(m);
  1435.         m = m->next;
  1436.     }
  1437.  
  1438.     return(NULL);
  1439.  
  1440. }
  1441.  
  1442. /**************************************************************************/
  1443. /*  Slookip
  1444. *   For FTP to look up the transfer options to use when running
  1445. *
  1446. */
  1447. struct machinfo 
  1448. *Slookip(ipnum)
  1449.     unsigned char *ipnum;
  1450.     {
  1451.     struct machinfo *m;
  1452.  
  1453.     m = Smachlist;
  1454.     while (m) {
  1455.         if (comparen(m->hostip,ipnum,4))
  1456.             return(m);
  1457.         m = m->next;
  1458.     }
  1459.  
  1460.     return(NULL);
  1461.  
  1462. }
  1463.  
  1464. /*********************************************************************/
  1465. /*  Snewns()
  1466. *   Rotate to the next nameserver
  1467. *   Chooses the next highest number from the nameserv field
  1468. */
  1469. int Snewns
  1470.   (
  1471.     void
  1472.   )
  1473.     {
  1474.     struct machinfo *m,*low;
  1475.     int i;
  1476.  
  1477.     if (!Sns)                    /* safety, should never happen */
  1478.         Sns = Smachlist;
  1479.  
  1480.     low = Sns;
  1481.     i = Sns->nameserv;            /* what is value now? */
  1482.  
  1483.     m = Smachlist;
  1484.     while (m) {
  1485.         if (m->nameserv == i+1) {
  1486.             Sns = m;
  1487.             return(0);
  1488.         }
  1489.         if ((m->nameserv > 0) && (m->nameserv < low->nameserv))
  1490.             low = m;
  1491.         m = m->next;
  1492.     }
  1493.  
  1494.     if (Sns == low)
  1495.         return(1);                /* no alternate */
  1496.     else
  1497.         Sns = low;
  1498.  
  1499.     return(0);
  1500. }
  1501.  
  1502. int Ssetns
  1503.   (
  1504.     unsigned char ipn[4]
  1505.   )
  1506.   /* saves the IP address of a name server for future use,
  1507.     returning 1 if I already have it, 0 if not. */
  1508.     {
  1509.     struct machinfo *m;
  1510.     int i;
  1511.  
  1512.     i = 0;
  1513.     if (NULL == (m = Slookip(ipn))) {        /* have already? */
  1514.         m = Smadd("=nameserv=");
  1515.         movebytes(m->hostip,ipn,4);
  1516.         m->mstat = FROMKIP;
  1517.         i = 1;
  1518.     }
  1519.  
  1520.     m->nameserv = 1;
  1521.     Sns = m;
  1522.  
  1523.     return(i);
  1524. }
  1525.  
  1526. /************************************************************************/
  1527. /*  setgates
  1528. *   set up the gateway machines and the subnet mask after netinit()
  1529. *   and start up ftp and rcp for them.
  1530. */
  1531. void Ssetgates
  1532.   (
  1533.     void
  1534.   )
  1535.     {
  1536.     struct machinfo *m;
  1537.     int level,again;
  1538.  
  1539.     if (Scon.havemask)                    /* leave default unless specified */
  1540.         netsetmask(Scon.netmask);
  1541. /*
  1542. *  Search the list of machines for gateway flags.
  1543. *  Invoke netsetgate in increasing order of gateway level #s.
  1544. *  Terminates when it gets through list without finding next higher number.
  1545. */
  1546.     level = 0;
  1547.     do {
  1548.         level++;
  1549.         again = 0;
  1550.         m = Smachlist;
  1551.         while (m != NULL) {
  1552.             if (m->gateway == level && m->mstat >= HAVEIP) 
  1553.                 netsetgate(m->hostip);
  1554.             if (m->gateway == level+1)
  1555.                 again=1;
  1556.             m = m->next;
  1557.         }
  1558.     } while (again);
  1559.  
  1560.     Sftpmode(Scon.ftp);
  1561. #ifdef PC
  1562.     Srcpmode(Scon.rcp);
  1563. #endif
  1564.     /* return(0); */
  1565. }
  1566.