]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-osf.c
typo
[ppp.git] / pppd / sys-osf.c
index c25e33921afdc3eb4b1139d11748c02b9e837304..920b30af1315cadac88fb7003c554e024b7f5184 100644 (file)
@@ -25,9 +25,7 @@
  * OR MODIFICATIONS.
  */
 
-#ifndef lint
-static char rcsid[] = "$Id: sys-osf.c,v 1.22 1999/03/19 04:23:49 paulus Exp $";
-#endif
+#define RCSID  "$Id: sys-osf.c,v 1.30 1999/08/13 06:46:18 paulus Exp $"
 
 #include <stdio.h>
 #include <stddef.h>
@@ -61,6 +59,8 @@ static char rcsid[] = "$Id: sys-osf.c,v 1.22 1999/03/19 04:23:49 paulus Exp $";
 
 #include "pppd.h"
 
+static const char rcsid[] = RCSID;
+
 static int     pppfd;
 static int     fdmuxid = -1;
 static int     iffd;
@@ -200,7 +200,7 @@ sys_check_options()
     return 1;
 }
 
-
+#if 0
 /*
  * daemon - Detach us from controlling terminal session.
  */
@@ -224,6 +224,7 @@ daemon(nochdir, noclose)
     }
     return 0;
 }
+#endif
 
 /*
  * ppp_available - check whether the system has any ppp interfaces
@@ -374,6 +375,13 @@ establish_ppp(fd)
             if (i != fd && i != sockfd)
                 close(i);
         closed_stdio = 1;
+       /* make sure 0, 1, 2 are open to /dev/null */
+       while ((i = open("/dev/null", O_RDWR)) >= 0) {
+           if (i > 2) {
+               close(i);
+               break;
+           }
+       }
     }
 
     /*
@@ -836,7 +844,7 @@ read_packet(buf)
        flags = 0;
        len = getmsg(pppfd, &ctrl, &data, &flags);
        if (len < 0) {
-           if (errno = EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
+           if (errno == EAGAIN || errno == EWOULDBLOCK || errno == EINTR)
                return -1;
            fatal("Error reading packet: %m");
        }
@@ -1017,12 +1025,16 @@ get_idle_time(u, ip)
 int
 get_ppp_stats(u, stats)
     int u;
-    struct ppp_stats *stats;
+    struct pppd_stats *stats;
 {
-    if (strioctl(pppfd, PPPIO_GETSTAT, stats, 0, sizeof(*stats)) < 0) {
+    struct ppp_stats s;
+
+    if (strioctl(pppfd, PPPIO_GETSTAT, &s, 0, sizeof(s)) < 0) {
        error("Couldn't get link statistics: %m");
        return 0;
     }
+    stats->bytes_in = s.p.ppp_ibytes;
+    stats->bytes_out = s.p.ppp_obytes;
     return 1;
 }
 
@@ -1108,6 +1120,7 @@ sifdown(u)
 {
     struct ifreq ifr;
 
+    bzero(&ifr, sizeof(ifr));
     strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name));
     if (ioctl(sockfd, SIOCGIFFLAGS, &ifr) < 0) {
        error("Couldn't mark interface down (get): %m");
@@ -1200,7 +1213,8 @@ sifaddr(u, o, h, m)
         ret = 0;
     }
 
-    ifr.ifr_metric = link_mtu;
+    ifr.ifr_data = (caddr_t)&link_mtu;
+
     if (ioctl(sockfd, SIOCSIPMTU, &ifr) < 0) {
        error("Couldn't set IP MTU: %m");
         ret = 0;
@@ -1430,9 +1444,9 @@ logwtmp(line, name, host)
     if ((fd = open(WTMPFILE, O_WRONLY|O_APPEND, 0)) < 0)
        return;
     if (!fstat(fd, &buf)) {
-       strlcpy(ut.ut_line, line, sizeof(ut.ut_line));
-       strlcpy(ut.ut_name, name, sizeof(ut.ut_name));
-       strlcpy(ut.ut_host, host, sizeof(ut.ut_host));
+       strncpy(ut.ut_line, line, sizeof(ut.ut_line));
+       strncpy(ut.ut_name, name, sizeof(ut.ut_name));
+       strncpy(ut.ut_host, host, sizeof(ut.ut_host));
        (void)time(&ut.ut_time);
        if (write(fd, (char *)&ut, sizeof(struct utmp)) != sizeof(struct utmp))
            (void)ftruncate(fd, buf.st_size);
@@ -1604,6 +1618,57 @@ get_host_seed()
     return gethostid();
 }
 
+/*
+ * get_pty - get a pty master/slave pair and chown the slave side
+ * to the uid given.  Assumes slave_name points to >= 12 bytes of space.
+ */
+int
+get_pty(master_fdp, slave_fdp, slave_name, uid)
+    int *master_fdp;
+    int *slave_fdp;
+    char *slave_name;
+    int uid;
+{
+    int i, mfd, sfd;
+    char pty_name[12];
+    struct termios tios;
+
+    sfd = -1;
+    for (i = 0; i < 64; ++i) {
+       slprintf(pty_name, sizeof(pty_name), "/dev/pty%c%x",
+                'p' + i / 16, i % 16);
+       mfd = open(pty_name, O_RDWR, 0);
+       if (mfd >= 0) {
+           pty_name[5] = 't';
+           sfd = open(pty_name, O_RDWR | O_NOCTTY, 0);
+           if (sfd >= 0)
+               break;
+           close(mfd);
+       }
+    }
+    if (sfd < 0)
+       return 0;
+
+    strlcpy(slave_name, pty_name, 12);
+    *master_fdp = mfd;
+    *slave_fdp = sfd;
+    fchown(sfd, uid, -1);
+    fchmod(sfd, S_IRUSR | S_IWUSR);
+    if (tcgetattr(sfd, &tios) == 0) {
+       tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB);
+       tios.c_cflag |= CS8 | CREAD;
+       tios.c_iflag  = IGNPAR | CLOCAL;
+       tios.c_oflag  = 0;
+       tios.c_lflag  = 0;
+       if (tcsetattr(sfd, TCSAFLUSH, &tios) < 0)
+           warn("couldn't set attributes on pty: %m");
+    } else
+       warn("couldn't get attributes on pty: %m");
+
+    return 1;
+}
+
+#if 0
 /*
  * Code for locking/unlocking the serial device.
  * This code is derived from chat.c.
@@ -1707,6 +1772,7 @@ unlock()
        lock_file = NULL;
     }
 }
+#endif
 
 int
 set_filters(pass, active)