*/
#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 <stdio.h>
#include <utmp.h>
#include <unistd.h>
#include <stdlib.h>
+#include <libc.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/file.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/in_var.h>
+#if !(NS_TARGET >= 40)
+/* XXX get an error "duplicate member ip_v under 4.1 GAMMA */
#include <netinet/ip.h>
+#endif /* NS_TARGET */
#include <netinet/if_ether.h>
#include <net/route.h>
#include <netinet/in.h>
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
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);
+ }
+
}
/*
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;
cifdefaultroute(0, 0, default_route_gateway);
if (proxy_arp_addr)
cifproxyarp(0, proxy_arp_addr);
+
+ close(pppdev);
}
/*
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);
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");
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;
/* 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;
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) {
((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.
* 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)
/*
* 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;
/*
* 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))
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;
+}
/*
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);
{
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
}
+/*
+ * 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;
}