The kernels endian handing is better than ours -- use the kernel.

diff --git a/arch/alpha/include/klibc/endian.h b/arch/alpha/include/klibc/endian.h
deleted file mode 100644
index 9aaeeb4..0000000
--- a/arch/alpha/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/alpha/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/arm/include/klibc/endian.h b/arch/arm/include/klibc/endian.h
deleted file mode 100644
index 647c1af..0000000
--- a/arch/arm/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/arm/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/i386/include/klibc/endian.h b/arch/i386/include/klibc/endian.h
deleted file mode 100644
index f7ab7a7..0000000
--- a/arch/i386/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/i386/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/ia64/include/klibc/endian.h b/arch/ia64/include/klibc/endian.h
deleted file mode 100644
index fc7a38c..0000000
--- a/arch/ia64/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ia64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/m68k/include/klibc/endian.h b/arch/m68k/include/klibc/endian.h
deleted file mode 100644
index 93735ca..0000000
--- a/arch/m68k/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/m68k/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/mips/include/klibc/endian.h b/arch/mips/include/klibc/endian.h
deleted file mode 100644
index 1097fe7..0000000
--- a/arch/mips/include/klibc/endian.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/mips/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#if defined(__MIPSEB__)
-# define __BYTE_ORDER __BIG_ENDIAN
-#elif defined(__MIPSEL__)
-# define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-# error "Neither __MIPSEB__ nor __MIPSEL__ defined"
-#endif
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/mips64/include/klibc/endian.h b/arch/mips64/include/klibc/endian.h
deleted file mode 100644
index ba46179..0000000
--- a/arch/mips64/include/klibc/endian.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/mips64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#if defined(__MIPSEB__)
-# define __BYTE_ORDER __BIG_ENDIAN
-#elif defined(__MIPSEL__)
-# define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-# error "Neither __MIPSEB__ nor __MIPSEL__ defined"
-#endif
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/parisc/include/klibc/endian.h b/arch/parisc/include/klibc/endian.h
deleted file mode 100644
index d849f72..0000000
--- a/arch/parisc/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/parisc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/ppc/include/klibc/endian.h b/arch/ppc/include/klibc/endian.h
deleted file mode 100644
index ba42645..0000000
--- a/arch/ppc/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ppc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/ppc64/include/klibc/endian.h b/arch/ppc64/include/klibc/endian.h
deleted file mode 100644
index eb18078..0000000
--- a/arch/ppc64/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ppc64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/s390/include/klibc/endian.h b/arch/s390/include/klibc/endian.h
deleted file mode 100644
index f30347a..0000000
--- a/arch/s390/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/s390/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/s390x/include/klibc/endian.h b/arch/s390x/include/klibc/endian.h
deleted file mode 100644
index 87218fd..0000000
--- a/arch/s390x/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/s390x/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/sparc/include/klibc/endian.h b/arch/sparc/include/klibc/endian.h
deleted file mode 100644
index 39c4897..0000000
--- a/arch/sparc/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/sparc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/arch/sparc64/include/klibc/endian.h b/arch/sparc64/include/klibc/endian.h
deleted file mode 100644
index 5c09982..0000000
--- a/arch/sparc64/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/sparc64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/alpha/klibc/endian.h b/include/arch/alpha/klibc/endian.h
deleted file mode 100644
index 9aaeeb4..0000000
--- a/include/arch/alpha/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/alpha/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/arm/klibc/endian.h b/include/arch/arm/klibc/endian.h
deleted file mode 100644
index 647c1af..0000000
--- a/include/arch/arm/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/arm/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/i386/klibc/endian.h b/include/arch/i386/klibc/endian.h
deleted file mode 100644
index f7ab7a7..0000000
--- a/include/arch/i386/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/i386/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/ia64/klibc/endian.h b/include/arch/ia64/klibc/endian.h
deleted file mode 100644
index fc7a38c..0000000
--- a/include/arch/ia64/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ia64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/m68k/klibc/endian.h b/include/arch/m68k/klibc/endian.h
deleted file mode 100644
index 93735ca..0000000
--- a/include/arch/m68k/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/m68k/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/mips/klibc/endian.h b/include/arch/mips/klibc/endian.h
deleted file mode 100644
index 1097fe7..0000000
--- a/include/arch/mips/klibc/endian.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/mips/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#if defined(__MIPSEB__)
-# define __BYTE_ORDER __BIG_ENDIAN
-#elif defined(__MIPSEL__)
-# define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-# error "Neither __MIPSEB__ nor __MIPSEL__ defined"
-#endif
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/mips64/klibc/endian.h b/include/arch/mips64/klibc/endian.h
deleted file mode 100644
index ba46179..0000000
--- a/include/arch/mips64/klibc/endian.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/mips64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#if defined(__MIPSEB__)
-# define __BYTE_ORDER __BIG_ENDIAN
-#elif defined(__MIPSEL__)
-# define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-# error "Neither __MIPSEB__ nor __MIPSEL__ defined"
-#endif
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/parisc/klibc/endian.h b/include/arch/parisc/klibc/endian.h
deleted file mode 100644
index d849f72..0000000
--- a/include/arch/parisc/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/parisc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/ppc/klibc/endian.h b/include/arch/ppc/klibc/endian.h
deleted file mode 100644
index ba42645..0000000
--- a/include/arch/ppc/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ppc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/ppc64/klibc/endian.h b/include/arch/ppc64/klibc/endian.h
deleted file mode 100644
index eb18078..0000000
--- a/include/arch/ppc64/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ppc64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/s390/klibc/endian.h b/include/arch/s390/klibc/endian.h
deleted file mode 100644
index f30347a..0000000
--- a/include/arch/s390/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/s390/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/s390x/klibc/endian.h b/include/arch/s390x/klibc/endian.h
deleted file mode 100644
index 87218fd..0000000
--- a/include/arch/s390x/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/s390x/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/sparc/klibc/endian.h b/include/arch/sparc/klibc/endian.h
deleted file mode 100644
index 39c4897..0000000
--- a/include/arch/sparc/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/sparc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/arch/sparc64/klibc/endian.h b/include/arch/sparc64/klibc/endian.h
deleted file mode 100644
index 5c09982..0000000
--- a/include/arch/sparc64/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/sparc64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/include/endian.h b/include/endian.h
index 7a3680d..348d659 100644
--- a/include/endian.h
+++ b/include/endian.h
@@ -5,11 +5,33 @@
 #ifndef _ENDIAN_H
 #define _ENDIAN_H
 
