move to rev 5
[unix-history] / usr / src / sbin / routed / inet.c
index ef7c52e..81f0f16 100644 (file)
@@ -1,12 +1,13 @@
 /*
  * Copyright (c) 1983 Regents of the University of California.
 /*
  * Copyright (c) 1983 Regents of the University of California.
- * All rights reserved.  The Berkeley software License Agreement
- * specifies the terms and conditions for redistribution.
+ * All rights reserved.
+ *
+ * %sccs.include.redist.c%
  */
 
 #ifndef lint
  */
 
 #ifndef lint
-static char sccsid[] = "@(#)inet.c     5.4 (Berkeley) %G%";
-#endif not lint
+static char sccsid[] = "@(#)inet.c     5.10 (Berkeley) %G%";
+#endif /* not lint */
 
 /*
  * Temporarily, copy these routines from the kernel,
 
 /*
  * Temporarily, copy these routines from the kernel,
@@ -101,6 +102,35 @@ inet_lnaof(in)
        return (host);
 }
 
        return (host);
 }
 
+/*
+ * Return the netmask pertaining to an internet address.
+ */
+inet_maskof(in)
+       struct in_addr in;
+{
+       register u_long i = ntohl(in.s_addr);
+       register u_long mask;
+       register struct interface *ifp;
+
+       if (i == 0) {
+               mask = 0;
+       } else if (IN_CLASSA(i)) {
+               mask = IN_CLASSA_NET;
+       } else if (IN_CLASSB(i)) {
+               mask = i & IN_CLASSB_NET;
+       } else
+               mask = i & IN_CLASSC_NET;
+
+       /*
+        * Check whether network is a subnet;
+        * if so, use the modified interpretation of `host'.
+        */
+       for (ifp = ifnet; ifp; ifp = ifp->int_next)
+               if ((ifp->int_netmask & i) == ifp->int_net)
+                       mask = ifp->int_subnetmask;
+       return (htonl(mask));
+}
+
 /*
  * Return RTF_HOST if the address is
  * for an Internet host, RTF_SUBNET for a subnet,
 /*
  * Return RTF_HOST if the address is
  * for an Internet host, RTF_SUBNET for a subnet,
@@ -144,11 +174,11 @@ inet_rtflags(sin)
 }
 
 /*
 }
 
 /*
- * Return true if a route to subnet of route rt should be sent to dst.
- * Send it only if dst is on the same logical network,
- * or the route is the "internal" route for the net.
+ * Return true if a route to subnet/host of route rt should be sent to dst.
+ * Send it only if dst is on the same logical network if not "internal",
+ * otherwise only if the route is the "internal" route for the logical net.
  */
  */
-inet_sendsubnet(rt, dst)
+inet_sendroute(rt, dst)
        struct rt_entry *rt;
        struct sockaddr_in *dst;
 {
        struct rt_entry *rt;
        struct sockaddr_in *dst;
 {