From c5f5d0f6cb0df00093e46ac9f0379fdbecaa25c3 Mon Sep 17 00:00:00 2001 From: dg Date: Wed, 14 Sep 1994 05:40:56 +0000 Subject: Fixed slattach to do flags ioctl via network device rather than tty. Submitted by: Rich Murphey, and fixed up by me. --- sbin/slattach/slattach.c | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) (limited to 'sbin/slattach') diff --git a/sbin/slattach/slattach.c b/sbin/slattach/slattach.c index 8987123..ac4a530 100644 --- a/sbin/slattach/slattach.c +++ b/sbin/slattach/slattach.c @@ -284,18 +284,50 @@ void setup_line(int cflag) /* Put the line in slip discipline. */ void slip_discipline() { + struct ifreq ifr; int slipdisc = SLIPDISC; + int s, tmp_unit = -1; /* Switch to slip line discipline. */ if (ioctl(fd, TIOCSETD, &slipdisc) < 0) { syslog(LOG_ERR, "ioctl(TIOCSETD): %m"); exit_handler(1); } + + /* find out what unit number we were assigned */ + if (ioctl(fd, SLIOCGUNIT, (caddr_t)&tmp_unit) < 0) { + syslog(LOG_ERR, "ioctl(SLIOCGUNIT): %m"); + exit_handler(1); + } + + if (tmp_unit < 0) { + syslog(LOG_ERR, "bad unit (%d) from ioctl(SLIOCGUNIT)",tmp_unit); + exit_handler(1); + } + + /* open a socket as the handle to the interface */ + s = socket(AF_INET, SOCK_DGRAM, 0); + if (s < 0) { + syslog(LOG_ERR, "socket: %m"); + exit_handler(1); + } + sprintf(ifr.ifr_name, "sl%d", tmp_unit); + + /* get the flags for the interface */ + if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) < 0) { + syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m"); + exit_handler(1); + } + /* Assert any compression or no-icmp flags. */ - if (ioctl(fd, SIOCSIFFLAGS, &slflags) < 0) { - syslog(LOG_ERR, "ioctl(SIOCSIFFLAGS): %m"); +#define SLMASK (~(IFF_LINK0 | IFF_LINK1 | IFF_LINK2)) + ifr.ifr_flags &= SLMASK; + ifr.ifr_flags |= slflags; + if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr) < 0) { + syslog(LOG_ERR, "ioctl (SIOCSIFFLAGS): %m"); exit_handler(1); } + close(s); } /* configure the interface, eg. by passing the unit number to a script. */ -- cgit v1.1