From 9557844c482a3a2302df69e06677178247634d56 Mon Sep 17 00:00:00 2001 From: David McCullough Date: Thu, 17 Jan 2002 03:58:58 +0000 Subject: Add in support for inet_netof, inet_lnaof, inet_makeaddr and hstrerror. --- libc/inet/addr.c | 66 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) (limited to 'libc/inet/addr.c') 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 -- cgit v1.2.3