From: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> Date: Sat, 1 Jan 2022 19:28:03 +0000 (+0100) Subject: Win32: gai_strerror → WSAGetLastError X-Git-Tag: v9.00~67^2 X-Git-Url: https://www.infradead.org/git/?a=commitdiff_plain;h=1d6fed417426a4d33ff9f8c82f81710b93f08b5a;p=users%2Fdwmw2%2Fopenconnect.git Win32: gai_strerror → WSAGetLastError The Windows Sockets documentation recommends using WSAGetLastError() instead of gai_strerror(), because the latter is not thread safe: https://docs.microsoft.com/en-us/windows/win32/winsock/error-codes-errno-h-errno-and-wsagetlasterror-2 Properly decode the output using openconnect__win32_strerror(). Signed-off-by: Dimitri Papadopoulos <3350651-DimitriPapadopoulos@users.noreply.gitlab.com> --- diff --git a/ssl.c b/ssl.c index 9e223504..e77abba2 100644 --- a/ssl.c +++ b/ssl.c @@ -343,9 +343,17 @@ int connect_https_socket(struct openconnect_info *vpninfo) err = getaddrinfo(hostname, port, &hints, &result); if (err) { +#ifdef _WIN32 + char *errstr = openconnect__win32_strerror(WSAGetLastError()); +#else + const char *errstr = gai_strerror(err); +#endif vpn_progress(vpninfo, PRG_ERR, _("getaddrinfo failed for host '%s': %s\n"), - hostname, gai_strerror(err)); + hostname, errstr); +#ifdef _WIN32 + free(errstr); +#endif if (hints.ai_flags & AI_NUMERICHOST) free(hostname); ssl_sock = -EINVAL;