diff -urNp openvpn-2.1.3/acinclude.m4 openvpn-2.1.3.new/acinclude.m4
--- openvpn-2.1.3/acinclude.m4	2010-03-31 09:47:08.000000000 +0300
+++ openvpn-2.1.3.new/acinclude.m4	2010-09-13 17:50:08.000000000 +0200
@@ -90,34 +90,30 @@ AC_DEFUN([TYPE_SOCKLEN_T],
       AC_MSG_CHECKING([for socklen_t equivalent])
       AC_CACHE_VAL([curl_cv_socklen_t_equiv],
       [
-         # Systems have either "struct sockaddr *" or
-         # "void *" as the second argument to getpeername
-         curl_cv_socklen_t_equiv=
-         for arg2 in "struct sockaddr" void; do
-            for t in int size_t unsigned long "unsigned long"; do
-               AC_TRY_COMPILE([
-                  #ifdef _WIN32
-                  #include <windows.h>
-                  #define PREFIX1 WINSOCK_API_LINKAGE
-                  #define PREFIX2 PASCAL
-                  #else
-                  #include <sys/types.h>
-                  #include <sys/socket.h>
-                  #define PREFIX1
-                  #define PREFIX2
-                  #define SOCKET int
-                  #endif
-
-                  PREFIX1 int PREFIX2 getpeername (SOCKET, $arg2 *, $t *);
-               ],[
-                  $t len;
-                  getpeername(0,0,&len);
-               ],[
-                  curl_cv_socklen_t_equiv="$t"
-                  break
-               ])
+         case "$host" in
+	 *-mingw*) curl_cv_socklen_t_equiv=int ;;
+	 *)
+            # Systems have either "struct sockaddr *" or
+            # "void *" as the second argument to getpeername
+            curl_cv_socklen_t_equiv=
+            for arg2 in "struct sockaddr" void; do
+               for t in int size_t unsigned long "unsigned long"; do
+                  AC_TRY_COMPILE([
+                     #include <sys/types.h>
+                     #include <sys/socket.h>
+
+                     int getpeername (int, $arg2 *, $t *);
+                  ],[
+                     $t len;
+                     getpeername(0,0,&len);
+                  ],[
+                     curl_cv_socklen_t_equiv="$t"
+                     break
+                  ])
+               done
             done
-         done
+	 ;;
+	 esac
 
          if test "x$curl_cv_socklen_t_equiv" = x; then
             AC_MSG_ERROR([Cannot find a type to use in place of socklen_t])
diff -urNp openvpn-2.1.3/configure.ac openvpn-2.1.3.new/configure.ac
--- openvpn-2.1.3/configure.ac	2010-04-28 19:25:38.000000000 +0300
+++ openvpn-2.1.3.new/configure.ac	2010-09-13 17:50:35.000000000 +0200
@@ -308,6 +308,7 @@ case "$target" in
 	;;
 *mingw*)
 	AC_DEFINE(TARGET_WIN32, 1, [Are we running WIN32?])
+	CPPFLAGS="${CPPFLAGS} -DWIN32_LEAN_AND_MEAN"
 	OPENVPN_ADD_LIBS(-lgdi32)
 	OPENVPN_ADD_LIBS(-lws2_32)
 	OPENVPN_ADD_LIBS(-lwininet)
diff -urNp openvpn-2.1.3/syshead.h openvpn-2.1.3.new/syshead.h
--- openvpn-2.1.3/syshead.h	2010-07-27 01:06:51.000000000 +0300
+++ openvpn-2.1.3.new/syshead.h	2010-09-13 17:44:16.000000000 +0200
@@ -51,6 +51,7 @@
 
 #ifdef WIN32
 #include <windows.h>
+#include <winsock2.h>
 #define sleep(x) Sleep((x)*1000)
 #define random rand
 #define srandom srand
diff -urNp openvpn-2.1.3/tap-win32/common.h openvpn-2.1.3.new/tap-win32/common.h
--- openvpn-2.1.3/tap-win32/common.h	2010-04-28 19:25:39.000000000 +0300
+++ openvpn-2.1.3.new/tap-win32/common.h	2010-09-13 17:54:26.000000000 +0200
@@ -28,7 +28,9 @@
 // common to both.
 //===============================================
 
+#ifndef HAVE_CONFIG_H
 #include "autodefs.h"
+#endif
 
 //=============
 // TAP IOCTLs
