summaryrefslogtreecommitdiffstats
path: root/sys/lib/libkern/htons.c
diff options
context:
space:
mode:
authorderaadt <deraadt@openbsd.org>1995-10-18 08:37:01 +0000
committerderaadt <deraadt@openbsd.org>1995-10-18 08:37:01 +0000
commitdf930be708d50e9715f173caa26ffe1b7599b157 (patch)
treeaa317e49e28cb999c9cf3db7f00c20903fe6010a /sys/lib/libkern/htons.c
downloadwireguard-openbsd-df930be708d50e9715f173caa26ffe1b7599b157.tar.xz
wireguard-openbsd-df930be708d50e9715f173caa26ffe1b7599b157.zip
initial import of NetBSD tree
Diffstat (limited to 'sys/lib/libkern/htons.c')
-rw-r--r--sys/lib/libkern/htons.c27
1 files changed, 27 insertions, 0 deletions
diff --git a/sys/lib/libkern/htons.c b/sys/lib/libkern/htons.c
new file mode 100644
index 00000000000..6d491588b59
--- /dev/null
+++ b/sys/lib/libkern/htons.c
@@ -0,0 +1,27 @@
+/* $NetBSD: htons.c,v 1.6 1995/10/07 09:26:27 mycroft Exp $ */
+
+/*
+ * Written by J.T. Conklin <jtc@netbsd.org>.
+ * Public domain.
+ */
+
+#if defined(LIBC_SCCS) && !defined(lint)
+static char *rcsid = "$NetBSD: htons.c,v 1.6 1995/10/07 09:26:27 mycroft Exp $";
+#endif
+
+#include <sys/types.h>
+#include <machine/endian.h>
+
+#undef htons
+
+unsigned short
+htons(x)
+ unsigned short x;
+{
+#if BYTE_ORDER == LITTLE_ENDIAN
+ u_char *s = (u_char *) &x;
+ return s[0] << 8 | s[1];
+#else
+ return x;
+#endif
+}