]> git.ozlabs.org Git - ppp.git/commitdiff
added GetMask
authorPaul Mackerras <paulus@samba.org>
Thu, 27 Apr 1995 00:45:24 +0000 (00:45 +0000)
committerPaul Mackerras <paulus@samba.org>
Thu, 27 Apr 1995 00:45:24 +0000 (00:45 +0000)
pppd/sys-linux.c
pppd/sys-osf.c
pppd/sys-ultrix.c

index 7d203c7a3a8cd0b6a2aafd729cde519b687a9643..34830f06ba0a11e94433b814397e00dd553071b5 100644 (file)
@@ -1147,6 +1147,73 @@ int get_ether_addr (u_int32_t ipaddr, struct sockaddr *hwaddr)
     return 1;
   }
 
     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 + ifr->ifr_addr.sa_len)) {
+       /*
+        * 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;
+}
+
 /*
  * Internal routine to decode the version.modification.patch level
  */
 /*
  * Internal routine to decode the version.modification.patch level
  */
index cb3c7fd824e84af050e9a51ca9fdfcb871e047f0..66fc07d0856e2da1d44be01968535228fab3783a 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char rcsid[] = "$Id: sys-osf.c,v 1.1 1995/04/24 06:16:23 paulus Exp $";
+static char rcsid[] = "$Id: sys-osf.c,v 1.2 1995/04/27 00:44:46 paulus Exp $";
 #endif
 
 /*
 #endif
 
 /*
@@ -1156,6 +1156,72 @@ get_ether_addr(ipaddr, hwaddr)
 }
 
 
 }
 
 
+/*
+ * 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 + ifr->ifr_addr.sa_len)) {
+       /*
+        * 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;
+}
 
 
 #define        WTMPFILE        "/usr/adm/wtmp"
 
 
 #define        WTMPFILE        "/usr/adm/wtmp"
index faddd6e2d070bf4942bf0372e016c131634111ca..d8653f141d2af8cf4a249f9ec5bde93465838b0e 100644 (file)
@@ -19,7 +19,7 @@
  */
 
 #ifndef lint
  */
 
 #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.9 1995/04/27 00:45:24 paulus Exp $";
 #endif
 
 /*
 #endif
 
 /*
@@ -939,7 +939,7 @@ get_ether_addr(ipaddr, hwaddr)
              */
             if (ioctl(sockfd, SIOCGIFNETMASK, &ifreq) < 0)
                 continue;
              */
             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;
 
             if ((ipaddr & mask) != (ina & mask))
                 continue;
 
@@ -959,7 +959,6 @@ get_ether_addr(ipaddr, hwaddr)
     for (ifr = ifc.ifc_req; ifr < ifend; ) {
         if (strcmp(ifp->ifr_name, ifr->ifr_name) == 0
             && ifr->ifr_addr.sa_family == AF_DLI) {
     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
              */
             /*
              * Found the link-level address - copy it out
              */
@@ -975,6 +974,73 @@ get_ether_addr(ipaddr, hwaddr)
     return 0;
 }
 
     return 0;
 }
 
+/*
+ * 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 + ifr->ifr_addr.sa_len)) {
+       /*
+        * 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;
+}
+
 
 /*
   Seems like strdup() is not part of string package in Ultrix.
 
 /*
   Seems like strdup() is not part of string package in Ultrix.