1156952Sume/* 2156952Sume * Copyright (c) 1983, 1993 3156952Sume * The Regents of the University of California. All rights reserved. 4156952Sume * 5156952Sume * Redistribution and use in source and binary forms, with or without 6156952Sume * modification, are permitted provided that the following conditions 7156952Sume * are met: 8156952Sume * 1. Redistributions of source code must retain the above copyright 9156952Sume * notice, this list of conditions and the following disclaimer. 10156952Sume * 2. Redistributions in binary form must reproduce the above copyright 11156952Sume * notice, this list of conditions and the following disclaimer in the 12156952Sume * documentation and/or other materials provided with the distribution. 13156952Sume * 4. Neither the name of the University nor the names of its contributors 14156952Sume * may be used to endorse or promote products derived from this software 15156952Sume * without specific prior written permission. 16156952Sume * 17156952Sume * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 18156952Sume * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 19156952Sume * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 20156952Sume * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 21156952Sume * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 22156952Sume * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 23156952Sume * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 24156952Sume * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 25156952Sume * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 26156952Sume * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 27156952Sume * SUCH DAMAGE. 28156952Sume */ 29156952Sume 30156952Sume#if defined(LIBC_SCCS) && !defined(lint) 31156952Sumestatic const char sccsid[] = "@(#)inet_netof.c 8.1 (Berkeley) 6/4/93"; 32156952Sume#endif /* LIBC_SCCS and not lint */ 33156956Sume#include <sys/cdefs.h> 34156956Sume__FBSDID("$FreeBSD$"); 35156952Sume 36156952Sume#include "port_before.h" 37156952Sume 38156952Sume#include <sys/param.h> 39156952Sume#include <netinet/in.h> 40156952Sume#include <arpa/inet.h> 41156952Sume 42156952Sume#include "port_after.h" 43156952Sume 44170244Sume/*% 45156952Sume * Return the network number from an internet 46156952Sume * address; handles class a/b/c network #'s. 47156952Sume */ 48156956Sumein_addr_t 49156952Sumeinet_netof(in) 50156952Sume struct in_addr in; 51156952Sume{ 52156956Sume in_addr_t i = ntohl(in.s_addr); 53156952Sume 54156952Sume if (IN_CLASSA(i)) 55156952Sume return (((i)&IN_CLASSA_NET) >> IN_CLASSA_NSHIFT); 56156952Sume else if (IN_CLASSB(i)) 57156952Sume return (((i)&IN_CLASSB_NET) >> IN_CLASSB_NSHIFT); 58156952Sume else 59156952Sume return (((i)&IN_CLASSC_NET) >> IN_CLASSC_NSHIFT); 60156952Sume} 61156956Sume 62156956Sume/* 63156956Sume * Weak aliases for applications that use certain private entry points, 64156956Sume * and fail to include <arpa/inet.h>. 65156956Sume */ 66156956Sume#undef inet_netof 67156956Sume__weak_reference(__inet_netof, inet_netof); 68170244Sume 69170244Sume/*! \file */ 70