X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fsys-bsd.c;h=27c568921187984fa3d53b460b2d24503858b917;hb=ade32d2243161da94d757258cd0929a975a6a74c;hp=b830e01c3935851040b4a3ab96571639db2fa4ca;hpb=cb6271cf11b1237286e53124dd7a6ac2e24f6671;p=ppp.git diff --git a/pppd/sys-bsd.c b/pppd/sys-bsd.c index b830e01..27c5689 100644 --- a/pppd/sys-bsd.c +++ b/pppd/sys-bsd.c @@ -21,7 +21,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-bsd.c,v 1.37 1999/03/16 02:57:06 paulus Exp $"; +static char rcsid[] = "$Id: sys-bsd.c,v 1.41 1999/03/22 05:55:36 paulus Exp $"; /* $NetBSD: sys-bsd.c,v 1.1.1.3 1997/09/26 18:53:04 christos Exp $ */ #endif @@ -131,7 +131,7 @@ sys_cleanup() struct ifreq ifr; if (if_is_up) { - strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0 && ((ifr.ifr_flags & IFF_UP) != 0)) { ifr.ifr_flags &= ~IFF_UP; @@ -188,7 +188,7 @@ ppp_available() if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1; /* can't tell */ - strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), "ppp0"); + strlcpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; close(s); @@ -202,7 +202,7 @@ file in the ppp-2.2 distribution.\n"; /* * establish_ppp - Turn the serial port into a ppp interface. */ -void +int establish_ppp(fd) int fd; { @@ -265,6 +265,8 @@ establish_ppp(fd) || fcntl(fd, F_SETFL, initfdflags | O_NONBLOCK) == -1) { warn("Couldn't set device to non-blocking mode: %m"); } + + return fd; } /* @@ -464,7 +466,7 @@ int fd, on; * packets in demand mode, and connect it to a ppp interface. * Here we use a pty. */ -void +int open_ppp_loopback() { int flags; @@ -512,6 +514,7 @@ open_ppp_loopback() } } + return loop_master; } @@ -556,7 +559,8 @@ wait_input(timo) /* * add_fd - add an fd to the set that wait_input waits for. */ -void add_fd(int fd) +void add_fd(fd) + int fd; { FD_SET(fd, &in_fds); if (fd > max_in_fd) @@ -566,7 +570,8 @@ void add_fd(int fd) /* * remove_fd - remove an fd from the set that wait_input waits for. */ -void remove_fd(int fd) +void remove_fd(fd) + int fd; { FD_CLR(fd, &in_fds); } @@ -665,7 +670,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp) u_int x; struct ifreq ifr; - strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); ifr.ifr_mtu = mtu; if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) fatal("ioctl(SIOCSIFMTU): %m"); @@ -787,6 +792,27 @@ get_idle_time(u, ip) return ioctl(ppp_fd, PPPIOCGIDLE, ip) >= 0; } +/* + * get_ppp_stats - return statistics for the link. + */ +int +get_ppp_stats(u, stats) + int u; + struct pppd_stats *stats; +{ + struct ifpppstatsreq req; + + memset (&req, 0, sizeof (req)); + strlcpy(req.ifr_name, interface, sizeof(req.ifr_name)); + if (ioctl(sockfd, SIOCGPPPSTATS, &req) < 0) { + error("Couldn't get PPP statistics: %m"); + return 0; + } + stats->bytes_in = req.stats.p.ppp_ibytes; + stats->bytes_out = req.stats.p.ppp_obytes; + return 1; +} + #ifdef PPP_FILTER /* @@ -849,7 +875,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, (caddr_t) &ifr) < 0) { error("ioctl (SIOCGIFFLAGS): %m"); return 0; @@ -900,7 +926,7 @@ sifdown(u) ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi); /* ignore errors, because ppp_fd might have been closed by now. */ - strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { error("ioctl (SIOCGIFFLAGS): %m"); rv = 0; @@ -935,7 +961,7 @@ sifaddr(u, o, h, m) struct ifaliasreq ifra; struct ifreq ifr; - strlcpy(ifra.ifra_name, sizeof(ifra.ifra_name), ifname); + strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name)); SET_SA_FAMILY(ifra.ifra_addr, AF_INET); ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o; SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET); @@ -946,7 +972,7 @@ sifaddr(u, o, h, m) } else BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask)); BZERO(&ifr, sizeof(ifr)); - strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); + strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) { if (errno != EADDRNOTAVAIL) warn("Couldn't remove interface address: %m"); @@ -975,7 +1001,7 @@ cifaddr(u, o, h) struct ifaliasreq ifra; ifaddrs[0] = 0; - strlcpy(ifra.ifra_name, sizeof(ifra.ifra_name), ifname); + strlcpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name)); SET_SA_FAMILY(ifra.ifra_addr, AF_INET); ((struct sockaddr_in *) &ifra.ifra_addr)->sin_addr.s_addr = o; SET_SA_FAMILY(ifra.ifra_broadaddr, AF_INET); @@ -1253,7 +1279,7 @@ get_ether_addr(ipaddr, hwaddr) ((char *)&ifr->ifr_addr + ifr->ifr_addr.sa_len)) { if (ifr->ifr_addr.sa_family == AF_INET) { ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr; - strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name); + strlcpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); /* * Check that the interface is up, and not point-to-point * or loopback. @@ -1352,7 +1378,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))