X-Git-Url: http://git.ozlabs.org/?p=ppp.git;a=blobdiff_plain;f=pppd%2Fsys-bsd.c;h=c2475a18d0b28cee72aba20a06ea0786a6f08a3c;hp=88d22848272ab7461254e38348e16b513ad64f44;hb=1fae28ce79350b03f0cf8a69ad06dd68637cd6b1;hpb=44e1777caa7658b455b5269f895734a5c33d2246 diff --git a/pppd/sys-bsd.c b/pppd/sys-bsd.c index 88d2284..c2475a1 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.33 1998/09/04 18:49:16 christos Exp $"; +static char rcsid[] = "$Id: sys-bsd.c,v 1.36 1999/03/12 06:07:21 paulus Exp $"; /* $NetBSD: sys-bsd.c,v 1.1.1.3 1997/09/26 18:53:04 christos Exp $ */ #endif @@ -128,7 +128,7 @@ sys_cleanup() struct ifreq ifr; if (if_is_up) { - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) >= 0 && ((ifr.ifr_flags & IFF_UP) != 0)) { ifr.ifr_flags &= ~IFF_UP; @@ -159,9 +159,16 @@ sys_close() /* * sys_check_options - check the options that the user specified */ -void +int sys_check_options() { +#ifndef CDTRCTS + if (crtscts == 2) { + syslog(LOG_WARNING, "DTR/CTS flow control is not supported on this system"); + return 0; + } +#endif + return 1; } /* @@ -178,7 +185,7 @@ ppp_available() if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1; /* can't tell */ - strncpy(ifr.ifr_name, "ppp0", sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), "ppp0"); ok = ioctl(s, SIOCGIFFLAGS, (caddr_t) &ifr) >= 0; close(s); @@ -389,9 +396,6 @@ set_up_tty(fd, local) if (crtscts == 2) { #ifdef CDTRCTS tios.c_cflag |= CDTRCTS; -#else - syslog(LOG_ERR, "System does not support DTR/CTS flow control"); - die(1); #endif } else tios.c_cflag |= CRTSCTS; @@ -684,7 +688,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp) u_int x; struct ifreq ifr; - strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname); ifr.ifr_mtu = mtu; if (ioctl(sockfd, SIOCSIFMTU, (caddr_t) &ifr) < 0) { syslog(LOG_ERR, "ioctl(SIOCSIFMTU): %m"); @@ -884,7 +888,7 @@ sifup(u) { struct ifreq ifr; - strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname); if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m"); return 0; @@ -935,7 +939,7 @@ sifdown(u) ioctl(ppp_fd, PPPIOCSNPMODE, (caddr_t) &npi); /* ignore errors, because ppp_fd might have been closed by now. */ - strncpy(ifr.ifr_name, ifname, sizeof (ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof (ifr.ifr_name), ifname); if (ioctl(sockfd, SIOCGIFFLAGS, (caddr_t) &ifr) < 0) { syslog(LOG_ERR, "ioctl (SIOCGIFFLAGS): %m"); rv = 0; @@ -970,7 +974,7 @@ sifaddr(u, o, h, m) struct ifaliasreq ifra; struct ifreq ifr; - strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name)); + strlcpy(ifra.ifra_name, sizeof(ifra.ifra_name), ifname); 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); @@ -981,7 +985,7 @@ sifaddr(u, o, h, m) } else BZERO(&ifra.ifra_mask, sizeof(ifra.ifra_mask)); BZERO(&ifr, sizeof(ifr)); - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); if (ioctl(sockfd, SIOCDIFADDR, (caddr_t) &ifr) < 0) { if (errno != EADDRNOTAVAIL) syslog(LOG_WARNING, "Couldn't remove interface address: %m"); @@ -1012,7 +1016,7 @@ cifaddr(u, o, h) struct ifaliasreq ifra; ifaddrs[0] = 0; - strncpy(ifra.ifra_name, ifname, sizeof(ifra.ifra_name)); + strlcpy(ifra.ifra_name, sizeof(ifra.ifra_name), ifname); 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); @@ -1290,7 +1294,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; - strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); + strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name); /* * Check that the interface is up, and not point-to-point * or loopback. @@ -1389,7 +1393,7 @@ GetMask(addr) /* * Check that the interface is up, and not point-to-point or loopback. */ - strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name)); + strlcpy(ifreq.ifr_name, sizeof(ifreq.ifr_name), ifr->ifr_name); if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0) continue; if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK)) @@ -1406,6 +1410,17 @@ GetMask(addr) return mask; } +/* + * have_route_to - determine if the system has any route to + * a given IP address. + * For demand mode to work properly, we have to ignore routes + * through our own interface. + */ +int have_route_to(u_int32_t addr) +{ + return -1; +} + /* * Use the hostid as part of the random number seed. */ @@ -1427,13 +1442,15 @@ lock(dev) char hdb_lock_buffer[12]; int fd, pid, n; char *p; + size_t l; if ((p = strrchr(dev, '/')) != NULL) dev = p + 1; - lock_file = malloc(strlen(LOCK_PREFIX) + strlen(dev) + 1); + l = strlen(LOCK_PREFIX) + strlen(dev) + 1; + lock_file = malloc(l); if (lock_file == NULL) novm("lock file name"); - strcat(strcpy(lock_file, LOCK_PREFIX), dev); + slprintf(lock_file, l, "%s%s", LOCK_PREFIX, dev); while ((fd = open(lock_file, O_EXCL | O_CREAT | O_RDWR, 0644)) < 0) { if (errno == EEXIST