diff -urN a/configure.ac b/configure.ac --- a/configure.ac 2014-10-11 14:20:16.937702700 +0100 +++ b/configure.ac 2014-10-11 14:20:19.747863400 +0100 @@ -3621,21 +3621,36 @@ ],[]) AC_MSG_RESULT($was_it_defined) +AC_CHECK_HEADERS([ws2tcpip.h]) AC_MSG_CHECKING(for addrinfo) AC_CACHE_VAL(ac_cv_struct_addrinfo, -AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[#include ]], [[struct addrinfo a]])], +AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ +#ifdef HAVE_WS2TCPIP_H +# include +#else +# include +#endif]], + [[struct addrinfo a]])], [ac_cv_struct_addrinfo=yes], [ac_cv_struct_addrinfo=no])) AC_MSG_RESULT($ac_cv_struct_addrinfo) if test $ac_cv_struct_addrinfo = yes; then - AC_DEFINE(HAVE_ADDRINFO, 1, [struct addrinfo (netdb.h)]) + AC_DEFINE(HAVE_ADDRINFO, 1, [struct addrinfo]) fi AC_MSG_CHECKING(for sockaddr_storage) AC_CACHE_VAL(ac_cv_struct_sockaddr_storage, AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[ -# include -# include ]], [[struct sockaddr_storage s]])], +#ifdef HAVE_WS2TCPIP_H +#include +#endif +#ifdef HAVE_SYS_TYPES_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif]], + [[struct sockaddr_storage s]])], [ac_cv_struct_sockaddr_storage=yes], [ac_cv_struct_sockaddr_storage=no])) AC_MSG_RESULT($ac_cv_struct_sockaddr_storage) @@ -4821,7 +4836,10 @@ AC_CHECK_TYPE(socklen_t,, AC_DEFINE(socklen_t,int, - [Define to `int' if does not define.]),[ + [Define to `int' if or does not define.]),[ +#ifdef HAVE_WS2TCPIP_H +#include +#endif #ifdef HAVE_SYS_TYPES_H #include #endif diff -urN a/Misc/config_mingw b/Misc/config_mingw --- a/Misc/config_mingw 2014-10-11 14:20:17.566738600 +0100 +++ b/Misc/config_mingw 2014-10-11 14:20:19.748863500 +0100 @@ -10,3 +10,6 @@ # files to ignore ac_cv_file__dev_ptmx=ignore #NOTE: under MSYS environment device exist ac_cv_file__dev_ptc=no + +# force detection of winsock2 functionality - require wxp or newer +ac_cv_func_getpeername=yes diff -urN a/Modules/socketmodule.c b/Modules/socketmodule.c --- a/Modules/socketmodule.c 2014-10-11 14:20:17.822753300 +0100 +++ b/Modules/socketmodule.c 2014-10-11 14:20:19.751863600 +0100 @@ -306,6 +306,12 @@ /* Do not include addrinfo.h for MSVC7 or greater. 'addrinfo' and * EAI_* constants are defined in (the already included) ws2tcpip.h. */ +#elif defined(__MINGW32__) + /* Do not include addrinfo.h as minimum supported version is + * _WIN32_WINNT >= WindowsXP(0x0501) + */ +# define HAVE_GETADDRINFO +# define HAVE_GETNAMEINFO #else # include "addrinfo.h" #endif diff -urN a/pyconfig.h.in b/pyconfig.h.in --- a/pyconfig.h.in 2014-10-11 14:20:17.492734400 +0100 +++ b/pyconfig.h.in 2014-10-11 14:20:19.752863700 +0100 @@ -43,7 +43,7 @@ /* Define to 1 if you have the `acosh' function. */ #undef HAVE_ACOSH -/* struct addrinfo (netdb.h) */ +/* struct addrinfo */ #undef HAVE_ADDRINFO /* Define to 1 if you have the `alarm' function. */ @@ -1149,6 +1149,9 @@ /* Define to 1 if you have the `writev' function. */ #undef HAVE_WRITEV +/* Define to 1 if you have the header file. */ +#undef HAVE_WS2TCPIP_H + /* Define if the zlib library has inflateCopy */ #undef HAVE_ZLIB_COPY @@ -1481,7 +1484,7 @@ /* Define to `unsigned int' if does not define. */ #undef size_t -/* Define to `int' if does not define. */ +/* Define to `int' if or does not define. */ #undef socklen_t /* Define to `int' if doesn't define. */ diff -urN a/setup.py b/setup.py --- a/setup.py 2014-10-11 14:20:18.052766400 +0100 +++ b/setup.py 2014-10-11 14:20:19.754863800 +0100 @@ -762,7 +762,11 @@ exts.append( Extension('_posixsubprocess', ['_posixsubprocess.c']) ) # socket(2) + socket_libs = [] + if host_platform.startswith(('mingw', 'win')): + socket_libs += ['ws2_32'] exts.append( Extension('_socket', ['socketmodule.c'], + libraries = socket_libs, depends = ['socketmodule.h']) ) # Detect SSL support for the socket module (via _ssl) search_for_ssl_incs_in = [