#include "ntlib.h"
#undef _WIN32_WINNT
#define _WIN32_WINNT 0x0501 /* for getaddrinfo stuff */
-#include <winsock2.h>
-#include <ws2tcpip.h>
+#if defined __MINGW32_VERSION && __MINGW32_VERSION >= 5000000L
+# include <windows.h>
+#else
+# include <winsock2.h>
+#endif
+# include <ws2tcpip.h>
#undef getaddrinfo
#define getaddrinfo sys_getaddrinfo
#undef freeaddrinfo
windows.h. For this to have proper effect, config.h must always be
included before windows.h. */
#define _WINSOCKAPI_ 1
-#define _WINSOCK_H
+#if defined __MINGW32_VERSION && __MINGW32_VERSION < 5000000L
+/* mingw.org's MinGW 5.x changed how it includes winsock.h and time.h,
+ and now defining _WINSOCK_H skips the definition of struct timeval,
+ which we don't want. */
+# define _WINSOCK_H
+#endif
/* Defines size_t and alloca (). */
#include <stdlib.h>
#define timeval ws_timeval
#endif
+#if defined __MINGW32_VERSION && __MINGW32_VERSION >= 5000000L
+/* Need winerror.h before winsock2.h with mingw.org's MinGW 5.x,
+ otherwise some error codes are not defined. */
+# include <winerror.h>
+#endif
#include <winsock2.h>
#include <ws2tcpip.h>
/* process.c uses uint16_t (from C99) for IPv6, but