diff options
Diffstat (limited to 'src/lib/libc/net/ntohl.c')
| -rw-r--r-- | src/lib/libc/net/ntohl.c | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/src/lib/libc/net/ntohl.c b/src/lib/libc/net/ntohl.c new file mode 100644 index 0000000000..36414b7a13 --- /dev/null +++ b/src/lib/libc/net/ntohl.c | |||
| @@ -0,0 +1,21 @@ | |||
| 1 | /* $OpenBSD: ntohl.c,v 1.6 2005/08/06 20:30:03 espie Exp $ */ | ||
| 2 | /* | ||
| 3 | * Written by J.T. Conklin <jtc@netbsd.org>. | ||
| 4 | * Public domain. | ||
| 5 | */ | ||
| 6 | |||
| 7 | #include <sys/types.h> | ||
| 8 | #include <machine/endian.h> | ||
| 9 | |||
| 10 | #undef ntohl | ||
| 11 | |||
| 12 | u_int32_t | ||
| 13 | ntohl(u_int32_t x) | ||
| 14 | { | ||
| 15 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
| 16 | u_char *s = (u_char *)&x; | ||
| 17 | return (u_int32_t)(s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]); | ||
| 18 | #else | ||
| 19 | return x; | ||
| 20 | #endif | ||
| 21 | } | ||
