X-Git-Url: https://git.ozlabs.org/?a=blobdiff_plain;f=pppd%2Fsys-NeXT.c;h=6ec682fb23b06995dbca8e22ec969c6331d81eae;hb=1fae28ce79350b03f0cf8a69ad06dd68637cd6b1;hp=ee2cece2f4e0bbfad49e480f1c3957005d01809e;hpb=f69a54671e8b3777681017c01c1984207e3d881d;p=ppp.git diff --git a/pppd/sys-NeXT.c b/pppd/sys-NeXT.c index ee2cece..6ec682f 100644 --- a/pppd/sys-NeXT.c +++ b/pppd/sys-NeXT.c @@ -20,7 +20,7 @@ */ #ifndef lint -static char rcsid[] = "$Id: sys-NeXT.c,v 1.8 1997/04/30 05:57:14 paulus Exp $"; +static char rcsid[] = "$Id: sys-NeXT.c,v 1.12 1999/03/12 06:07:20 paulus Exp $"; #endif #include @@ -29,6 +29,7 @@ static char rcsid[] = "$Id: sys-NeXT.c,v 1.8 1997/04/30 05:57:14 paulus Exp $"; #include #include #include +#include #include #include #include @@ -46,7 +47,10 @@ static char rcsid[] = "$Id: sys-NeXT.c,v 1.8 1997/04/30 05:57:14 paulus Exp $"; #include #include #include +#if !(NS_TARGET >= 40) +/* XXX get an error "duplicate member ip_v under 4.1 GAMMA */ #include +#endif /* NS_TARGET */ #include #include #include @@ -70,6 +74,7 @@ static struct termios inittermios; /* Initial TTY termios */ static char *lock_file; static int sockfd; /* socket for doing interface ioctls */ +static int pppdev; /* +++ */ #if defined(i386) && defined(HAS_BROKEN_IOCTL) #define ioctl myioctl @@ -101,6 +106,13 @@ sys_init() syslog(LOG_ERR, "Couldn't create IP socket: %m"); die(1); } + + if((pppdev = open("/dev/ppp0", O_RDWR, O_NONBLOCK)) == NULL) + { + syslog(LOG_ERR, "Couldn't open /dev/ppp0: %m"); + die(1); + } + } /* @@ -114,7 +126,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; @@ -126,6 +138,8 @@ sys_cleanup() cifdefaultroute(0, 0, default_route_gateway); if (proxy_arp_addr) cifproxyarp(0, proxy_arp_addr); + + close(pppdev); } /* @@ -156,7 +170,7 @@ ppp_available() if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) return 1; /* can't tell - maybe we're not root */ - 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); @@ -588,7 +602,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"); @@ -754,7 +768,7 @@ sifup(u) u_int x; struct npioctl npi; - 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; @@ -805,7 +819,7 @@ sifdown(u) /* ignore errors, because ttyfd 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; @@ -840,7 +854,7 @@ sifaddr(u, o, h, m) struct ifreq ifr; ret = 1; - strncpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); + strlcpy(ifr.ifr_name, sizeof(ifr.ifr_name), ifname); SET_SA_FAMILY(ifr.ifr_addr, AF_INET); ((struct sockaddr_in *) &ifr.ifr_addr)->sin_addr.s_addr = o; if (ioctl(sockfd, SIOCSIFADDR, (caddr_t) &ifr) < 0) { @@ -1029,7 +1043,7 @@ get_ether_addr(ipaddr, hwaddr) ((char *)&ifr->ifr_addr + sizeof(struct sockaddr))) { 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. @@ -1091,7 +1105,7 @@ ether_by_host(hostname, etherptr) * find the address in the * top domain of netinfo. */ - strcat(strcpy(path, "/machines/"), hostname); + slprintf(path, sizeof(path), "/machines/%s", hostname); if (ni_open((void *)0, "/", &conn) || ni_root(conn, &root) @@ -1102,7 +1116,7 @@ ether_by_host(hostname, etherptr) /* * Now we can convert the returned string into an ethernet address. */ - strcpy(path, val.ni_namelist_val[0]); + strlcpy(path, sizeof(path), val.ni_namelist_val[0]); ni_free(conn); if ((thisptr = (struct ether_addr*)ether_aton(path)) == NULL) return 1; @@ -1162,7 +1176,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)) @@ -1179,6 +1193,16 @@ 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; +} /* @@ -1248,9 +1272,9 @@ logwtmp(line, name, host) if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0) return; if (!fstat(fd, &buf)) { - (void)strncpy(ut.ut_line, line, sizeof(ut.ut_line)); - (void)strncpy(ut.ut_name, name, sizeof(ut.ut_name)); - (void)strncpy(ut.ut_host, host, sizeof(ut.ut_host)); + 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); (void)time(&ut.ut_time); if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp)) (void)ftruncate(fd, buf.st_size); @@ -1274,13 +1298,15 @@ lock(dev) { 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 @@ -1609,20 +1635,31 @@ restore_loop() } +/* + * Use the hostid as part of the random number seed. + */ +int +get_host_seed() +{ + return gethostid(); +} + + /* * sys_check_options - check the options that the user specified */ -void +int sys_check_options() { /* * We don't support demand dialing yet. */ - if(demand) + if (demand) { syslog(LOG_WARNING, "PPP-2.3 for NeXTSTEP does not yet support demand dialing\n"); - demand = 0; + return 0; } + return 1; }