xref: /original-bsd/lib/libc/net/inet_netof.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)inet_netof.c	8.1 (Berkeley) 06/04/93";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/param.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 
16 /*
17  * Return the network number from an internet
18  * address; handles class a/b/c network #'s.
19  */
20 u_long
21 inet_netof(in)
22 	struct in_addr in;
23 {
24 	register u_long i = ntohl(in.s_addr);
25 
26 	if (IN_CLASSA(i))
27 		return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
28 	else if (IN_CLASSB(i))
29 		return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
30 	else
31 		return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
32 }
33