--- Xwinsock.h.orig	2017-01-19 10:23:40.556270706 -0500
+++ Xwinsock.h	2017-01-19 15:28:07.231318187 -0500
@@ -39,6 +39,16 @@
 # undef XFree86Server
 #endif
 
+/* Xmd.h defines LONG64 (with no expansion) if a 'long' is 64-bits,
+ * so we need to jump through some extra hoops to be consistent and
+ * not name-clash with the Windows LONG64 type.
+ */
+#ifdef LONG64
+#define __xwinsock_long64_was_defined
+#undef LONG64
+#endif
+#define LONG64 wLONG64
+
 /*
  * mingw-w64 headers define BOOL as a typedef, protecting against macros
  * mingw.org headers define BOOL in terms of WINBOOL
@@ -47,23 +57,32 @@
 #define _NO_BOOL_TYPEDEF
 #define BOOL WINBOOL
 #define INT32 wINT32
+#define INT64 wINT64
 #undef Status
 #define Status wStatus
 #define ATOM wATOM
 #define BYTE wBYTE
 #define FreeResource wFreeResource
 #include <winsock2.h>
+#include <WS2tcpip.h>
 #undef Status
 #define Status int
 #undef BYTE
 #undef BOOL
 #undef INT32
+#undef INT64
 #undef ATOM
 #undef FreeResource
 #undef CreateWindowA
 #undef RT_FONT
 #undef RT_CURSOR
 
+#undef LONG64
+#ifdef __xwinsock_long64_was_defined
+#define LONG64
+#undef __xwinsock_long64_was_defined
+#endif 
+
 /*
  * Older version of this header used to name the windows API bool type wBOOL,
  * rather than more standard name WINBOOL
--- Xwindows.h.orig	2017-02-04 12:22:54.132778566 -0500
+++ Xwindows.h	2017-02-04 12:24:25.186192753 -0500
@@ -55,6 +55,15 @@
  */
 #define NOMINMAX
 
+/* Xmd.h defines LONG64 (with no expansion) if a 'long' is 64-bits,
+ * so we need to jump through some extra hoops to be consistent and
+ * not name-clash with the Windows LONG64 type.
+ */
+#ifdef LONG64
+#define __xwindows_long64_was_defined
+#undef LONG64
+#endif
+
 /*
  * mingw-w64 headers define BOOL as a typedef, protecting against macros
  * mingw.org headers define BOOL in terms of WINBOOL
@@ -85,6 +94,11 @@
 #undef FreeResource
 #undef CreateWindowA
 
+#ifdef __xwindows_long64_was_defined
+#define LONG64
+#undef __xwindows_long64_was_defined
+#endif
+
 /*
  * Older version of this header used to name the windows API bool type wBOOL,
  * rather than more standard name WINBOOL
