X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fsys-svr4.c;h=4173e4d2f4c246e81431403960c3929ad0689d80;hb=0375e3ce50b9e0bc4e559615039988e7834c7d01;hp=fcdc6ba22564384a0901871f3d84c5edaf720018;hpb=9a7163be646110ba65b7b43da550662052f13d80;p=ppp.git diff --git a/pppd/sys-svr4.c b/pppd/sys-svr4.c index fcdc6ba..4173e4d 100644 --- a/pppd/sys-svr4.c +++ b/pppd/sys-svr4.c @@ -26,7 +26,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-svr4.c,v 1.20 1999/02/26 10:35:34 paulus Exp $"; +static char rcsid[] = "$Id: sys-svr4.c,v 1.24 1999/03/12 06:07:23 paulus Exp $"; #endif #include @@ -91,6 +91,7 @@ static int tty_nmodules; static char tty_modules[NMODULES][FMNAMESZ+1]; static int if_is_up; /* Interface has been marked up */ +static u_int32_t remote_addr; /* IP address of peer */ static u_int32_t default_route_gateway; /* Gateway for default route added */ static u_int32_t proxy_arp_addr; /* Addr for proxy arp entry added */ @@ -627,14 +628,6 @@ restore_tty(fd) } } -/* - * hangup_modem - hang up the modem by clearing DTR. - */ -void hangup_modem(int ttyfd) -{ - setdtr(ttyfd, 0); -} - /* * setdtr - control the DTR line on the serial port. * This is called from die(), so it shouldn't call die(). @@ -831,7 +824,7 @@ ppp_send_config(unit, mtu, asyncmap, pcomp, accomp) /* set the MTU for IP as well */ memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); ifr.ifr_metric = link_mtu; if (ioctl(ipfd, SIOCSIFMTU, &ifr) < 0) { syslog(LOG_ERR, "Couldn't set IP MTU: %m"); @@ -1013,7 +1006,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(ipfd, SIOCGIFFLAGS, &ifr) < 0) { syslog(LOG_ERR, "Couldn't mark interface up (get): %m"); return 0; @@ -1038,7 +1031,7 @@ sifdown(u) if (ipmuxid < 0) return 1; - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); if (ioctl(ipfd, SIOCGIFFLAGS, &ifr) < 0) { syslog(LOG_ERR, "Couldn't mark interface down (get): %m"); return 0; @@ -1086,7 +1079,7 @@ sifaddr(u, o, h, m) int ret = 1; memset(&ifr, 0, sizeof(ifr)); - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); ifr.ifr_addr.sa_family = AF_INET; INET_ADDR(ifr.ifr_addr) = m; if (ioctl(ipfd, SIOCSIFNETMASK, &ifr) < 0) { @@ -1125,6 +1118,7 @@ sifaddr(u, o, h, m) } #endif + remote_addr = h; return ret; } @@ -1148,6 +1142,7 @@ cifaddr(u, o, h) ipmuxid = -1; } #endif + remote_addr = 0; return 1; } @@ -1296,7 +1291,7 @@ get_ether_addr(ipaddr, hwaddr) /* * 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(ipfd, SIOCGIFFLAGS, &ifreq) < 0) continue; if ((ifreq.ifr_flags & @@ -1372,12 +1367,12 @@ get_hw_addr(name, ina, hwaddr) * We have to open the device and ask it for its hardware address. * First split apart the device name and unit. */ - strcpy(ifdev, "/dev/"); - q = ifdev + 5; /* strlen("/dev/") */ - while (*name != 0 && !isdigit(*name)) - *q++ = *name++; - *q = 0; - unit = atoi(name); + slprintf(ifdev, sizeof(ifdev), "/dev/%s", name); + for (q = ifdev + strlen(ifdev); --q >= ifdev; ) + if (!isdigit(*q)) + break; + unit = atoi(q+1); + q[1] = 0; /* * Open the device and do a DLPI attach and phys_addr_req. @@ -1545,7 +1540,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(ipfd, SIOCGIFFLAGS, &ifreq) < 0) continue; if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK)) @@ -1574,9 +1569,9 @@ logwtmp(line, name, host) if (name[0] != 0) { /* logging in */ - strncpy(utmpx.ut_user, name, sizeof(utmpx.ut_user)); - strncpy(utmpx.ut_id, ifname, sizeof(utmpx.ut_id)); - strncpy(utmpx.ut_line, line, sizeof(utmpx.ut_line)); + strlcpy(utmpx.ut_user, sizeof(utmpx.ut_user), name); + strlcpy(utmpx.ut_id, sizeof(utmpx.ut_id), ifname); + strlcpy(utmpx.ut_line, sizeof(utmpx.ut_line), line); utmpx.ut_pid = getpid(); utmpx.ut_type = USER_PROCESS; } else { @@ -1726,6 +1721,9 @@ cifroute(u, our, his) /* * have_route_to - determine if the system has a route to the specified * IP address. Returns 0 if not, 1 if so, -1 if we can't tell. + * `addr' is in network byte order. + * For demand mode to work properly, we have to ignore routes + * through our own interface. */ #ifndef T_CURRENT /* needed for Solaris 2.5 */ #define T_CURRENT MI_T_CURRENT @@ -1813,7 +1811,8 @@ have_route_to(addr) syslog(LOG_DEBUG, "have_route_to: dest=%x gw=%x mask=%x\n", rp->ipRouteDest, rp->ipRouteNextHop, rp->ipRouteMask); - if (((addr ^ rp->ipRouteDest) && rp->ipRouteMask) == 0) + if (((addr ^ rp->ipRouteDest) & rp->ipRouteMask) == 0 + && rp->ipRouteNextHop != remote_addr) return 1; } }