summaryrefslogtreecommitdiff
path: root/libc/inet/addr.c
diff options
context:
space:
mode:
Diffstat (limited to 'libc/inet/addr.c')
-rw-r--r--libc/inet/addr.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/libc/inet/addr.c b/libc/inet/addr.c
index 15f6d0a5a..d1f9c04e6 100644
--- a/libc/inet/addr.c
+++ b/libc/inet/addr.c
@@ -112,3 +112,69 @@ struct in_addr in;
return p+1;
}
#endif
+
+#ifdef L_inet_makeaddr
+/*
+ * Formulate an Internet address from network + host. Used in
+ * building addresses stored in the ifnet structure.
+ */
+struct in_addr inet_makeaddr(net, host)
+unsigned long net, host;
+{
+ unsigned long addr;
+
+ if (net < 128)
+ addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
+ else if (net < 65536)
+ addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
+ else if (net < 16777216L)
+ addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
+ else
+ addr = net | host;
+ addr = htonl(addr);
+ return (*(struct in_addr *)&addr);
+}
+
+#endif
+
+#ifdef L_inet_lnaof
+/*
+ * Return the local network address portion of an
+ * internet address; handles class a/b/c network
+ * number formats.
+ */
+unsigned long inet_lnaof(in)
+struct in_addr in;
+{
+ unsigned long i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return ((i)&IN_CLASSA_HOST);
+ else if (IN_CLASSB(i))
+ return ((i)&IN_CLASSB_HOST);
+ else
+ return ((i)&IN_CLASSC_HOST);
+}
+#endif
+
+#ifdef L_inet_netof
+
+/*
+ * Return the network number from an internet
+ * address; handles class a/b/c network #'s.
+ */
+u_int32_t
+inet_netof(in)
+ struct in_addr in;
+{
+ u_int32_t i = ntohl(in.s_addr);
+
+ if (IN_CLASSA(i))
+ return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
+ else if (IN_CLASSB(i))
+ return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
+ else
+ return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
+}
+
+#endif