diff options
Diffstat (limited to '')
| -rw-r--r-- | src/lib/libc/net/ntohl.c | 29 |
1 files changed, 29 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..05b7f4c9a3 --- /dev/null +++ b/src/lib/libc/net/ntohl.c | |||
| @@ -0,0 +1,29 @@ | |||
| 1 | /* $NetBSD: ntohl.c,v 1.5 1995/04/28 23:25:21 jtc Exp $ */ | ||
| 2 | |||
| 3 | /* | ||
| 4 | * Written by J.T. Conklin <jtc@netbsd.org>. | ||
| 5 | * Public domain. | ||
| 6 | */ | ||
| 7 | |||
| 8 | #if defined(LIBC_SCCS) && !defined(lint) | ||
| 9 | static char *rcsid = "$NetBSD: ntohl.c,v 1.5 1995/04/28 23:25:21 jtc Exp $"; | ||
| 10 | #endif | ||
| 11 | |||
| 12 | #include <sys/types.h> | ||
| 13 | #include <machine/endian.h> | ||
| 14 | |||
| 15 | #undef ntohl | ||
| 16 | |||
| 17 | unsigned long | ||
| 18 | ntohl(x) | ||
| 19 | unsigned long x; | ||
| 20 | { | ||
| 21 | u_int32_t y = x; | ||
| 22 | |||
| 23 | #if BYTE_ORDER == LITTLE_ENDIAN | ||
| 24 | u_char *s = (u_char *)&y; | ||
| 25 | return s[0] << 24 | s[1] << 16 | s[2] << 8 | s[3]; | ||
| 26 | #else | ||
| 27 | return y; | ||
| 28 | #endif | ||
| 29 | } | ||