-#define __LITTLE_ENDIAN 1234
-#define __BIG_ENDIAN    4321
-#define __PDP_ENDIAN    3412
+#include <asm/byteorder.h>
 
-#include <klibc/endian.h>
+/* Linux' asm/byteorder.h defines either __LITTLE_ENDIAN or __BIG_ENDIAN,
+   but the BSD-ish macros expect both to be defined with __BYTE_ORDER
+   defining which is actually used... */
+
+#if defined(__LITTLE_ENDIAN)
+# undef  __LITTLE_ENDIAN
+# define __LITTLE_ENDIAN 1234
+# define __BIG_ENDIAN    4321
+# define __PDP_ENDIAN    3412
+# define __BYTE_ORDER    __LITTLE_ENDIAN
+#elif defined(__BIG_ENDIAN)
+# undef  __BIG_ENDIAN
+# define __LITTLE_ENDIAN 1234
+# define __BIG_ENDIAN    4321
+# define __PDP_ENDIAN    3412
+# define __BYTE_ORDER    __BIG_ENDIAN
+#elif defined(__PDP_ENDIAN)
+# undef  __PDP_ENDIAN
+# define __LITTLE_ENDIAN 1234
+# define __BIG_ENDIAN    4321
+# define __PDP_ENDIAN    3412
+# define __BYTE_ORDER    __PDP_ENDIAN
+#else
+# error "Unknown byte order!"
+#endif
 
 #define LITTLE_ENDIAN	__LITTLE_ENDIAN
 #define BIG_ENDIAN	__BIG_ENDIAN
diff --git a/include/netinet/in.h b/include/netinet/in.h
index c1f1c16..4b7e77e 100644
--- a/include/netinet/in.h
+++ b/include/netinet/in.h
@@ -8,38 +8,9 @@
 #include <stdint.h>
 #include <endian.h>
 
