17c478bd9Sstevel@tonic-gate /*
29525b14bSRao Shoaib  * Copyright (c) 2004 by Internet Systems Consortium, Inc. ("ISC")
37c478bd9Sstevel@tonic-gate  * Copyright (c) 1996,1999 by Internet Software Consortium.
47c478bd9Sstevel@tonic-gate  *
57c478bd9Sstevel@tonic-gate  * Permission to use, copy, modify, and distribute this software for any
67c478bd9Sstevel@tonic-gate  * purpose with or without fee is hereby granted, provided that the above
77c478bd9Sstevel@tonic-gate  * copyright notice and this permission notice appear in all copies.
87c478bd9Sstevel@tonic-gate  *
99525b14bSRao Shoaib  * THE SOFTWARE IS PROVIDED "AS IS" AND ISC DISCLAIMS ALL WARRANTIES
109525b14bSRao Shoaib  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
119525b14bSRao Shoaib  * MERCHANTABILITY AND FITNESS.  IN NO EVENT SHALL ISC BE LIABLE FOR
129525b14bSRao Shoaib  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
139525b14bSRao Shoaib  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
149525b14bSRao Shoaib  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
159525b14bSRao Shoaib  * OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
167c478bd9Sstevel@tonic-gate  */
177c478bd9Sstevel@tonic-gate 
187c478bd9Sstevel@tonic-gate /* Imports */
197c478bd9Sstevel@tonic-gate 
207c478bd9Sstevel@tonic-gate #include "port_before.h"
217c478bd9Sstevel@tonic-gate 
227c478bd9Sstevel@tonic-gate #if !defined(__BIND_NOSTATIC)
237c478bd9Sstevel@tonic-gate 
247c478bd9Sstevel@tonic-gate #include <sys/types.h>
257c478bd9Sstevel@tonic-gate #include <sys/socket.h>
267c478bd9Sstevel@tonic-gate 
277c478bd9Sstevel@tonic-gate #include <netinet/in.h>
287c478bd9Sstevel@tonic-gate #include <arpa/nameser.h>
297c478bd9Sstevel@tonic-gate #include <arpa/inet.h>
307c478bd9Sstevel@tonic-gate 
317c478bd9Sstevel@tonic-gate #include <ctype.h>
327c478bd9Sstevel@tonic-gate #include <errno.h>
337c478bd9Sstevel@tonic-gate #include <netdb.h>
347c478bd9Sstevel@tonic-gate #include <resolv.h>
357c478bd9Sstevel@tonic-gate #include <stdlib.h>
367c478bd9Sstevel@tonic-gate #include <string.h>
377c478bd9Sstevel@tonic-gate 
387c478bd9Sstevel@tonic-gate #include <irs.h>
397c478bd9Sstevel@tonic-gate 
407c478bd9Sstevel@tonic-gate #include "port_after.h"
417c478bd9Sstevel@tonic-gate 
427c478bd9Sstevel@tonic-gate #include "irs_p.h"
437c478bd9Sstevel@tonic-gate #include "irs_data.h"
447c478bd9Sstevel@tonic-gate 
457c478bd9Sstevel@tonic-gate /* Definitions */
467c478bd9Sstevel@tonic-gate 
477c478bd9Sstevel@tonic-gate struct pvt {
487c478bd9Sstevel@tonic-gate 	struct netent	netent;
497c478bd9Sstevel@tonic-gate 	char *		aliases[1];
507c478bd9Sstevel@tonic-gate 	char		name[MAXDNAME + 1];
517c478bd9Sstevel@tonic-gate };
527c478bd9Sstevel@tonic-gate 
537c478bd9Sstevel@tonic-gate /* Forward */
547c478bd9Sstevel@tonic-gate 
557c478bd9Sstevel@tonic-gate static struct net_data *init(void);
567c478bd9Sstevel@tonic-gate static struct netent   *nw_to_net(struct nwent *, struct net_data *);
577c478bd9Sstevel@tonic-gate static void		freepvt(struct net_data *);
587c478bd9Sstevel@tonic-gate static struct netent   *fakeaddr(const char *, int af, struct net_data *);
597c478bd9Sstevel@tonic-gate 
607c478bd9Sstevel@tonic-gate /* Portability */
617c478bd9Sstevel@tonic-gate 
627c478bd9Sstevel@tonic-gate #ifndef INADDR_NONE
637c478bd9Sstevel@tonic-gate # define INADDR_NONE 0xffffffff
647c478bd9Sstevel@tonic-gate #endif
657c478bd9Sstevel@tonic-gate 
667c478bd9Sstevel@tonic-gate /* Public */
677c478bd9Sstevel@tonic-gate 
687c478bd9Sstevel@tonic-gate struct netent *
getnetent()697c478bd9Sstevel@tonic-gate getnetent() {
707c478bd9Sstevel@tonic-gate 	struct net_data *net_data = init();
717c478bd9Sstevel@tonic-gate 
727c478bd9Sstevel@tonic-gate 	return (getnetent_p(net_data));
737c478bd9Sstevel@tonic-gate }
747c478bd9Sstevel@tonic-gate 
757c478bd9Sstevel@tonic-gate struct netent *
getnetbyname(const char * name)767c478bd9Sstevel@tonic-gate getnetbyname(const char *name) {
777c478bd9Sstevel@tonic-gate 	struct net_data *net_data = init();
787c478bd9Sstevel@tonic-gate 
797c478bd9Sstevel@tonic-gate 	return (getnetbyname_p(name, net_data));
807c478bd9Sstevel@tonic-gate }
817c478bd9Sstevel@tonic-gate 
827c478bd9Sstevel@tonic-gate struct netent *
getnetbyaddr(unsigned long net,int type)837c478bd9Sstevel@tonic-gate getnetbyaddr(unsigned long net, int type) {
847c478bd9Sstevel@tonic-gate 	struct net_data *net_data = init();
857c478bd9Sstevel@tonic-gate 
867c478bd9Sstevel@tonic-gate 	return (getnetbyaddr_p(net, type, net_data));
877c478bd9Sstevel@tonic-gate }
887c478bd9Sstevel@tonic-gate 
897c478bd9Sstevel@tonic-gate void
setnetent(int stayopen)907c478bd9Sstevel@tonic-gate setnetent(int stayopen) {
917c478bd9Sstevel@tonic-gate 	struct net_data *net_data = init();
927c478bd9Sstevel@tonic-gate 
937c478bd9Sstevel@tonic-gate 	setnetent_p(stayopen, net_data);
947c478bd9Sstevel@tonic-gate }
957c478bd9Sstevel@tonic-gate 
967c478bd9Sstevel@tonic-gate 
977c478bd9Sstevel@tonic-gate void
endnetent()987c478bd9Sstevel@tonic-gate endnetent() {
997c478bd9Sstevel@tonic-gate 	struct net_data *net_data = init();
1007c478bd9Sstevel@tonic-gate 
1017c478bd9Sstevel@tonic-gate 	endnetent_p(net_data);
1027c478bd9Sstevel@tonic-gate }
1037c478bd9Sstevel@tonic-gate 
1047c478bd9Sstevel@tonic-gate /* Shared private. */
1057c478bd9Sstevel@tonic-gate 
1067c478bd9Sstevel@tonic-gate struct netent *
getnetent_p(struct net_data * net_data)1077c478bd9Sstevel@tonic-gate getnetent_p(struct net_data *net_data) {
1087c478bd9Sstevel@tonic-gate 	struct irs_nw *nw;
1097c478bd9Sstevel@tonic-gate 
1107c478bd9Sstevel@tonic-gate 	if (!net_data || !(nw = net_data->nw))
1117c478bd9Sstevel@tonic-gate 		return (NULL);
1127c478bd9Sstevel@tonic-gate 	net_data->nww_last = (*nw->next)(nw);
1137c478bd9Sstevel@tonic-gate 	net_data->nw_last = nw_to_net(net_data->nww_last, net_data);
1147c478bd9Sstevel@tonic-gate 	return (net_data->nw_last);
1157c478bd9Sstevel@tonic-gate }
1167c478bd9Sstevel@tonic-gate 
1177c478bd9Sstevel@tonic-gate struct netent *
getnetbyname_p(const char * name,struct net_data * net_data)1187c478bd9Sstevel@tonic-gate getnetbyname_p(const char *name, struct net_data *net_data) {
1197c478bd9Sstevel@tonic-gate 	struct irs_nw *nw;
1207c478bd9Sstevel@tonic-gate 	struct netent *np;
1217c478bd9Sstevel@tonic-gate 	char **nap;
1227c478bd9Sstevel@tonic-gate 
1237c478bd9Sstevel@tonic-gate 	if (!net_data || !(nw = net_data->nw))
1247c478bd9Sstevel@tonic-gate 		return (NULL);
1257c478bd9Sstevel@tonic-gate 	if (net_data->nw_stayopen && net_data->nw_last) {
1267c478bd9Sstevel@tonic-gate 		if (!strcmp(net_data->nw_last->n_name, name))
1277c478bd9Sstevel@tonic-gate 			return (net_data->nw_last);
1287c478bd9Sstevel@tonic-gate 		for (nap = net_data->nw_last->n_aliases; nap && *nap; nap++)
1297c478bd9Sstevel@tonic-gate 			if (!strcmp(name, *nap))
1307c478bd9Sstevel@tonic-gate 				return (net_data->nw_last);
1317c478bd9Sstevel@tonic-gate 	}
1327c478bd9Sstevel@tonic-gate 	if ((np = fakeaddr(name, AF_INET, net_data)) != NULL)
1337c478bd9Sstevel@tonic-gate 		return (np);
1347c478bd9Sstevel@tonic-gate 	net_data->nww_last = (*nw->byname)(nw, name, AF_INET);
1357c478bd9Sstevel@tonic-gate 	net_data->nw_last = nw_to_net(net_data->nww_last, net_data);
1367c478bd9Sstevel@tonic-gate 	if (!net_data->nw_stayopen)
1377c478bd9Sstevel@tonic-gate 		endnetent();
1387c478bd9Sstevel@tonic-gate 	return (net_data->nw_last);
1397c478bd9Sstevel@tonic-gate }
1407c478bd9Sstevel@tonic-gate 
1417c478bd9Sstevel@tonic-gate struct netent *
getnetbyaddr_p(unsigned long net,int type,struct net_data * net_data)1427c478bd9Sstevel@tonic-gate getnetbyaddr_p(unsigned long net, int type, struct net_data *net_data) {
1437c478bd9Sstevel@tonic-gate 	struct irs_nw *nw;
1447c478bd9Sstevel@tonic-gate 	u_char addr[4];
1457c478bd9Sstevel@tonic-gate 	int bits;
1467c478bd9Sstevel@tonic-gate 
1477c478bd9Sstevel@tonic-gate 	if (!net_data || !(nw = net_data->nw))
1487c478bd9Sstevel@tonic-gate 		return (NULL);
1497c478bd9Sstevel@tonic-gate 	if (net_data->nw_stayopen && net_data->nw_last)
1507c478bd9Sstevel@tonic-gate 		if (type == net_data->nw_last->n_addrtype &&
1517c478bd9Sstevel@tonic-gate 		    net == net_data->nw_last->n_net)
1527c478bd9Sstevel@tonic-gate 			return (net_data->nw_last);
1537c478bd9Sstevel@tonic-gate 
1547c478bd9Sstevel@tonic-gate 	/* cannonize net(host order) */
1559525b14bSRao Shoaib 	if (net < 256UL) {
1567c478bd9Sstevel@tonic-gate 		net <<= 24;
1577c478bd9Sstevel@tonic-gate 		bits = 8;
1589525b14bSRao Shoaib 	} else if (net < 65536UL) {
1597c478bd9Sstevel@tonic-gate 		net <<= 16;
1607c478bd9Sstevel@tonic-gate 		bits = 16;
1619525b14bSRao Shoaib 	} else if (net < 16777216UL) {
1627c478bd9Sstevel@tonic-gate 		net <<= 8;
1637c478bd9Sstevel@tonic-gate 		bits = 24;
1647c478bd9Sstevel@tonic-gate 	} else
1657c478bd9Sstevel@tonic-gate 		bits = 32;
1667c478bd9Sstevel@tonic-gate 
1677c478bd9Sstevel@tonic-gate 	/* convert to net order */
1687c478bd9Sstevel@tonic-gate 	addr[0] = (0xFF000000 & net) >> 24;
1697c478bd9Sstevel@tonic-gate 	addr[1] = (0x00FF0000 & net) >> 16;
1707c478bd9Sstevel@tonic-gate 	addr[2] = (0x0000FF00 & net) >> 8;
1717c478bd9Sstevel@tonic-gate 	addr[3] = (0x000000FF & net);
1727c478bd9Sstevel@tonic-gate 
1737c478bd9Sstevel@tonic-gate 	/* reduce bits to as close to natural number as possible */
1747c478bd9Sstevel@tonic-gate 	if ((bits == 32) && (addr[0] < 224) && (addr[3] == 0)) {
1757c478bd9Sstevel@tonic-gate 		if ((addr[0] < 192) && (addr[2] == 0)) {
1767c478bd9Sstevel@tonic-gate 			if ((addr[0] < 128) && (addr[1] == 0))
1777c478bd9Sstevel@tonic-gate 				bits = 8;
1787c478bd9Sstevel@tonic-gate 			else
1797c478bd9Sstevel@tonic-gate 				bits = 16;
1807c478bd9Sstevel@tonic-gate 		} else {
1817c478bd9Sstevel@tonic-gate 			bits = 24;
1827c478bd9Sstevel@tonic-gate 		}
1837c478bd9Sstevel@tonic-gate 	}
1847c478bd9Sstevel@tonic-gate 
1857c478bd9Sstevel@tonic-gate 	net_data->nww_last = (*nw->byaddr)(nw, addr, bits, AF_INET);
1867c478bd9Sstevel@tonic-gate 	net_data->nw_last = nw_to_net(net_data->nww_last, net_data);
1877c478bd9Sstevel@tonic-gate 	if (!net_data->nw_stayopen)
1887c478bd9Sstevel@tonic-gate 		endnetent();
1897c478bd9Sstevel@tonic-gate 	return (net_data->nw_last);
1907c478bd9Sstevel@tonic-gate }
1917c478bd9Sstevel@tonic-gate 
1927c478bd9Sstevel@tonic-gate 
1937c478bd9Sstevel@tonic-gate 
1947c478bd9Sstevel@tonic-gate 
1957c478bd9Sstevel@tonic-gate void
setnetent_p(int stayopen,struct net_data * net_data)1967c478bd9Sstevel@tonic-gate setnetent_p(int stayopen, struct net_data *net_data) {
1977c478bd9Sstevel@tonic-gate 	struct irs_nw *nw;
1987c478bd9Sstevel@tonic-gate 
1997c478bd9Sstevel@tonic-gate 	if (!net_data || !(nw = net_data->nw))
2007c478bd9Sstevel@tonic-gate 		return;
2017c478bd9Sstevel@tonic-gate 	freepvt(net_data);
2027c478bd9Sstevel@tonic-gate 	(*nw->rewind)(nw);
2037c478bd9Sstevel@tonic-gate 	net_data->nw_stayopen = (stayopen != 0);
2047c478bd9Sstevel@tonic-gate 	if (stayopen == 0)
2057c478bd9Sstevel@tonic-gate 		net_data_minimize(net_data);
2067c478bd9Sstevel@tonic-gate }
2077c478bd9Sstevel@tonic-gate 
2087c478bd9Sstevel@tonic-gate void
endnetent_p(struct net_data * net_data)2097c478bd9Sstevel@tonic-gate endnetent_p(struct net_data *net_data) {
2107c478bd9Sstevel@tonic-gate 	struct irs_nw *nw;
2117c478bd9Sstevel@tonic-gate 
2127c478bd9Sstevel@tonic-gate 	if ((net_data != NULL) && ((nw	= net_data->nw) != NULL))
2137c478bd9Sstevel@tonic-gate 		(*nw->minimize)(nw);
2147c478bd9Sstevel@tonic-gate }
2157c478bd9Sstevel@tonic-gate 
2167c478bd9Sstevel@tonic-gate /* Private */
2177c478bd9Sstevel@tonic-gate 
2187c478bd9Sstevel@tonic-gate static struct net_data *
init()2197c478bd9Sstevel@tonic-gate init() {
2207c478bd9Sstevel@tonic-gate 	struct net_data *net_data;
2217c478bd9Sstevel@tonic-gate 
2227c478bd9Sstevel@tonic-gate 	if (!(net_data = net_data_init(NULL)))
2237c478bd9Sstevel@tonic-gate 		goto error;
2247c478bd9Sstevel@tonic-gate 	if (!net_data->nw) {
2257c478bd9Sstevel@tonic-gate 		net_data->nw = (*net_data->irs->nw_map)(net_data->irs);
2267c478bd9Sstevel@tonic-gate 
2277c478bd9Sstevel@tonic-gate 		if (!net_data->nw || !net_data->res) {
228*55fea89dSDan Cross  error:
2297c478bd9Sstevel@tonic-gate 			errno = EIO;
2307c478bd9Sstevel@tonic-gate 			return (NULL);
2317c478bd9Sstevel@tonic-gate 		}
2327c478bd9Sstevel@tonic-gate 		(*net_data->nw->res_set)(net_data->nw, net_data->res, NULL);
2337c478bd9Sstevel@tonic-gate 	}
234*55fea89dSDan Cross 
2357c478bd9Sstevel@tonic-gate 	return (net_data);
2367c478bd9Sstevel@tonic-gate }
2377c478bd9Sstevel@tonic-gate 
2387c478bd9Sstevel@tonic-gate static void
freepvt(struct net_data * net_data)2397c478bd9Sstevel@tonic-gate freepvt(struct net_data *net_data) {
2407c478bd9Sstevel@tonic-gate 	if (net_data->nw_data) {
2417c478bd9Sstevel@tonic-gate 		free(net_data->nw_data);
2427c478bd9Sstevel@tonic-gate 		net_data->nw_data = NULL;
2437c478bd9Sstevel@tonic-gate 	}
2447c478bd9Sstevel@tonic-gate }
2457c478bd9Sstevel@tonic-gate 
2467c478bd9Sstevel@tonic-gate static struct netent *
fakeaddr(const char * name,int af,struct net_data * net_data)2477c478bd9Sstevel@tonic-gate fakeaddr(const char *name, int af, struct net_data *net_data) {
2487c478bd9Sstevel@tonic-gate 	struct pvt *pvt;
2497c478bd9Sstevel@tonic-gate 	const char *cp;
2507c478bd9Sstevel@tonic-gate 	u_long tmp;
2517c478bd9Sstevel@tonic-gate 
2527c478bd9Sstevel@tonic-gate 	if (af != AF_INET) {
2537c478bd9Sstevel@tonic-gate 		/* XXX should support IPv6 some day */
2547c478bd9Sstevel@tonic-gate 		errno = EAFNOSUPPORT;
2557c478bd9Sstevel@tonic-gate 		RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
2567c478bd9Sstevel@tonic-gate 		return (NULL);
2577c478bd9Sstevel@tonic-gate 	}
2587c478bd9Sstevel@tonic-gate 	if (!isascii((unsigned char)(name[0])) ||
2597c478bd9Sstevel@tonic-gate 	    !isdigit((unsigned char)(name[0])))
2607c478bd9Sstevel@tonic-gate 		return (NULL);
2617c478bd9Sstevel@tonic-gate 	for (cp = name; *cp; ++cp)
2627c478bd9Sstevel@tonic-gate 		if (!isascii(*cp) || (!isdigit((unsigned char)*cp) && *cp != '.'))
2637c478bd9Sstevel@tonic-gate 			return (NULL);
2647c478bd9Sstevel@tonic-gate 	if (*--cp == '.')
2657c478bd9Sstevel@tonic-gate 		return (NULL);
2667c478bd9Sstevel@tonic-gate 
2677c478bd9Sstevel@tonic-gate 	/* All-numeric, no dot at the end. */
2687c478bd9Sstevel@tonic-gate 
2697c478bd9Sstevel@tonic-gate 	tmp = inet_network(name);
2707c478bd9Sstevel@tonic-gate 	if (tmp == INADDR_NONE) {
2717c478bd9Sstevel@tonic-gate 		RES_SET_H_ERRNO(net_data->res, HOST_NOT_FOUND);
2727c478bd9Sstevel@tonic-gate 		return (NULL);
2737c478bd9Sstevel@tonic-gate 	}
2747c478bd9Sstevel@tonic-gate 
2757c478bd9Sstevel@tonic-gate 	/* Valid network number specified.
2767c478bd9Sstevel@tonic-gate 	 * Fake up a netent as if we'd actually
2777c478bd9Sstevel@tonic-gate 	 * done a lookup.
2787c478bd9Sstevel@tonic-gate 	 */
2797c478bd9Sstevel@tonic-gate 	freepvt(net_data);
2807c478bd9Sstevel@tonic-gate 	net_data->nw_data = malloc(sizeof (struct pvt));
2817c478bd9Sstevel@tonic-gate 	if (!net_data->nw_data) {
2827c478bd9Sstevel@tonic-gate 		errno = ENOMEM;
2837c478bd9Sstevel@tonic-gate 		RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
2847c478bd9Sstevel@tonic-gate 		return (NULL);
2857c478bd9Sstevel@tonic-gate 	}
2867c478bd9Sstevel@tonic-gate 	pvt = net_data->nw_data;
2877c478bd9Sstevel@tonic-gate 
2887c478bd9Sstevel@tonic-gate 	strncpy(pvt->name, name, MAXDNAME);
2897c478bd9Sstevel@tonic-gate 	pvt->name[MAXDNAME] = '\0';
2907c478bd9Sstevel@tonic-gate 	pvt->netent.n_name = pvt->name;
2917c478bd9Sstevel@tonic-gate 	pvt->netent.n_addrtype = AF_INET;
2927c478bd9Sstevel@tonic-gate 	pvt->netent.n_aliases = pvt->aliases;
2937c478bd9Sstevel@tonic-gate 	pvt->aliases[0] = NULL;
2947c478bd9Sstevel@tonic-gate 	pvt->netent.n_net = tmp;
2957c478bd9Sstevel@tonic-gate 
2967c478bd9Sstevel@tonic-gate 	return (&pvt->netent);
2977c478bd9Sstevel@tonic-gate }
2987c478bd9Sstevel@tonic-gate 
2997c478bd9Sstevel@tonic-gate static struct netent *
nw_to_net(struct nwent * nwent,struct net_data * net_data)3007c478bd9Sstevel@tonic-gate nw_to_net(struct nwent *nwent, struct net_data *net_data) {
3017c478bd9Sstevel@tonic-gate 	struct pvt *pvt;
3027c478bd9Sstevel@tonic-gate 	u_long addr = 0;
3037c478bd9Sstevel@tonic-gate 	int i;
3047c478bd9Sstevel@tonic-gate 	int msbyte;
3057c478bd9Sstevel@tonic-gate 
3067c478bd9Sstevel@tonic-gate 	if (!nwent || nwent->n_addrtype != AF_INET)
3077c478bd9Sstevel@tonic-gate 		return (NULL);
3087c478bd9Sstevel@tonic-gate 	freepvt(net_data);
3097c478bd9Sstevel@tonic-gate 	net_data->nw_data = malloc(sizeof (struct pvt));
3107c478bd9Sstevel@tonic-gate 	if (!net_data->nw_data) {
3117c478bd9Sstevel@tonic-gate 		errno = ENOMEM;
3127c478bd9Sstevel@tonic-gate 		RES_SET_H_ERRNO(net_data->res, NETDB_INTERNAL);
3137c478bd9Sstevel@tonic-gate 		return (NULL);
3147c478bd9Sstevel@tonic-gate 	}
3157c478bd9Sstevel@tonic-gate 	pvt = net_data->nw_data;
3167c478bd9Sstevel@tonic-gate 	pvt->netent.n_name = nwent->n_name;
3177c478bd9Sstevel@tonic-gate 	pvt->netent.n_aliases = nwent->n_aliases;
3187c478bd9Sstevel@tonic-gate 	pvt->netent.n_addrtype = nwent->n_addrtype;
3197c478bd9Sstevel@tonic-gate 
3209525b14bSRao Shoaib /*%
3217c478bd9Sstevel@tonic-gate  * What this code does: Converts net addresses from network to host form.
3227c478bd9Sstevel@tonic-gate  *
3237c478bd9Sstevel@tonic-gate  * msbyte: the index of the most significant byte in the n_addr array.
3247c478bd9Sstevel@tonic-gate  *
3257c478bd9Sstevel@tonic-gate  * Shift bytes in significant order into addr. When all signicant
3267c478bd9Sstevel@tonic-gate  * bytes are in, zero out bits in the LSB that are not part of the network.
3277c478bd9Sstevel@tonic-gate  */
3287c478bd9Sstevel@tonic-gate 	msbyte = nwent->n_length / 8 +
3297c478bd9Sstevel@tonic-gate 		((nwent->n_length % 8) != 0 ? 1 : 0) - 1;
3307c478bd9Sstevel@tonic-gate 	for (i = 0; i <= msbyte; i++)
3317c478bd9Sstevel@tonic-gate 		addr = (addr << 8) | ((unsigned char *)nwent->n_addr)[i];
3327c478bd9Sstevel@tonic-gate 	i = (32 - nwent->n_length) % 8;
3337c478bd9Sstevel@tonic-gate 	if (i != 0)
3347c478bd9Sstevel@tonic-gate 		addr &= ~((1 << (i + 1)) - 1);
3357c478bd9Sstevel@tonic-gate 	pvt->netent.n_net = addr;
3367c478bd9Sstevel@tonic-gate 	return (&pvt->netent);
3377c478bd9Sstevel@tonic-gate }
3387c478bd9Sstevel@tonic-gate 
3397c478bd9Sstevel@tonic-gate #endif /*__BIND_NOSTATIC*/
3409525b14bSRao Shoaib 
3419525b14bSRao Shoaib /*! \file */
342