1: static char sccsid[] = "@(#)setup.c	4.2	(Berkeley)	10/3/82";
   2: 
   3: /*
   4: 	setup.c
   5: 
   6: 	support procedures used in setting up the network
   7: 
   8: */
   9: 
  10: # include "defs.h"
  11: 
  12: char logfile[] =    LOGFILE;
  13: 
  14: /* global variables */
  15: struct daemonparms netd;
  16: 
  17: /*
  18: 	called in netdaemon and debugging software
  19: 	handles parameter lists to setup
  20: 	remote machine and pipes
  21: */
  22: setupdaemon(argc,argv)
  23: char **argv;{
  24:     long timev;
  25:     int timei;
  26:     FILE *cfile;
  27: 
  28:     parseargs(argc,argv);
  29: 
  30:     cfile = fopen(INITFILE,"r");
  31:     rdnetfile(cfile);
  32:     fclose(cfile);
  33:     err("remote %c local %c link %s inspeed %d outspeed %d length %d\n",
  34:         remote,local,netd.dp_device,netd.dp_inspeed,
  35:         netd.dp_outspeed,netd.dp_datasize);
  36:     err("debug %d time %d count %d onlyuid %d usehispeed=%d hispeedlink='%s'\n",
  37:         debugflg,netd.dp_oatime, netd.dp_maxbread,netd.dp_onlyuid,
  38:         netd.dp_usehispeed, netd.dp_hispeedlink);
  39:     err("sendonly %c rcvonly %c pipesim %c\n",
  40:         chfromf(netd.dp_sndorcv < 0),chfromf(netd.dp_sndorcv > 0),
  41:         chfromf(netd.dp_pipesim));
  42:     setup(netd.dp_device);
  43:     timev = gettime();
  44:     timei = timev >> 16;
  45:     srand(timei);
  46: }
  47: /*
  48: 
  49: see comment in netdaemon.c about the arguments
  50: 
  51: */
  52: parseargs(argc,argv)
  53:   char **argv; {
  54:     char stemp[30];
  55:     remote = 0;
  56:     while(argc > 1 && argv[1][0] == '-'){
  57:         argc--; argv++;
  58:         switch(argv[0][1]){
  59:         case '8':
  60:             netd.dp_use8bit = 1;
  61:             break;
  62:         case 'd':
  63:             debugflg = 1;
  64:             break;
  65:         case 'h':
  66:             netd.dp_usehispeed = 1;
  67:             break;
  68:         case 'l':
  69:             netd.dp_trynetl = 0;
  70:             break;
  71:         case 'm':
  72:             harg(stemp);
  73:             remote = lookup(stemp);
  74:             break;
  75:         case 'o':       /* only */
  76:             if(argv[0][2] == 's')       /* only send */
  77:                 netd.dp_sndorcv = -1;
  78:             else if(argv[0][2] == 'r')  /* only receive */
  79:                 netd.dp_sndorcv = 1;
  80:             else if(argv[0][2] == 'u')  /* only uid num */
  81:                 netd.dp_onlyuid = atoi(argv[1]);
  82:             break;
  83:         case 'p':
  84:             harg(stemp);
  85:             netd.dp_datasize = atol(stemp);
  86:             break;
  87:         case 'r':
  88:             harg(stemp);
  89:             netd.dp_rdfile = fdopen(atoi(stemp),"r");
  90:             netd.dp_pipesim++;
  91:             break;
  92:         case 'w':
  93:             harg(stemp);
  94:             netd.dp_pwritefd = atoi(stemp);
  95:             netd.dp_pipesim++;
  96:             break;
  97:         /* ignore unknown options */
  98:         }
  99:     }
 100:     if(remote == 0){
 101:         fprintf(stderr,"Error- must specify machine - use -m option\n");
 102:         exit(EX_USAGE);
 103:     }
 104: }
 105: /*
 106: 	set the correct mode on the link device
 107: */
 108: setup(str)
 109:   char *str; {
 110:     struct sgttyb stt;
 111: # ifdef RAND
 112:     struct {
 113:         int     t_xflags;
 114:         char    t_col;
 115:         char    t_delct;
 116:         char    t_outqc_cc;
 117:         char    t_rawqc_cc;
 118:     } exstt;
 119: #define OUT8BIT 01              /* All 8 bits on output */
 120: #define IN8BIT  02              /* All 8 bits on input  */
 121: # endif
 122: 
 123:     initseqno();
 124:     /* nothing to set up if we're simulating with pipes */
 125:     if(netd.dp_pipesim)return;
 126: 
 127:     if(netd.dp_usehispeed){
 128:         str = netd.dp_hispeedlink;
 129:         netd.dp_datasize = SENDLEN - ACKLENGTH;
 130:         }
 131:     if(str == 0 || str[0] == 0){
 132:         err("invalid net device\n");
 133:         exit(EX_OSFILE);
 134:         }
 135:     netd.dp_linefd = open(str,2);
 136:     if(netd.dp_linefd < 0){
 137:         perror(str);
 138:         exit(EX_OSERR);
 139:         }
 140:     /* set exclusive use for line */
 141: #ifdef TIOCEXCL
 142: #ifdef VAX
 143:     (void)
 144: #endif
 145:     ioctl(netd.dp_linefd,TIOCEXCL,&stt);
 146: #endif
 147:     if(gtty(netd.dp_linefd,&stt) < 0){
 148:         perror(str);
 149:         exit(EX_OSERR);
 150:         }
 151:     stt.sg_ispeed = netd.dp_inspeed;    /* user set baud */
 152:     stt.sg_ospeed = netd.dp_outspeed;   /* user-set baud */
 153:     stt.sg_erase = stt.sg_kill = 0;     /* erase and kill off */
 154:     stt.sg_flags = ANYP;    /* even and odd parity, off everything else */
 155:     if(stty(netd.dp_linefd,&stt) < 0){
 156:         perror(str);
 157:         exit(EX_OSERR);
 158:         }
 159: # ifdef RAND
 160:     /* set device into 8-bit mode */
 161:     if(gtty((2<<8)|netd.dp_linefd,&exstt) < 0){
 162:         perror(str);
 163:         exit(EX_OSERR);
 164:         }
 165:     exstt.t_xflags = OUT8BIT | IN8BIT;
 166:     if(stty((2<<8)|netd.dp_linefd, &exstt) < 0){
 167:         perror(str);
 168:         exit(EX_OSERR);
 169:         }
 170: # endif
 171:     /* set my own line discipline */
 172:     /* NETLDISC is defined in sgtty.h on the CSVAX */
 173:     /* setting the line discipline must be done AFTER the sttys */
 174: # ifdef NETLDISC
 175:     if(netd.dp_trynetl){
 176:         netd.dp_linedis = NETLDISC;
 177:         if(ioctl(netd.dp_linefd,TIOCSETD,&netd.dp_linedis) != 0){
 178:             printf("error - line discipline\n");
 179:             perror(str);
 180:             printf("proceeding...\n");
 181:             netd.dp_linedis = 0;
 182:             }
 183:         if(netd.dp_linedis){
 184:             /* set the line into RAW mode */
 185:             netd.dp_linedis = 0;
 186:             ioctl(netd.dp_linefd,TIOCSETD,&netd.dp_linedis);
 187:             netd.dp_linedis = NETLDISC;
 188:             stt.sg_ispeed = netd.dp_inspeed;/* user set baud */
 189:             stt.sg_ospeed = netd.dp_outspeed;  /* user-set baud */
 190:             stt.sg_erase = stt.sg_kill = 0;
 191:             stt.sg_flags = ANYP|RAW;    /* in raw mode */
 192:             if(stty(netd.dp_linefd,&stt) < 0){
 193:                 perror(str);
 194:                 exit(EX_OSERR);
 195:             }
 196:             ioctl(netd.dp_linefd,TIOCSETD,&netd.dp_linedis);
 197:             printf("Using network line discipline.\n");
 198:         }
 199:     }
 200: # endif
 201: }
 202: /*VARARGS0*/
 203: error(s,a,b,c,d,e,f,g,h)
 204: char *s; {
 205:     char buf[10];
 206:     if(remote != 0) sprintf(buf,"%s",longname(remote));
 207:     else buf[0] = 0;
 208:     fflush(stdout);
 209:     if(debugflg){
 210:         fprintf(stderr,s,a,b,c,d,e,f,g,h);
 211:         putc('\n',stderr);
 212:         }
 213:     addtolog(remote,"Err %s: ",buf);
 214:     addtolog(remote,s,a,b,c,d,e,f,g,h);
 215:     addtolog(remote,"\n");
 216:     }
 217: /* this is really not right - we should use the rcslog format */
 218: /* also, the user must be able to write on the
 219:    public logfile to get error messages such as
 220:    directory not found after he has
 221:    setuid'd from root
 222: */
 223: /*VARARGS0*/
 224: addtolog(mach,s,a,b,c,d,e,f,g,h,i,j,k,l,m,n)
 225: char *s;
 226: {
 227:     static FILE *log = NULL;
 228:     struct stat statbuf;
 229:     logfile[strlen(logfile)-1] = mach;
 230:     if(log == NULL){
 231:         if(stat(logfile,&statbuf) < 0)return;
 232:         log = fopen(logfile,"a");
 233:         }
 234:     if(log == NULL)return;
 235:     fseek(log,0L,2);
 236:     fprintf(log,s,a,b,c,d,e,f,g,h,i,j,k,l,m,n);
 237:     fflush(log);
 238:     debug(s,a,b,c,d,e,f,g,h,i,h,k,l,m,n);
 239:     }

Defined functions

addtolog defined in line 224; used 20 times
error defined in line 203; used 38 times
parseargs defined in line 52; used 2 times
setup defined in line 108; used 1 times
  • in line 42

Defined variables

logfile defined in line 12; used 4 times
netd defined in line 15; used 52 times
sccsid defined in line 1; never used

Defined macros

IN8BIT defined in line 120; used 1 times
OUT8BIT defined in line 119; used 1 times
Last modified: 1982-10-03
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1570
Valid CSS Valid XHTML 1.0 Strict