date and time created 91/04/15 11:47:09 by donn
[unix-history] / usr / src / lib / libc / net / inet_makeaddr.c
CommitLineData
5b25cd8a
MK
1/*
2 * Copyright (c) 1983 Regents of the University of California.
140b4f5f
KB
3 * All rights reserved.
4 *
269a7923 5 * %sccs.include.redist.c%
5b25cd8a
MK
6 */
7
8#if defined(LIBC_SCCS) && !defined(lint)
24fac7d8 9static char sccsid[] = "@(#)inet_makeaddr.c 5.6 (Berkeley) %G%";
140b4f5f 10#endif /* LIBC_SCCS and not lint */
9b8667c0 11
24fac7d8 12#include <sys/param.h>
056d5bbd 13#include <netinet/in.h>
24fac7d8 14#include <arpa/inet.h>
9b8667c0
SL
15
16/*
17 * Formulate an Internet address from network + host. Used in
18 * building addresses stored in the ifnet structure.
19 */
20struct in_addr
3a3b7ace 21inet_makeaddr(net, host)
b8fb3ea1 22 u_long net, host;
9b8667c0
SL
23{
24 u_long addr;
25
26 if (net < 128)
4efde109 27 addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
9b8667c0 28 else if (net < 65536)
4efde109 29 addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
b8fb3ea1 30 else if (net < 16777216L)
4efde109 31 addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
b8fb3ea1
KS
32 else
33 addr = net | host;
9b8667c0
SL
34 addr = htonl(addr);
35 return (*(struct in_addr *)&addr);
36}