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_makeaddr.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 * Formulate an Internet address from network + host.  Used in
46156952Sume * building addresses stored in the ifnet structure.
47156952Sume */
48156952Sumestruct in_addr
49156952Sumeinet_makeaddr(net, host)
50156956Sume	in_addr_t net, host;
51156952Sume{
52156952Sume	struct in_addr a;
53156952Sume
54156952Sume	if (net < 128U)
55156952Sume		a.s_addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
56156952Sume	else if (net < 65536U)
57156952Sume		a.s_addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
58156952Sume	else if (net < 16777216L)
59156952Sume		a.s_addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
60156952Sume	else
61156952Sume		a.s_addr = net | host;
62156952Sume	a.s_addr = htonl(a.s_addr);
63156952Sume	return (a);
64156952Sume}
65156956Sume
66156956Sume/*
67156956Sume * Weak aliases for applications that use certain private entry points,
68156956Sume * and fail to include <arpa/inet.h>.
69156956Sume */
70156956Sume#undef inet_makeaddr
71156956Sume__weak_reference(__inet_makeaddr, inet_makeaddr);
72170244Sume
73170244Sume/*! \file */
74