xref: /csrg-svn/lib/libc/net/inet_netof.c (revision 61150)
121369Sdist /*
2*61150Sbostic  * Copyright (c) 1983, 1993
3*61150Sbostic  *	The Regents of the University of California.  All rights reserved.
433676Sbostic  *
542626Sbostic  * %sccs.include.redist.c%
621369Sdist  */
78360Ssam 
826614Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*61150Sbostic static char sccsid[] = "@(#)inet_netof.c	8.1 (Berkeley) 06/04/93";
1033676Sbostic #endif /* LIBC_SCCS and not lint */
1121369Sdist 
1246604Sbostic #include <sys/param.h>
139192Ssam #include <netinet/in.h>
1446604Sbostic #include <arpa/inet.h>
158360Ssam 
168360Ssam /*
178360Ssam  * Return the network number from an internet
188360Ssam  * address; handles class a/b/c network #'s.
198360Ssam  */
2032317Sbostic u_long
inet_netof(in)218370Ssam inet_netof(in)
228360Ssam 	struct in_addr in;
238360Ssam {
249192Ssam 	register u_long i = ntohl(in.s_addr);
258360Ssam 
269192Ssam 	if (IN_CLASSA(i))
279192Ssam 		return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
289192Ssam 	else if (IN_CLASSB(i))
299192Ssam 		return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
309192Ssam 	else
319192Ssam 		return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
328360Ssam }
33