-#if __BYTE_ORDER == __BIG_ENDIAN
-
-#define htonl(x) ((uint32_t)(x))
-#define ntohl(x) ((uint32_t)(x))
-#define htons(x) ((uint16_t)(x))
-#define ntohs(x) ((uint16_t)(x))
-
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-
-static __inline__
-uint32_t htonl(uint32_t __x)
-{
-#if defined(__i486__)||defined(__pentium__)||defined(__pentiumpro__)
-  asm("bswap %0" : "+rm" (__x));
-  return __x;
-#else
-  return (__x >> 24) + ((__x >> 8) & 0xff00) +
-    ((__x & 0xff00) << 8) + (__x << 24);
-#endif
-}
-
-static __inline__
-uint16_t htons(uint16_t __x)
-{
-  return (__x >> 8) + (__x << 8);
-}
-
-#define htonl(x) htonl(x)
-#define ntohl(x) htohl(x)
-#define htons(x) htons(x)
-#define ntohs(x) htons(x)
-
-#endif /* endian */
+#define htons(x)	__cpu_to_be16(x)
+#define ntohs(x)	__be16_to_cpu(x)
+#define htonl(x)	__cpu_to_be32(x)
+#define ntohl(x)	__be32_to_cpu(x)
 
 #endif /* _NETINET_IN_H */
diff --git a/klibc/arch/alpha/include/klibc/endian.h b/klibc/arch/alpha/include/klibc/endian.h
deleted file mode 100644
index 9aaeeb4..0000000
--- a/klibc/arch/alpha/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/alpha/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/arm/include/klibc/endian.h b/klibc/arch/arm/include/klibc/endian.h
deleted file mode 100644
index 647c1af..0000000
--- a/klibc/arch/arm/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/arm/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/i386/include/klibc/endian.h b/klibc/arch/i386/include/klibc/endian.h
deleted file mode 100644
index f7ab7a7..0000000
--- a/klibc/arch/i386/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/i386/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/ia64/include/klibc/endian.h b/klibc/arch/ia64/include/klibc/endian.h
deleted file mode 100644
index fc7a38c..0000000
--- a/klibc/arch/ia64/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ia64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __LITTLE_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/m68k/include/klibc/endian.h b/klibc/arch/m68k/include/klibc/endian.h
deleted file mode 100644
index 93735ca..0000000
--- a/klibc/arch/m68k/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/m68k/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/mips/include/klibc/endian.h b/klibc/arch/mips/include/klibc/endian.h
deleted file mode 100644
index 1097fe7..0000000
--- a/klibc/arch/mips/include/klibc/endian.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/mips/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#if defined(__MIPSEB__)
-# define __BYTE_ORDER __BIG_ENDIAN
-#elif defined(__MIPSEL__)
-# define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-# error "Neither __MIPSEB__ nor __MIPSEL__ defined"
-#endif
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/mips64/include/klibc/endian.h b/klibc/arch/mips64/include/klibc/endian.h
deleted file mode 100644
index ba46179..0000000
--- a/klibc/arch/mips64/include/klibc/endian.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * arch/mips64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#if defined(__MIPSEB__)
-# define __BYTE_ORDER __BIG_ENDIAN
-#elif defined(__MIPSEL__)
-# define __BYTE_ORDER __LITTLE_ENDIAN
-#else
-# error "Neither __MIPSEB__ nor __MIPSEL__ defined"
-#endif
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/parisc/include/klibc/endian.h b/klibc/arch/parisc/include/klibc/endian.h
deleted file mode 100644
index d849f72..0000000
--- a/klibc/arch/parisc/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/parisc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/ppc/include/klibc/endian.h b/klibc/arch/ppc/include/klibc/endian.h
deleted file mode 100644
index ba42645..0000000
--- a/klibc/arch/ppc/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ppc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/ppc64/include/klibc/endian.h b/klibc/arch/ppc64/include/klibc/endian.h
deleted file mode 100644
index eb18078..0000000
--- a/klibc/arch/ppc64/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/ppc64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/s390/include/klibc/endian.h b/klibc/arch/s390/include/klibc/endian.h
deleted file mode 100644
index f30347a..0000000
--- a/klibc/arch/s390/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/s390/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/s390x/include/klibc/endian.h b/klibc/arch/s390x/include/klibc/endian.h
deleted file mode 100644
index 87218fd..0000000
--- a/klibc/arch/s390x/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/s390x/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/sparc/include/klibc/endian.h b/klibc/arch/sparc/include/klibc/endian.h
deleted file mode 100644
index 39c4897..0000000
--- a/klibc/arch/sparc/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/sparc/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/arch/sparc64/include/klibc/endian.h b/klibc/arch/sparc64/include/klibc/endian.h
deleted file mode 100644
index 5c09982..0000000
--- a/klibc/arch/sparc64/include/klibc/endian.h
+++ /dev/null
@@ -1,10 +0,0 @@
-/*
- * arch/sparc64/include/klibc/endian.h
- */
-
-#ifndef _KLIBC_ENDIAN_H
-#define _KLIBC_ENDIAN_H
-
-#define __BYTE_ORDER __BIG_ENDIAN
-
-#endif /* _KLIBC_ENDIAN_H */
diff --git a/klibc/include/endian.h b/klibc/include/endian.h
index 7a3680d..348d659 100644
--- a/klibc/include/endian.h
+++ b/klibc/include/endian.h
@@ -5,11 +5,33 @@
 #ifndef _ENDIAN_H
 #define _ENDIAN_H
 
