xref: /netbsd/lib/libc/inet/inet_lnaof.c (revision 3fa54233)
1*3fa54233Schristos /*	$NetBSD: inet_lnaof.c,v 1.1 2004/05/20 23:13:02 christos Exp $	*/
2*3fa54233Schristos 
3*3fa54233Schristos /*
4*3fa54233Schristos  * Copyright (c) 1983, 1993
5*3fa54233Schristos  *	The Regents of the University of California.  All rights reserved.
6*3fa54233Schristos  *
7*3fa54233Schristos  * Redistribution and use in source and binary forms, with or without
8*3fa54233Schristos  * modification, are permitted provided that the following conditions
9*3fa54233Schristos  * are met:
10*3fa54233Schristos  * 1. Redistributions of source code must retain the above copyright
11*3fa54233Schristos  *    notice, this list of conditions and the following disclaimer.
12*3fa54233Schristos  * 2. Redistributions in binary form must reproduce the above copyright
13*3fa54233Schristos  *    notice, this list of conditions and the following disclaimer in the
14*3fa54233Schristos  *    documentation and/or other materials provided with the distribution.
15*3fa54233Schristos  * 3. Neither the name of the University nor the names of its contributors
16*3fa54233Schristos  *    may be used to endorse or promote products derived from this software
17*3fa54233Schristos  *    without specific prior written permission.
18*3fa54233Schristos  *
19*3fa54233Schristos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20*3fa54233Schristos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21*3fa54233Schristos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22*3fa54233Schristos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23*3fa54233Schristos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24*3fa54233Schristos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25*3fa54233Schristos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26*3fa54233Schristos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27*3fa54233Schristos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28*3fa54233Schristos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29*3fa54233Schristos  * SUCH DAMAGE.
30*3fa54233Schristos  */
31*3fa54233Schristos 
32*3fa54233Schristos #include <sys/cdefs.h>
33*3fa54233Schristos #if defined(LIBC_SCCS) && !defined(lint)
34*3fa54233Schristos #if 0
35*3fa54233Schristos static char sccsid[] = "@(#)inet_lnaof.c	8.1 (Berkeley) 6/4/93";
36*3fa54233Schristos #else
37*3fa54233Schristos __RCSID("$NetBSD: inet_lnaof.c,v 1.1 2004/05/20 23:13:02 christos Exp $");
38*3fa54233Schristos #endif
39*3fa54233Schristos #endif /* LIBC_SCCS and not lint */
40*3fa54233Schristos 
41*3fa54233Schristos #include "namespace.h"
42*3fa54233Schristos #include <sys/param.h>
43*3fa54233Schristos #include <netinet/in.h>
44*3fa54233Schristos #include <arpa/inet.h>
45*3fa54233Schristos 
46*3fa54233Schristos #ifdef __weak_alias
__weak_alias(inet_lnaof,_inet_lnaof)47*3fa54233Schristos __weak_alias(inet_lnaof,_inet_lnaof)
48*3fa54233Schristos #endif
49*3fa54233Schristos 
50*3fa54233Schristos /*
51*3fa54233Schristos  * Return the local network address portion of an
52*3fa54233Schristos  * internet address; handles class a/b/c network
53*3fa54233Schristos  * number formats.
54*3fa54233Schristos  */
55*3fa54233Schristos in_addr_t
56*3fa54233Schristos inet_lnaof(struct in_addr in)
57*3fa54233Schristos {
58*3fa54233Schristos 	in_addr_t i = ntohl(in.s_addr);
59*3fa54233Schristos 
60*3fa54233Schristos 	if (IN_CLASSA(i))
61*3fa54233Schristos 		return ((i)&IN_CLASSA_HOST);
62*3fa54233Schristos 	else if (IN_CLASSB(i))
63*3fa54233Schristos 		return ((i)&IN_CLASSB_HOST);
64*3fa54233Schristos 	else
65*3fa54233Schristos 		return ((i)&IN_CLASSC_HOST);
66*3fa54233Schristos }
67