xref: /csrg-svn/lib/libc/net/inet_netof.c (revision 21369)
1*21369Sdist /*
2*21369Sdist  * Copyright (c) 1983 Regents of the University of California.
3*21369Sdist  * All rights reserved.  The Berkeley software License Agreement
4*21369Sdist  * specifies the terms and conditions for redistribution.
5*21369Sdist  */
68360Ssam 
7*21369Sdist #ifndef lint
8*21369Sdist static char sccsid[] = "@(#)inet_netof.c	5.1 (Berkeley) 05/30/85";
9*21369Sdist #endif not lint
10*21369Sdist 
118360Ssam #include <sys/types.h>
129192Ssam #include <netinet/in.h>
138360Ssam 
148360Ssam /*
158360Ssam  * Return the network number from an internet
168360Ssam  * address; handles class a/b/c network #'s.
178360Ssam  */
188370Ssam inet_netof(in)
198360Ssam 	struct in_addr in;
208360Ssam {
219192Ssam 	register u_long i = ntohl(in.s_addr);
228360Ssam 
239192Ssam 	if (IN_CLASSA(i))
249192Ssam 		return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
259192Ssam 	else if (IN_CLASSB(i))
269192Ssam 		return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
279192Ssam 	else
289192Ssam 		return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
298360Ssam }
30