1 /* 2 * Copyright (c) 1983 Regents of the University of California. 3 * All rights reserved. 4 * 5 * Redistribution and use in source and binary forms are permitted 6 * provided that this notice is preserved and that due credit is given 7 * to the University of California at Berkeley. The name of the University 8 * may not be used to endorse or promote products derived from this 9 * software without specific prior written permission. This software 10 * is provided ``as is'' without express or implied warranty. 11 */ 12 13 #if defined(LIBC_SCCS) && !defined(lint) 14 static char sccsid[] = "@(#)inet_makeaddr.c 5.2 (Berkeley) 03/07/88"; 15 #endif /* LIBC_SCCS and not lint */ 16 17 #include <sys/types.h> 18 #include <netinet/in.h> 19 20 /* 21 * Formulate an Internet address from network + host. Used in 22 * building addresses stored in the ifnet structure. 23 */ 24 struct in_addr 25 inet_makeaddr(net, host) 26 int net, host; 27 { 28 u_long addr; 29 30 if (net < 128) 31 addr = (net << IN_CLASSA_NSHIFT) | (host & IN_CLASSA_HOST); 32 else if (net < 65536) 33 addr = (net << IN_CLASSB_NSHIFT) | (host & IN_CLASSB_HOST); 34 else 35 addr = (net << IN_CLASSC_NSHIFT) | (host & IN_CLASSC_HOST); 36 addr = htonl(addr); 37 return (*(struct in_addr *)&addr); 38 } 39