xref: /original-bsd/lib/libc/net/inet_makeaddr.c (revision 5e36add1)
1 /*
2  * Copyright (c) 1983 Regents of the University of California.
3  * 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	5.5 (Berkeley) 06/01/90";
10 #endif /* LIBC_SCCS and not lint */
11 
12 #include <sys/types.h>
13 #include <netinet/in.h>
14 
15 /*
16  * Formulate an Internet address from network + host.  Used in
17  * building addresses stored in the ifnet structure.
18  */
19 struct in_addr
20 inet_makeaddr(net, host)
21 	u_long net, host;
22 {
23 	u_long addr;
24 
25 	if (net < 128)
26 		addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
27 	else if (net < 65536)
28 		addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
29 	else if (net < 16777216L)
30 		addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
31 	else
32 		addr = net | host;
33 	addr = htonl(addr);
34 	return (*(struct in_addr *)&addr);
35 }
36