diff options
author | Lev Stipakov | 2022-08-20 11:47:19 +0300 |
---|---|---|
committer | Gert Doering | 2022-08-20 11:29:35 +0200 |
commit | 2f8053f9a97584b759d11d05a668d38653508617 (patch) | |
tree | 9c48d8511940253c4146743c9fdf8ba861d65819 | |
parent | efebdfe2de8dd5125fb42d646d03a958b7dc3eea (diff) | |
download | openvpn-2f8053f9a97584b759d11d05a668d38653508617.zip openvpn-2f8053f9a97584b759d11d05a668d38653508617.tar.gz |
dco-win: use run-time dynamic linking for GetOverlappedResultEx
This function is available starting from Windows 8. Calling it
"as is" causes startup error on Windows 7.
dco-win driver available on Windows 10 20H1 and newer. On older
systems installer will not show nor install the driver and dco-win code
won't be reached. It is safe to load GetOverlappedResultEx in runtime
and exit in case of error.
Signed-off-by: Lev Stipakov <lev@openvpn.net>
Acked-by: Gert Doering <gert@greenie.muc.de>
Message-Id: <20220820084719.243-1-lstipakov@gmail.com>
URL: https://www.mail-archive.com/openvpn-devel@lists.sourceforge.net/msg25038.html
Signed-off-by: Gert Doering <gert@greenie.muc.de>
-rw-r--r-- | src/openvpn/dco_win.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/src/openvpn/dco_win.c b/src/openvpn/dco_win.c index 28bcccd..a203086 100644 --- a/src/openvpn/dco_win.c +++ b/src/openvpn/dco_win.c @@ -107,6 +107,17 @@ dco_start_tun(struct tuntap *tt) static int dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, volatile int *signal_received) { + /* GetOverlappedResultEx is available starting from Windows 8 */ + typedef BOOL (*get_overlapped_result_ex_t) (HANDLE, LPOVERLAPPED, LPDWORD, DWORD, BOOL); + get_overlapped_result_ex_t get_overlapped_result_ex = + (get_overlapped_result_ex_t)GetProcAddress(GetModuleHandle("Kernel32.dll"), + "GetOverlappedResultEx"); + + if (get_overlapped_result_ex == NULL) + { + msg(M_ERR, "Failed to load GetOverlappedResult()"); + } + DWORD timeout_msec = timeout * 1000; const int poll_interval_ms = 50; @@ -115,7 +126,7 @@ dco_connect_wait(HANDLE handle, OVERLAPPED *ov, int timeout, volatile int *signa timeout_msec -= poll_interval_ms; DWORD transferred; - if (GetOverlappedResultEx(handle, ov, &transferred, poll_interval_ms, FALSE) != 0) + if (get_overlapped_result_ex(handle, ov, &transferred, poll_interval_ms, FALSE) != 0) { /* TCP connection established by dco */ return 0; |