inet_makeaddr.c (7c478bd9) inet_makeaddr.c (9525b14b)
1/*
1/*
2 * Copyright (c) 1997-2001 by Sun Microsystems, Inc.
3 * All rights reserved.
4 */
5
6/*
7 * Copyright (c) 1983, 1993
8 * The Regents of the University of California. All rights reserved.
9 *
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
12 * are met:
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.

--- 16 unchanged lines hidden (view full) ---

31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
36 * SUCH DAMAGE.
37 */
38
2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.

--- 16 unchanged lines hidden (view full) ---

26 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
27 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
28 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
29 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
30 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
31 * SUCH DAMAGE.
32 */
33
39#pragma ident "%Z%%M% %I% %E% SMI"
40
41#if defined(LIBC_SCCS) && !defined(lint)
42static const char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93";
43#endif /* LIBC_SCCS and not lint */
44
45#include "port_before.h"
46
47#include <sys/param.h>
48#include <netinet/in.h>
49#include <arpa/inet.h>
50
51#include "port_after.h"
52
34#if defined(LIBC_SCCS) && !defined(lint)
35static const char sccsid[] = "@(#)inet_makeaddr.c 8.1 (Berkeley) 6/4/93";
36#endif /* LIBC_SCCS and not lint */
37
38#include "port_before.h"
39
40#include <sys/param.h>
41#include <netinet/in.h>
42#include <arpa/inet.h>
43
44#include "port_after.h"
45
53/*
46/*%
54 * Formulate an Internet address from network + host. Used in
55 * building addresses stored in the ifnet structure.
56 */
57struct in_addr
58inet_makeaddr(net, host)
47 * Formulate an Internet address from network + host. Used in
48 * building addresses stored in the ifnet structure.
49 */
50struct in_addr
51inet_makeaddr(net, host)
59#ifdef ORIGINAL_ISC_CODE
60 u_long net, host;
52 u_long net, host;
61#else
62 in_addr_t net, host;
63#endif
64{
53{
65#ifdef ORIGINAL_ISC_CODE
66 u_long addr;
67#else
68 in_addr_t addr;
69 struct in_addr inaddr;
70#endif
54 struct in_addr a;
71
55
72 if (net < 128)
73 addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
74 else if (net < 65536)
75 addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
56 if (net < 128U)
57 a.s_addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
58 else if (net < 65536U)
59 a.s_addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
76 else if (net < 16777216L)
60 else if (net < 16777216L)
77 addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
61 a.s_addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
78 else
62 else
79 addr = net | host;
80#ifdef ORIGINAL_ISC_CODE
81 addr = htonl(addr);
82 return (*(struct in_addr *)&addr);
83#else
84 inaddr.s_addr = htonl(addr);
85 return (inaddr);
86#endif
63 a.s_addr = net | host;
64 a.s_addr = htonl(a.s_addr);
65 return (a);
87}
66}
67
68/*! \file */