xref: /csrg-svn/lib/libc/net/inet_netof.c (revision 42626)
121369Sdist /*
221369Sdist  * Copyright (c) 1983 Regents of the University of California.
333676Sbostic  * All rights reserved.
433676Sbostic  *
5*42626Sbostic  * %sccs.include.redist.c%
621369Sdist  */
78360Ssam 
826614Sdonn #if defined(LIBC_SCCS) && !defined(lint)
9*42626Sbostic static char sccsid[] = "@(#)inet_netof.c	5.6 (Berkeley) 06/01/90";
1033676Sbostic #endif /* LIBC_SCCS and not lint */
1121369Sdist 
128360Ssam #include <sys/types.h>
139192Ssam #include <netinet/in.h>
148360Ssam 
158360Ssam /*
168360Ssam  * Return the network number from an internet
178360Ssam  * address; handles class a/b/c network #'s.
188360Ssam  */
1932317Sbostic u_long
208370Ssam inet_netof(in)
218360Ssam 	struct in_addr in;
228360Ssam {
239192Ssam 	register u_long i = ntohl(in.s_addr);
248360Ssam 
259192Ssam 	if (IN_CLASSA(i))
269192Ssam 		return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
279192Ssam 	else if (IN_CLASSB(i))
289192Ssam 		return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
299192Ssam 	else
309192Ssam 		return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
318360Ssam }
32