aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorH. Peter Anvin <hpa@zytor.com>2002-08-11 04:50:38 +0000
committerH. Peter Anvin <hpa@zytor.com>2002-08-11 04:50:38 +0000
commit13c7a3fd2452e1806c99105e180385a5fc543244 (patch)
tree96a01e0eb825dab21fd8de6945d4cb6b8b82509e
parent5d5d05fc89ebe38c4712367bbc7e617690a87af6 (diff)
downloadklibc-13c7a3fd2452e1806c99105e180385a5fc543244.tar.gz
Add <netinet/in.h> for hton/ntoh macrosklibc-0.15
-rw-r--r--include/extern.h14
-rw-r--r--include/netinet/in.h45
-rw-r--r--klibc/include/netinet/in.h45
3 files changed, 90 insertions, 14 deletions
diff --git a/include/extern.h b/include/extern.h
deleted file mode 100644
index f3369ba415f86..0000000000000
--- a/include/extern.h
+++ /dev/null
@@ -1,14 +0,0 @@
-/*
- * extern.h
- */
-
-#ifndef _EXTERN_H
-#define _EXTERN_H
-
-#ifdef __cplusplus
-#define __extern extern "C"
-#else
-#define __extern extern
-#endif
-
-#endif /* _EXTERN_H */
diff --git a/include/netinet/in.h b/include/netinet/in.h
new file mode 100644
index 0000000000000..a4bcb7efc4731
--- /dev/null
+++ b/include/netinet/in.h
@@ -0,0 +1,45 @@
+/*
+ * netinet/in.h
+ */
+
+#ifndef _NETINET_IN_H
+#define _NETINET_IN_H
+
+#include <stdint.h>
+#include <endian.h>
+
+#ifdef __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 defined(__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 */
+
+#endif /* _NETINET_IN_H */
diff --git a/klibc/include/netinet/in.h b/klibc/include/netinet/in.h
new file mode 100644
index 0000000000000..a4bcb7efc4731
--- /dev/null
+++ b/klibc/include/netinet/in.h
@@ -0,0 +1,45 @@
+/*
+ * netinet/in.h
+ */
+
+#ifndef _NETINET_IN_H
+#define _NETINET_IN_H
+
+#include <stdint.h>
+#include <endian.h>
+
+#ifdef __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 defined(__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 */
+
+#endif /* _NETINET_IN_H */