121369Sdist /* 221369Sdist * Copyright (c) 1983 Regents of the University of California. 3*33676Sbostic * All rights reserved. 4*33676Sbostic * 5*33676Sbostic * Redistribution and use in source and binary forms are permitted 6*33676Sbostic * provided that this notice is preserved and that due credit is given 7*33676Sbostic * to the University of California at Berkeley. The name of the University 8*33676Sbostic * may not be used to endorse or promote products derived from this 9*33676Sbostic * software without specific prior written permission. This software 10*33676Sbostic * is provided ``as is'' without express or implied warranty. 1121369Sdist */ 128360Ssam 1326614Sdonn #if defined(LIBC_SCCS) && !defined(lint) 14*33676Sbostic static char sccsid[] = "@(#)inet_netof.c 5.4 (Berkeley) 03/07/88"; 15*33676Sbostic #endif /* LIBC_SCCS and not lint */ 1621369Sdist 178360Ssam #include <sys/types.h> 189192Ssam #include <netinet/in.h> 198360Ssam 208360Ssam /* 218360Ssam * Return the network number from an internet 228360Ssam * address; handles class a/b/c network #'s. 238360Ssam */ 2432317Sbostic u_long 258370Ssam inet_netof(in) 268360Ssam struct in_addr in; 278360Ssam { 289192Ssam register u_long i = ntohl(in.s_addr); 298360Ssam 309192Ssam if (IN_CLASSA(i)) 319192Ssam return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); 329192Ssam else if (IN_CLASSB(i)) 339192Ssam return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); 349192Ssam else 359192Ssam return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); 368360Ssam } 37