diff --git a/configure b/configure
index 9598bce6c336b26cd7a9d73fdc8c1bf8dfc9afe2..35737a75498e9d98bdd2a85db58be1e965510560 100755
--- a/configure
+++ b/configure
@@ -695,6 +695,7 @@ HAVE_LIST="
     sys_soundcard_h
     termios_h
     threads
+    winsock2_h
 "
 
 CMDLINE_SELECT="
@@ -1534,6 +1535,7 @@ check_header termios.h
 check_header conio.h
 
 check_header arpa/inet.h
+check_header winsock2.h
 
 check_func inet_aton
 enabled zlib && check_lib zlib.h zlibVersion -lz || zlib="no"
diff --git a/libavformat/network.h b/libavformat/network.h
index 723b4f9536645e431db35834e40a8cb84e5f33fd..37606ee98df2bebf987b9935610505f874a75b39 100644
--- a/libavformat/network.h
+++ b/libavformat/network.h
@@ -21,7 +21,7 @@
 #ifndef NETWORK_H
 #define NETWORK_H
 
-#ifdef __MINGW32__
+#ifdef HAVE_WINSOCK2_H
 #include <winsock2.h>
 #include <ws2tcpip.h>
 
diff --git a/libavformat/os_support.c b/libavformat/os_support.c
index 65eb425eb36d5363236b51c4f8633a8cb3c13d26..13f82f76bb4d96ce4045008520a5510ff21f56ee 100644
--- a/libavformat/os_support.c
+++ b/libavformat/os_support.c
@@ -25,7 +25,7 @@
 #include <fcntl.h>
 
 #ifndef HAVE_SYS_POLL_H
-#if defined(__MINGW32__)
+#ifdef HAVE_WINSOCK2_H
 #include <winsock2.h>
 #else
 #include <sys/select.h>
@@ -70,7 +70,7 @@ int resolve_host(struct in_addr *sin_addr, const char *hostname)
 
 int ff_socket_nonblock(int socket, int enable)
 {
-#ifdef __MINGW32__
+#ifdef HAVE_WINSOCK2_H
    return ioctlsocket(socket, FIONBIO, &enable);
 #else
    if (enable)
@@ -92,7 +92,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
     int n;
     int rc;
 
-#ifdef __MINGW32__
+#ifdef HAVE_WINSOCK2_H
     if (numfds >= FD_SETSIZE) {
         errno = EINVAL;
         return -1;
@@ -107,7 +107,7 @@ int poll(struct pollfd *fds, nfds_t numfds, int timeout)
     for(i = 0; i < numfds; i++) {
         if (fds[i].fd < 0)
             continue;
-#ifndef __MINGW32__
+#ifndef HAVE_WINSOCK2_H
         if (fds[i].fd >= FD_SETSIZE) {
             errno = EINVAL;
             return -1;
diff --git a/libavformat/os_support.h b/libavformat/os_support.h
index 13615eec9ef5a382ad49d92ff92dc1c75068c12f..30c069d78b54326e0bd4cd21480a4abe66487604 100644
--- a/libavformat/os_support.h
+++ b/libavformat/os_support.h
@@ -43,6 +43,9 @@ __declspec(dllimport) void __stdcall Sleep(unsigned long dwMilliseconds);
 #  define usleep(t)    Sleep((t) / 1000)
 #  include <fcntl.h>
 #  define lseek(f,p,w) _lseeki64((f), (p), (w))
+#endif
+
+#ifdef HAVE_WINSOCK2_H
 #  define HAVE_CLOSESOCKET 1
 #endif