X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-sunos4.c;h=19c233ff7e3f6d8a21020e1a08b8d0e6e5f91cc4;hp=b0d0eaaf8ef21149abd7b60b920fead6ae1d65b7;hb=31b4bba68d46b38119fd8620ee09ff7f8831f4b5;hpb=cb6271cf11b1237286e53124dd7a6ac2e24f6671 diff --git a/pppd/sys-sunos4.c b/pppd/sys-sunos4.c index b0d0eaa..19c233f 100644 --- a/pppd/sys-sunos4.c +++ b/pppd/sys-sunos4.c @@ -25,9 +25,7 @@ * OR MODIFICATIONS. */ -#ifndef lint -static char rcsid[] = "$Id: sys-sunos4.c,v 1.14 1999/03/16 02:57:07 paulus Exp $"; -#endif +#define RCSID "$Id: sys-sunos4.c,v 1.24 1999/08/13 06:46:19 paulus Exp $" #include #include @@ -67,6 +65,8 @@ extern void *alloca(); #endif #endif /*sparc*/ +static const char rcsid[] = RCSID; + static int pppfd; static int fdmuxid = -1; static int iffd; @@ -201,7 +201,7 @@ sys_check_options() return 1; } - +#if 0 /* * daemon - Detach us from controlling terminal session. */ @@ -225,6 +225,7 @@ daemon(nochdir, noclose) } return 0; } +#endif /* * ppp_available - check whether the system has any ppp interfaces @@ -240,7 +241,7 @@ ppp_available() /* * establish_ppp - Turn the serial port into a ppp interface. */ -void +int establish_ppp(fd) int fd; { @@ -262,6 +263,8 @@ establish_ppp(fd) /* Link the serial port under the PPP multiplexor. */ if ((fdmuxid = ioctl(pppfd, I_LINK, fd)) < 0) fatal("Can't link tty to PPP mux: %m"); + + return pppfd; } /* @@ -558,12 +561,13 @@ int fd, on; /* * open_loopback - open the device we use for getting packets - * in demand mode. Under Solaris 2, we use our existing fd + * in demand mode. Under SunOS, we use our existing fd * to the ppp driver. */ -void +int open_ppp_loopback() { + return pppfd; } /* @@ -614,6 +618,44 @@ wait_input(timo) fatal("poll: %m"); } +/* + * add_fd - add an fd to the set that wait_input waits for. + */ +void add_fd(fd) + int fd; +{ + int n; + + for (n = 0; n < n_pollfds; ++n) + if (pollfds[n].fd == fd) + return; + if (n_pollfds < MAX_POLLFDS) { + pollfds[n_pollfds].fd = fd; + pollfds[n_pollfds].events = POLLIN | POLLPRI | POLLHUP; + ++n_pollfds; + } else + error("Too many inputs!"); +} + +/* + * remove_fd - remove an fd from the set that wait_input waits for. + */ +void remove_fd(fd) + int fd; +{ + int n; + + for (n = 0; n < n_pollfds; ++n) { + if (pollfds[n].fd == fd) { + while (++n < n_pollfds) + pollfds[n-1] = pollfds[n]; + --n_pollfds; + break; + } + } +} + +#if 0 /* * wait_loop_output - wait until there is data available on the * loopback, for the length of time specified by *timo (indefinite @@ -640,7 +682,7 @@ wait_time(timo) if (n < 0 && errno != EINTR) fatal("select: %m"); } - +#endif /* * read_packet - get a PPP packet from the serial device. @@ -661,7 +703,7 @@ read_packet(buf) flags = 0; len = getmsg(pppfd, &ctrl, &data, &flags); if (len < 0) { - if (errno = EAGAIN || errno == EINTR) + if (errno == EAGAIN || errno == EINTR) return -1; fatal("Error reading packet: %m"); } @@ -726,7 +768,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp) /* set mtu for ip as well */ memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); ifr.ifr_metric = link_mtu; if (ioctl(sockfd, SIOCSIFMTU, &ifr) < 0) { error("Couldn't set IP MTU: %m"); @@ -818,6 +860,25 @@ get_idle_time(u, ip) return strioctl(pppfd, PPPIO_GIDLE, ip, 0, sizeof(struct ppp_idle)) >= 0; } +/* + * get_ppp_stats - return statistics for the link. + */ +int +get_ppp_stats(u, stats) + int u; + struct pppd_stats *stats; +{ + struct ppp_stats s; + + if (strioctl(pppfd, PPPIO_GETSTAT, &s, 0, sizeof(s)) < 0) { + error("Couldn't get link statistics: %m"); + return 0; + } + stats->bytes_in = s.p.ppp_ibytes; + stats->bytes_out = s.p.ppp_obytes; + return 1; +} + /* * ccp_fatal_error - returns 1 if decompression was disabled as a @@ -877,7 +938,7 @@ sifup(u) { struct ifreq ifr; - strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) { error("Couldn't mark interface up (get): %m"); return 0; @@ -900,7 +961,7 @@ sifdown(u) { struct ifreq ifr; - strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) { error("Couldn't mark interface down (get): %m"); return 0; @@ -949,7 +1010,7 @@ sifaddr(u, o, h, m) struct ifreq ifr; memset(&ifr, 0, sizeof(ifr)); - strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); ifr.ifr_addr.sa_family = AF_INET; INET_ADDR(ifr.ifr_addr) = m; if (ioctl(sockfd, SIOCSIFNETMASK, &ifr) < 0) { @@ -1138,7 +1199,7 @@ get_ether_addr(ipaddr, hwaddr) * Check that the interface is up, and not point-to-point * or loopback. */ - strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name); + strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0) continue; if ((ifreq.ifr_flags & @@ -1171,7 +1232,7 @@ get_ether_addr(ipaddr, hwaddr) error("Couldn't open /dev/nit: %m"); return 0; } - strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name); + strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); if (ioctl(nit_fd, NIOCBIND, &ifreq) < 0 || ioctl(nit_fd, SIOCGIFADDR, &ifreq) < 0) { error("Couldn't get hardware address for %s: %m", @@ -1211,9 +1272,9 @@ logwtmp(line, name, host) if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0) return; if (!fstat(fd, &buf)) { - strlcpy(ut.ut_line, sizeof(ut.ut_line), line); - strlcpy(ut.ut_name, sizeof(ut.ut_name), name); - strlcpy(ut.ut_host, sizeof(ut.ut_host), host); + strncpy(ut.ut_line, line, sizeof(ut.ut_line)); + strncpy(ut.ut_name, name, sizeof(ut.ut_name)); + strncpy(ut.ut_host, host, sizeof(ut.ut_host)); (void)time(&ut.ut_time); if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp)) (void)ftruncate(fd, buf.st_size); @@ -1271,7 +1332,7 @@ GetMask(addr) /* * Check that the interface is up, and not point-to-point or loopback. */ - strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name); + strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0) continue; if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK)) @@ -1316,6 +1377,7 @@ get_host_seed() return gethostid(); } +#if 0 /* * Code for locking/unlocking the serial device. * This code is derived from chat.c. @@ -1419,6 +1481,57 @@ unlock() lock_file = NULL; } } +#endif /* lock stuff removed */ + +/* + * get_pty - get a pty master/slave pair and chown the slave side + * to the uid given. Assumes slave_name points to >= 12 bytes of space. + */ +int +get_pty(master_fdp, slave_fdp, slave_name, uid) + int *master_fdp; + int *slave_fdp; + char *slave_name; + int uid; +{ + int i, mfd, sfd; + char pty_name[12]; + struct termios tios; + + sfd = -1; + for (i = 0; i < 64; ++i) { + slprintf(pty_name, sizeof(pty_name), "/dev/pty%c%x", + 'p' + i / 16, i % 16); + mfd = open(pty_name, O_RDWR, 0); + if (mfd >= 0) { + pty_name[5] = 't'; + sfd = open(pty_name, O_RDWR | O_NOCTTY, 0); + if (sfd >= 0) + break; + close(mfd); + } + } + if (sfd < 0) + return 0; + + strlcpy(slave_name, pty_name, 12); + *master_fdp = mfd; + *slave_fdp = sfd; + fchown(sfd, uid, -1); + fchmod(sfd, S_IRUSR | S_IWUSR); + if (tcgetattr(sfd, &tios) == 0) { + tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB); + tios.c_cflag |= CS8 | CREAD; + tios.c_iflag = IGNPAR | CLOCAL; + tios.c_oflag = 0; + tios.c_lflag = 0; + if (tcsetattr(sfd, TCSAFLUSH, &tios) < 0) + warn("couldn't set attributes on pty: %m"); + } else + warn("couldn't get attributes on pty: %m"); + + return 1; +} /* * SunOS doesn't have strtoul :-(