5b80ffc88532cdb6f5cf3bd77c82a16132bba33a
* tip - Unix link to other systems
* tip [-v] [-speed] system-name
* Uses remote file for system descriptions.
* Current commands (escapes):
* ~! fork a shell on the local machine
* ~c change working directory on local machine
* ~< fetch file from remote system
* ~> send file to remote system
* ~t take a file from a remote UNIX (uses cat & echo)
* ~p send a file to a remote UNIX (uses cat)
* ~| fetch file from remote system and pipe it to
* ~% fork and wait for a program which inherits file
* descriptors 3 & 4 attached to the remote machine
* (optional by CONNECT define)
* ~s set or show variable
* Samuel J. Leffler 1-18-81
* add auto-dial stuff for the BIZCOMP
* cleaned up auto-dialer stuff and added variables
* handle quit and interrupt during calls
* mods to handle both FIOCAPACITY and FIONREAD in biz.c
* added take and put, made piping stuff work
* rewrite remote file stuff for DN-11 like acu's and just to clean
* real working setup for DN-11's
* Baud rate mapping table
0, 50, 75, 110, 134, 150, 200, 300, 600,
1200, 1800, 2400, 4800, 9600, 19200, -1
int disc
= OTTYDISC
; /* tip normally runs this way */
fprintf(stderr
, "usage: tip [-v] [-speed] [system-name]\n");
fprintf(stderr
, "tip: must be interactive\n");
if (argc
> 1 && argv
[argc
-1][0] != '-')
system
= argv
[argc
-1]; /* always last item */
signal(SIGQUIT
, cleanup
);
signal(SIGTERM
, cleanup
);
if ((i
= hunt(system
)) == 0) {
printf("all ports busy\n");
* Now that we have the logfile and the ACU open
* return to the real uid and gid. These things will
* be closed on exit. Note that we can't run as root,
* because locking mechanism on the tty and the accounting
for (i
= 1; i
< argc
-1; i
++)
if (equal(argv
[i
], "-v"))
* Kludge, their's no easy way to get the initialization
* in the right order, so force it here
if ((PH
= getenv("PHONES")) == NOSTR
)
vinit(); /* init variables */
for (i
= 1; i
< argc
-1; i
++)
if (argv
[i
][0] == '-' && argv
[i
][1] != 'v') {
number(value(BAUDRATE
)) = atoi(&argv
[i
][1]);
printf("%s: unknown option\n", argv
[i
]);
if ((i
= speed(number(value(BAUDRATE
)))) == NULL
) {
printf("tip: bad baud rate %d\n", number(value(BAUDRATE
)));
* Hardwired connections require the
* line speed set before they make any transmissions
* (this is particularly true of things like a DF03-AC)
printf("\07%s\n[EOT]\n", p
);
ioctl(0, TIOCGETP
, (char *)&defarg
);
ioctl(0, TIOCGETC
, (char *)&defchars
);
ioctl(0, TIOCGETD
, (char *)&odisc
);
arg
.sg_flags
= ANYP
| CBREAK
;
tchars
.t_intrc
= tchars
.t_quitc
= -1;
pipe(fildes
); pipe(repdes
);
signal(SIGALRM
, timeout
);
* Everything's set up now:
* connection established (hardwired or diaulup)
* line conditioned (baud rate, mode, etc.)
* internal data structures (variables)
* so, fork one process for local side and one for remote.
write(1, "\07connected\r\n", 12);
ioctl(0, TIOCSETD
, (char *)&odisc
);
* put the controlling keyboard into raw mode
ioctl(0, TIOCSETP
, &arg
);
ioctl(0, TIOCSETC
, &tchars
);
ioctl(0, TIOCSETD
, (char *)&disc
);
* return keyboard to normal mode
ioctl(0, TIOCSETD
, (char *)&odisc
);
ioctl(0, TIOCSETP
, (char *)&defarg
);
ioctl(0, TIOCSETC
, (char *)&defchars
);
* Print string ``s'', then read a string
* in from the terminal. Handles signals & allows use of
* normal erase and kill characters.
signal(SIGINT
, intprompt
);
signal(SIGQUIT
, SIG_IGN
);
while ((*p
= getchar()) != EOF
&& *p
!= '\n') {
return(stoprompt
|| p
== b
);
* Interrupt service routine during prompting
* check for scripting being turned on from the .tiprc file,
* but be careful about just using setscript(), as we may
* send a SIGEMT before tipout has a chance to set up catching
* it; so wait a second, then setscript()
if (boolean(value(SCRIPT
))) {
if ((gch
== character(value(ESCAPE
))) && bol
) {
} else if (gch
== character(value(RAISECHAR
))) {
boolean(value(RAISE
)) = !boolean(value(RAISE
));
printf("%s", ctrl(character(value(RAISECHAR
))));
} else if (gch
== '\r') {
} else if (gch
== character(value(FORCE
))) {
printf("%s", ctrl(character(value(FORCE
))));
bol
= any(gch
, value(EOL
));
if (boolean(value(RAISE
)) && islower(gch
))
* called on recognition of ``escapec'' at the beginning of a line
char c
= character(value(ESCAPE
));
extern esctable_t etable
[];
for (p
= etable
; p
->e_char
; p
++)
if ((p
->e_flags
&PRIV
) && getuid())
/* ESCAPE ESCAPE forces ESCAPE */
for (p
= bauds
; *p
!= -1; p
++)
register char *p
= buf
, c
, *q
;
for (q
= "\nn\rr\tt\ff\033E\bb"; *q
; q
++)
*p
++ = '^'; *p
++ = c
+ 'A'-1;
if (c
< 040 || c
== 0177) {
s
[1] = c
== 0177 ? '?' : c
+'A'-1;
extern esctable_t etable
[];
for (p
= etable
; p
->e_char
; p
++) {
if ((p
->e_flags
&PRIV
) && getuid())
printf("%2s", ctrl(character(value(ESCAPE
))));
printf("%-2s %c %s\r\n", ctrl(p
->e_char
),
p
->e_flags
&EXP
? '*': ' ', p
->e_help
);
* Set up the "remote" tty's state
arg
.sg_ispeed
= arg
.sg_ospeed
= speed
;
arg
.sg_flags
= TANDEM
|RAW
;
ioctl(FD
, TIOCSETP
, (char *)&arg
);
ioctl(FD
, TIOCLBIS
, (char *)&bits
);