* Copyright (c) 1990 The Regents of the University of California.
* %sccs.include.redist.c%
"@(#) Copyright (c) 1990 The Regents of the University of California.\n\
static char sccsid
[] = "@(#)startslip.c 5.1 (Berkeley) %G%";
#include <net/if_slvar.h>
#define DEFAULT_BAUD B9600
int speed
= DEFAULT_BAUD
;
#define printd if (debug) printf
char *dialerstring
= 0, buf
[BUFSIZ
];
while ((ch
= getopt(argc
, argv
, "ds:")) != EOF
)
openlog("startslip", LOG_PID
, LOG_DAEMON
);
if (debug
== 0 && (fd
= open("/dev/tty", 0))) {
if ((fd
= open(argv
[0], O_RDWR
)) < 0) {
syslog(LOG_ERR
, "startslip: open %s: %m\n", argv
[0]);
(void) write(fd
, dialerstring
, strlen(dialerstring
));
(void) write(fd
, "\n", 1);
if (ioctl(fd
, TIOCGETP
, &sgtty
) < 0) {
perror("ioctl (TIOCGETP)");
sgtty
.sg_flags
= RAW
| ANYP
;
sgtty
.sg_erase
= sgtty
.sg_kill
= 0377;
sgtty
.sg_ispeed
= sgtty
.sg_ospeed
= speed
;
if (ioctl(fd
, TIOCSETP
, &sgtty
) < 0) {
perror("ioctl (TIOCSETP)");
syslog(LOG_ERR
, "startslip: %s: ioctl (TIOCSETP): %m\n",
syslog(LOG_ERR
, "startslip: can't fdopen slip line\n");
while (fflush(wfd
), getline(buf
, BUFSIZ
, fd
) != NULL
) {
if (bcmp(&buf
[1], "ogin:", 5) == 0) {
fprintf(wfd
, "%s\r", argv
[1]);
if (bcmp(&buf
[1], "assword:", 8) == 0) {
fprintf(wfd
, "%s\r", argv
[2]);
if (ioctl(fd
, TIOCSETD
, &slipdisc
) < 0) {
perror("ioctl(TIOCSETD)");
syslog(LOG_ERR
, "startslip: %s: ioctl (TIOCSETD): %m\n",
if (ioctl(fd
, SLIOCSFLAGS
, (caddr_t
)&slipdisc
) < 0) {
perror("ioctl(SLIOCFLAGS)");
syslog(LOG_ERR
, "ioctl (SLIOCSFLAGS): %m");
if (ioctl(fd
, TIOCSCTTY
, 0) < 0)
perror("ioctl (TIOCSCTTY)");
(void) system("ifconfig sl0 up");
syslog(LOG_INFO
, "startslip: hangup signal\n");
for (i
= 0; i
< size
; i
++) {
if (read(fd
, &buf
[i
], 1) == 1) {
if (buf
[i
] != '\n' && buf
[i
] != ':')
fprintf(stderr
, "Got %d: \"%s\"\n", i
, buf
);
fprintf(stderr
, "usage: startslip [-d] [-s string] dev user passwd\n");