1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #if defined(LIBC_SCCS) && !defined(lint) 14 static char sccsid[] = "@(#)inet_netof.c 5.4 (Berkeley) 03/07/88"; 15 #endif /* LIBC_SCCS and not lint */ 16 17 #include <sys/types.h> 18 #include <netinet/in.h> 19 20 /* 21 * Return the network number from an internet 22 * address; handles class a/b/c network #'s. 23 */ 24 u_long 25 inet_netof(in) 26 struct in_addr in; 27 { 28 register u_long i = ntohl(in.s_addr); 29 30 if (IN_CLASSA(i)) 31 return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); 32 else if (IN_CLASSB(i)) 33 return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); 34 else 35 return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); 36 } 37