xref: /csrg-svn/lib/libc/net/inet_makeaddr.c (revision 36232)
126818Skarels /*
226818Skarels  * Copyright (c) 1983 Regents of the University of California.
333676Sbostic  * All rights reserved.
433676Sbostic  *
533676Sbostic  * Redistribution and use in source and binary forms are permitted
634832Sbostic  * provided that the above copyright notice and this paragraph are
734832Sbostic  * duplicated in all such forms and that any documentation,
834832Sbostic  * advertising materials, and other materials related to such
934832Sbostic  * distribution and use acknowledge that the software was developed
1034832Sbostic  * by the University of California, Berkeley.  The name of the
1134832Sbostic  * University may not be used to endorse or promote products derived
1234832Sbostic  * from this software without specific prior written permission.
1334832Sbostic  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
1434832Sbostic  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
1534832Sbostic  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
1626818Skarels  */
178359Ssam 
1826818Skarels #if defined(LIBC_SCCS) && !defined(lint)
19*36232Ssklower static char sccsid[] = "@(#)inet_makeaddr.c	5.4 (Berkeley) 11/17/88";
2033676Sbostic #endif /* LIBC_SCCS and not lint */
2126818Skarels 
228359Ssam #include <sys/types.h>
239192Ssam #include <netinet/in.h>
248359Ssam 
258359Ssam /*
268359Ssam  * Formulate an Internet address from network + host.  Used in
278359Ssam  * building addresses stored in the ifnet structure.
288359Ssam  */
298359Ssam struct in_addr
308370Ssam inet_makeaddr(net, host)
31*36232Ssklower 	u_long net, host;
328359Ssam {
338359Ssam 	u_long addr;
348359Ssam 
358359Ssam 	if (net < 128)
3621762Skarels 		addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST);
378359Ssam 	else if (net < 65536)
3821762Skarels 		addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST);
39*36232Ssklower 	else if (net < 16777216L)
40*36232Ssklower 		addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST);
418359Ssam 	else
42*36232Ssklower 		addr = net | host;
438359Ssam 	addr = htonl(addr);
448359Ssam 	return (*(struct in_addr *)&addr);
458359Ssam }
46