xref: /csrg-svn/lib/libc/net/inet_netof.c (revision 32317)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * All rights reserved.  The Berkeley software License Agreement
4  * specifies the terms and conditions for redistribution.
5  */
6 
7 #if defined(LIBC_SCCS) && !defined(lint)
8 static char sccsid[] = "@(#)inet_netof.c	5.3 (Berkeley) 10/01/87";
9 #endif LIBC_SCCS and not lint
10 
11 #include <sys/types.h>
12 #include <netinet/in.h>
13 
14 /*
15  * Return the network number from an internet
16  * address; handles class a/b/c network #'s.
17  */
18 u_long
19 inet_netof(in)
20 	struct in_addr in;
21 {
22 	register u_long i = ntohl(in.s_addr);
23 
24 	if (IN_CLASSA(i))
25 		return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT);
26 	else if (IN_CLASSB(i))
27 		return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT);
28 	else
29 		return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT);
30 }
31