winsock.h: Allow use of hton and ntoh functions on Big Endian when including from winsock2.h.

Pierre d'Herbemont pdherbemont at free.fr
Sat Nov 25 15:43:24 CST 2006


When including from winsock2.h the hton and ntoh functions are unusable 
on Big Endian host because the WS macro gets undefined, which causes the 
hton marcos to be unusable.

Here is a sample fix.

Pierre.
---

  include/winsock.h |   29 ++++++++++++++++-------------
  1 files changed, 16 insertions(+), 13 deletions(-)

-------------- next part --------------
4b3e23c887f1f52b629d95fcada4b723e2ea1da7
diff --git a/include/winsock.h b/include/winsock.h
index ae5df6d..b8c9de9 100644
--- a/include/winsock.h
+++ b/include/winsock.h
@@ -516,28 +516,31 @@ #undef ntohs
 
 #ifdef WORDS_BIGENDIAN
 
-#define htonl(l) ((WS(u_long))(l))
-#define htons(s) ((WS(u_short))(s))
-#define ntohl(l) ((WS(u_long))(l))
-#define ntohs(s) ((WS(u_short))(s))
-
+inline static WS(u_short) __wine_ushort_hton(WS(u_short) s)
+{
+    return s;
+}
+inline static WS(u_long) __wine_ulong_hton(WS(u_long) l)
+{
+    return l;
+}
 #else  /* WORDS_BIGENDIAN */
 
-inline static WS(u_short) __wine_ushort_swap(WS(u_short) s)
+inline static WS(u_short) __wine_ushort_hton(WS(u_short) s)
 {
     return (s >> 8) | (s << 8);
 }
-inline static WS(u_long) __wine_ulong_swap(WS(u_long) l)
+inline static WS(u_long) __wine_ulong_hton(WS(u_long) l)
 {
-    return ((WS(u_long))__wine_ushort_swap((WS(u_short))l) << 16) | __wine_ushort_swap((WS(u_short))(l >> 16));
+    return ((WS(u_long))__wine_ushort_hton((WS(u_short))l) << 16) | __wine_ushort_hton((WS(u_short))(l >> 16));
 }
-#define htonl(l) __wine_ulong_swap(l)
-#define htons(s) __wine_ushort_swap(s)
-#define ntohl(l) __wine_ulong_swap(l)
-#define ntohs(s) __wine_ushort_swap(s)
-
 #endif  /* WORDS_BIGENDIAN */
 
+#define htonl(l) __wine_ulong_hton(l)
+#define htons(s) __wine_ushort_hton(s)
+#define ntohl(l) __wine_ulong_hton(l)
+#define ntohs(s) __wine_ushort_hton(s)
+
 #endif  /* USE_WS_PREFIX */
 
 /*


More information about the wine-patches mailing list