xref: /netbsd-src/common/lib/libc/net/ntohl.c (revision 2fa47ecfcb23a9fa15f2448c2ad113946a4b0bf9)
1*2fa47ecfShe /*	$NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $	*/
237c9f0a6Schristos 
337c9f0a6Schristos /*
437c9f0a6Schristos  * Written by J.T. Conklin <jtc@NetBSD.org>.
537c9f0a6Schristos  * Public domain.
637c9f0a6Schristos  */
737c9f0a6Schristos 
837c9f0a6Schristos #include <sys/cdefs.h>
937c9f0a6Schristos #if defined(LIBC_SCCS) && !defined(lint)
10*2fa47ecfShe __RCSID("$NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $");
1137c9f0a6Schristos #endif
1237c9f0a6Schristos 
1337c9f0a6Schristos #include <sys/types.h>
1437c9f0a6Schristos 
1537c9f0a6Schristos #undef ntohl
1637c9f0a6Schristos 
1737c9f0a6Schristos uint32_t
ntohl(uint32_t x)18b45fa494Sjoerg ntohl(uint32_t x)
1937c9f0a6Schristos {
2037c9f0a6Schristos #if BYTE_ORDER == LITTLE_ENDIAN
21*2fa47ecfShe 	u_char *s = (void *)&x;
2237c9f0a6Schristos 	return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
2337c9f0a6Schristos #else
2437c9f0a6Schristos 	return x;
2537c9f0a6Schristos #endif
2637c9f0a6Schristos }
27