2012-11-15 12:06:41 +01:00
|
|
|
/* $NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $ */
|
2011-02-14 20:36:03 +01:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Written by J.T. Conklin <jtc@NetBSD.org>.
|
|
|
|
* Public domain.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include <sys/cdefs.h>
|
|
|
|
#if defined(LIBC_SCCS) && !defined(lint)
|
2012-11-15 12:06:41 +01:00
|
|
|
__RCSID("$NetBSD: ntohl.c,v 1.3 2012/03/21 20:02:56 he Exp $");
|
2011-02-14 20:36:03 +01:00
|
|
|
#endif
|
|
|
|
|
|
|
|
#include <sys/types.h>
|
|
|
|
|
|
|
|
#undef ntohl
|
|
|
|
|
|
|
|
uint32_t
|
2012-11-15 12:06:41 +01:00
|
|
|
ntohl(uint32_t x)
|
2011-02-14 20:36:03 +01:00
|
|
|
{
|
|
|
|
#if BYTE_ORDER == LITTLE_ENDIAN
|
2012-11-15 12:06:41 +01:00
|
|
|
u_char *s = (void *)&x;
|
2011-02-14 20:36:03 +01:00
|
|
|
return (uint32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]);
|
|
|
|
#else
|
|
|
|
return x;
|
|
|
|
#endif
|
|
|
|
}
|