xref: /openbsd-src/lib/libc/net/ntohl.c (revision e9b2b68ca3a6cce2632b4a73cc801bbb6f19c001)
1 /*
2  * Written by J.T. Conklin <jtc@netbsd.org>.
3  * Public domain.
4  */
5 
6 #if defined(LIBC_SCCS) && !defined(lint)
7 static char *rcsid = "$OpenBSD: ntohl.c,v 1.3 1996/08/19 08:29:33 tholo Exp $";
8 #endif /* LIBC_SCCS and not lint */
9 
10 #include <sys/types.h>
11 #include <machine/endian.h>
12 
13 #undef ntohl
14 
15 unsigned long
16 ntohl(x)
17 	unsigned long x;
18 {
19 	u_int32_t y = x;
20 
21 #if BYTE_ORDER == LITTLE_ENDIAN
22 	u_char *s = (u_char *)&y;
23 	return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
24 #else
25 	return y;
26 #endif
27 }
28