static char sccsid
[] = "@(#)setup.c 4.2 (Berkeley) %G%";
support procedures used in setting up the network
char logfile
[] = LOGFILE
;
called in netdaemon and debugging software
handles parameter lists to setup
cfile
= fopen(INITFILE
,"r");
err("remote %c local %c link %s inspeed %d outspeed %d length %d\n",
remote
,local
,netd
.dp_device
,netd
.dp_inspeed
,
netd
.dp_outspeed
,netd
.dp_datasize
);
err("debug %d time %d count %d onlyuid %d usehispeed=%d hispeedlink='%s'\n",
debugflg
,netd
.dp_oatime
, netd
.dp_maxbread
,netd
.dp_onlyuid
,
netd
.dp_usehispeed
, netd
.dp_hispeedlink
);
err("sendonly %c rcvonly %c pipesim %c\n",
chfromf(netd
.dp_sndorcv
< 0),chfromf(netd
.dp_sndorcv
> 0),
chfromf(netd
.dp_pipesim
));
see comment in netdaemon.c about the arguments
while(argc
> 1 && argv
[1][0] == '-'){
if(argv
[0][2] == 's') /* only send */
else if(argv
[0][2] == 'r') /* only receive */
else if(argv
[0][2] == 'u') /* only uid num */
netd
.dp_onlyuid
= atoi(argv
[1]);
netd
.dp_datasize
= atol(stemp
);
netd
.dp_rdfile
= fdopen(atoi(stemp
),"r");
netd
.dp_pwritefd
= atoi(stemp
);
/* ignore unknown options */
fprintf(stderr
,"Error- must specify machine - use -m option\n");
set the correct mode on the link device
#define OUT8BIT 01 /* All 8 bits on output */
#define IN8BIT 02 /* All 8 bits on input */
/* nothing to set up if we're simulating with pipes */
if(netd
.dp_pipesim
)return;
str
= netd
.dp_hispeedlink
;
netd
.dp_datasize
= SENDLEN
- ACKLENGTH
;
if(str
== 0 || str
[0] == 0){
err("invalid net device\n");
netd
.dp_linefd
= open(str
,2);
/* set exclusive use for line */
ioctl(netd
.dp_linefd
,TIOCEXCL
,&stt
);
if(gtty(netd
.dp_linefd
,&stt
) < 0){
stt
.sg_ispeed
= netd
.dp_inspeed
; /* user set baud */
stt
.sg_ospeed
= netd
.dp_outspeed
; /* user-set baud */
stt
.sg_erase
= stt
.sg_kill
= 0; /* erase and kill off */
stt
.sg_flags
= ANYP
; /* even and odd parity, off everything else */
if(stty(netd
.dp_linefd
,&stt
) < 0){
/* set device into 8-bit mode */
if(gtty((2<<8)|netd
.dp_linefd
,&exstt
) < 0){
exstt
.t_xflags
= OUT8BIT
| IN8BIT
;
if(stty((2<<8)|netd
.dp_linefd
, &exstt
) < 0){
/* set my own line discipline */
/* NETLDISC is defined in sgtty.h on the CSVAX */
/* setting the line discipline must be done AFTER the sttys */
netd
.dp_linedis
= NETLDISC
;
if(ioctl(netd
.dp_linefd
,TIOCSETD
,&netd
.dp_linedis
) != 0){
printf("error - line discipline\n");
printf("proceeding...\n");
/* set the line into RAW mode */
ioctl(netd
.dp_linefd
,TIOCSETD
,&netd
.dp_linedis
);
netd
.dp_linedis
= NETLDISC
;
stt
.sg_ispeed
= netd
.dp_inspeed
;/* user set baud */
stt
.sg_ospeed
= netd
.dp_outspeed
; /* user-set baud */
stt
.sg_erase
= stt
.sg_kill
= 0;
stt
.sg_flags
= ANYP
|RAW
; /* in raw mode */
if(stty(netd
.dp_linefd
,&stt
) < 0){
ioctl(netd
.dp_linefd
,TIOCSETD
,&netd
.dp_linedis
);
printf("Using network line discipline.\n");
if(remote
!= 0) sprintf(buf
,"%s",longname(remote
));
fprintf(stderr
,s
,a
,b
,c
,d
,e
,f
,g
,h
);
addtolog(remote
,"Err %s: ",buf
);
addtolog(remote
,s
,a
,b
,c
,d
,e
,f
,g
,h
);
/* this is really not right - we should use the rcslog format */
/* also, the user must be able to write on the
public logfile to get error messages such as
directory not found after he has
addtolog(mach
,s
,a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
)
logfile
[strlen(logfile
)-1] = mach
;
if(stat(logfile
,&statbuf
) < 0)return;
log
= fopen(logfile
,"a");
fprintf(log
,s
,a
,b
,c
,d
,e
,f
,g
,h
,i
,j
,k
,l
,m
,n
);
debug(s
,a
,b
,c
,d
,e
,f
,g
,h
,i
,h
,k
,l
,m
,n
);