xref: /original-bsd/lib/libc/net/inet_makeaddr.c (revision c3e32dec)
1 /*
2  * Copyright (c) 1983, 1993
3  *	The Regents of the University of California.  All rights reserved.
4  *
5  * %sccs.include.redist.c%
6  */
7 
8 #if defined(LIBC_SCCS) && !defined(lint)
9 static char sccsid[] = "@(#)inet_makeaddr.c	8.1 (Berkeley) 06/04/93";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/param.h>
13 #include <netinet/in.h>
14 #include <arpa/inet.h>
15 
16 /*
17  * Formulate an Internet address from network + host.  Used in
18  * building addresses stored in the ifnet structure.
19  */
20 struct in_addr
21 inet_makeaddr(net, host)
22 	u_long net, host;
23 {
24 	u_long addr;
25 
26 	if (net < 128)
27 		addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
28 	else if (net < 65536)
29 		addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
30 	else if (net < 16777216L)
31 		addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
32 	else
33 		addr = net | host;
34 	addr = htonl(addr);
35 	return (*(struct in_addr *)&addr);
36 }
37