xref: /netbsd-src/common/lib/libc/net/ntohl.c (revision 9ddb6ab554e70fb9bbd90c3d96b812bc57755a14)
1 /*	$NetBSD: ntohl.c,v 1.2 2011/07/04 21:29:16 joerg Exp $	*/
2 
3 /*
4  * Written by J.T. Conklin <jtc@NetBSD.org>.
5  * Public domain.
6  */
7 
8 #include <sys/cdefs.h>
9 #if defined(LIBC_SCCS) && !defined(lint)
10 __RCSID("$NetBSD: ntohl.c,v 1.2 2011/07/04 21:29:16 joerg Exp $");
11 #endif
12 
13 #include <sys/types.h>
14 
15 #undef ntohl
16 
17 uint32_t
18 ntohl(uint32_t x)
19 {
20 #if BYTE_ORDER == LITTLE_ENDIAN
21 	u_char *s = (u_char *)&x;
22 	return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
23 #else
24 	return x;
25 #endif
26 }
27