-#define __LITTLE_ENDIAN 1234
-#define __BIG_ENDIAN    4321
-#define __PDP_ENDIAN    3412
+#include <asm/byteorder.h>
 
-#include <klibc/endian.h>
+/* Linux' asm/byteorder.h defines either __LITTLE_ENDIAN or __BIG_ENDIAN,
+   but the BSD-ish macros expect both to be defined with __BYTE_ORDER
+   defining which is actually used... */
+
+#if defined(__LITTLE_ENDIAN)
+# undef  __LITTLE_ENDIAN
+# define __LITTLE_ENDIAN 1234
+# define __BIG_ENDIAN    4321
+# define __PDP_ENDIAN    3412
+# define __BYTE_ORDER    __LITTLE_ENDIAN
+#elif defined(__BIG_ENDIAN)
+# undef  __BIG_ENDIAN
+# define __LITTLE_ENDIAN 1234
+# define __BIG_ENDIAN    4321
+# define __PDP_ENDIAN    3412
+# define __BYTE_ORDER    __BIG_ENDIAN
+#elif defined(__PDP_ENDIAN)
+# undef  __PDP_ENDIAN
+# define __LITTLE_ENDIAN 1234
+# define __BIG_ENDIAN    4321
+# define __PDP_ENDIAN    3412
+# define __BYTE_ORDER    __PDP_ENDIAN
+#else
+# error "Unknown byte order!"
+#endif
 
 #define LITTLE_ENDIAN	__LITTLE_ENDIAN
 #define BIG_ENDIAN	__BIG_ENDIAN
diff --git a/klibc/include/netinet/in.h b/klibc/include/netinet/in.h
index c1f1c16..4b7e77e 100644
--- a/klibc/include/netinet/in.h
+++ b/klibc/include/netinet/in.h
@@ -8,38 +8,9 @@
 #include <stdint.h>
 #include <endian.h>
 
-#if __BYTE_ORDER == __BIG_ENDIAN
-
-#define htonl(x) ((uint32_t)(x))
-#define ntohl(x) ((uint32_t)(x))
-#define htons(x) ((uint16_t)(x))
-#define ntohs(x) ((uint16_t)(x))
-
-#elif __BYTE_ORDER == __LITTLE_ENDIAN
-
-static __inline__
-uint32_t htonl(uint32_t __x)
-{
-#if defined(__i486__)||defined(__pentium__)||defined(__pentiumpro__)
-  asm("bswap %0" : "+rm" (__x));
-  return __x;
-#else
-  return (__x >> 24) + ((__x >> 8) & 0xff00) +
-    ((__x & 0xff00) << 8) + (__x << 24);
-#endif
-}
-
-static __inline__
-uint16_t htons(uint16_t __x)
-{
-  return (__x >> 8) + (__x << 8);
-}
-
-#define htonl(x) htonl(x)
-#define ntohl(x) htohl(x)
-#define htons(x) htons(x)
-#define ntohs(x) htons(x)
-
-#endif /* endian */
+#define htons(x)	__cpu_to_be16(x)
+#define ntohs(x)	__be16_to_cpu(x)
+#define htonl(x)	__cpu_to_be32(x)
+#define ntohl(x)	__be32_to_cpu(x)
 
 #endif /* _NETINET_IN_H */