]> git.ozlabs.org Git - ppp.git/blobdiff - pppd/sys-ultrix.c
save and restore window size settings
[ppp.git] / pppd / sys-ultrix.c
index faddd6e2d070bf4942bf0372e016c131634111ca..7fc4034e6b0cdecc568909eac88f98376faa45e9 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-ultrix.c,v 1.8 1995/04/24 05:35:27 paulus Exp $";
+static char rcsid[] = "$Id: sys-ultrix.c,v 1.14 1995/08/11 02:36:26 paulus Exp $";
 #endif
 
 /*
@@ -52,6 +52,7 @@ static int initdisc = -1;     /* Initial TTY discipline */
 
 static int     restore_term;   /* 1 => we've munged the terminal */
 static struct termios inittermios; /* Initial TTY termios */
+static struct winsize wsinfo;  /* Initial window size info */
 
 static char *lock_file;
 
@@ -336,8 +337,10 @@ set_up_tty(fd, local)
        die(1);
     }
 
-    if (!restore_term)
+    if (!restore_term) {
        inittermios = tios;
+       ioctl(fd, TIOCGWINSZ, &wsinfo);
+    }
 
     tios.c_cflag &= ~(CSIZE | CSTOPB | PARENB | CLOCAL);
 #ifdef CRTSCTS
@@ -401,9 +404,19 @@ void
 restore_tty()
 {
     if (restore_term) {
+       if (!default_device) {
+           /*
+            * Turn off echoing, because otherwise we can get into
+            * a loop with the tty and the modem echoing to each other.
+            * We presume we are the sole user of this tty device, so
+            * when we close it, it will revert to its defaults anyway.
+            */
+           inittermios.c_lflag &= ~(ECHO | ECHONL);
+       }
        if (tcsetattr(fd, TCSAFLUSH, &inittermios) < 0)
            if (errno != ENXIO)
                syslog(LOG_WARNING, "tcsetattr: %m");
+       ioctl(fd, TIOCSWINSZ, &wsinfo);
        restore_term = FALSE;
     }
 }
@@ -900,12 +913,12 @@ get_ether_addr(ipaddr, hwaddr)
     u_int32_t ipaddr;
     struct sockaddr *hwaddr;
 {
-    struct ifreq *ifr, *ifend, *ifp;
+    struct ifreq *ifr, *ifend;
     u_int32_t ina, mask;
-    struct sockaddr_dl *dla;
     struct ifreq ifreq;
     struct ifconf ifc;
     struct ifreq ifs[MAX_IFS];
+    struct ifdevea ifdevea;
 
     ifc.ifc_len = sizeof(ifs);
     ifc.ifc_req = ifs;
@@ -939,7 +952,7 @@ get_ether_addr(ipaddr, hwaddr)
              */
             if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
                 continue;
-            mask = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
+            mask = ((struct sockaddr_in *) &ifreq.ifr_addr)->sin_addr.s_addr;
             if ((ipaddr & mask) != (ina & mask))
                 continue;
 
@@ -952,27 +965,84 @@ get_ether_addr(ipaddr, hwaddr)
     syslog(LOG_INFO, "found interface %s for proxy arp", ifr->ifr_name);
 
     /*
-     * Now scan through again looking for a link-level address
-     * for this interface.
+     * Grab the physical address for this interface.
      */
-    ifp = ifr;
-    for (ifr = ifc.ifc_req; ifr < ifend; ) {
-        if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0
-            && ifr->ifr_addr.sa_family == AF_DLI) {
-/*          && ifr->ifr_addr.sa_family == AF_LINK) { Per! Kolla !!! ROHACK */
-            /*
-             * Found the link-level address - copy it out
-             */
-            dla = (struct sockaddr_dl *)&ifr->ifr_addr;
-            hwaddr->sa_family = AF_UNSPEC;
-            BCOPY(dla, hwaddr->sa_data, sizeof(hwaddr->sa_data));
-            return 1;
-        }
-        ifr = (struct ifreq *) ((char *)&ifr->ifr_addr + sizeof(struct sockaddr)
-);
+    strncpy(ifdevea.ifr_name, ifr->ifr_name, sizeof(ifdevea.ifr_name));
+    if (ioctl(sockfd, SIOCRPHYSADDR, &ifdevea) < 0) {
+       syslog(LOG_ERR, "Couldn't get h/w address for %s: %m", ifr->ifr_name);
+       return 0;
     }
 
-    return 0;
+    hwaddr->sa_family = AF_UNSPEC;
+    BCOPY(ifdevea.current_pa, hwaddr->sa_data, 6);
+    return 1;
+}
+
+/*
+ * Return user specified netmask, modified by any mask we might determine
+ * for address `addr' (in network byte order).
+ * Here we scan through the system's list of interfaces, looking for
+ * any non-point-to-point interfaces which might appear to be on the same
+ * network as `addr'.  If we find any, we OR in their netmask to the
+ * user-specified netmask.
+ */
+u_int32_t
+GetMask(addr)
+    u_int32_t addr;
+{
+    u_int32_t mask, nmask, ina;
+    struct ifreq *ifr, *ifend, ifreq;
+    struct ifconf ifc;
+    struct ifreq ifs[MAX_IFS];
+
+    addr = ntohl(addr);
+    if (IN_CLASSA(addr))       /* determine network mask for address class */
+       nmask = IN_CLASSA_NET;
+    else if (IN_CLASSB(addr))
+       nmask = IN_CLASSB_NET;
+    else
+       nmask = IN_CLASSC_NET;
+    /* class D nets are disallowed by bad_ip_adrs */
+    mask = netmask | htonl(nmask);
+
+    /*
+     * Scan through the system's network interfaces.
+     */
+    ifc.ifc_len = sizeof(ifs);
+    ifc.ifc_req = ifs;
+    if (ioctl(sockfd, SIOCGIFCONF, &ifc) < 0) {
+       syslog(LOG_WARNING, "ioctl(SIOCGIFCONF): %m");
+       return mask;
+    }
+    ifend = (struct ifreq *) (ifc.ifc_buf + ifc.ifc_len);
+    for (ifr = ifc.ifc_req; ifr < ifend; ifr = (struct ifreq *)
+               ((char *)&ifr->ifr_addr + sizeof(struct sockaddr))) {
+       /*
+        * Check the interface's internet address.
+        */
+       if (ifr->ifr_addr.sa_family != AF_INET)
+           continue;
+       ina = ((struct sockaddr_in *) &ifr->ifr_addr)->sin_addr.s_addr;
+       if ((ntohl(ina) & nmask) != (addr & nmask))
+           continue;
+       /*
+        * Check that the interface is up, and not point-to-point or loopback.
+        */
+       strncpy(ifreq.ifr_name, ifr->ifr_name, sizeof(ifreq.ifr_name));
+       if (ioctl(sockfd, SIOCGIFFLAGS, &ifreq) < 0)
+           continue;
+       if ((ifreq.ifr_flags & (IFF_UP|IFF_POINTOPOINT|IFF_LOOPBACK))
+           != IFF_UP)
+           continue;
+       /*
+        * Get its netmask and OR it into our mask.
+        */
+       if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
+           continue;
+       mask |= ((struct sockaddr_in *)&ifreq.ifr_addr)->sin_addr.s_addr;
+    }
+
+    return mask;
 }