diff --git a/Common/Net/HTTPClient.cpp b/Common/Net/HTTPClient.cpp index b68ad6bfe961..232da51fbabc 100644 --- a/Common/Net/HTTPClient.cpp +++ b/Common/Net/HTTPClient.cpp @@ -30,6 +30,7 @@ #include "Common/Net/URL.h" #include "Common/File/FileDescriptor.h" +#include "Common/SysError.h" #include "Common/Thread/ThreadUtil.h" #include "Common/Data/Encoding/Compression.h" #include "Common/Net/NetBuffer.h" @@ -97,7 +98,7 @@ static void FormatAddr(char *addrbuf, size_t bufsize, const addrinfo *info) { switch (info->ai_family) { case AF_INET: case AF_INET6: - inet_ntop(info->ai_family, info->ai_addr, addrbuf, bufsize); + inet_ntop(info->ai_family, &((sockaddr_in *)info->ai_addr)->sin_addr, addrbuf, bufsize); break; default: snprintf(addrbuf, bufsize, "(Unknown AF %d)", info->ai_family); @@ -131,11 +132,22 @@ bool Connection::Connect(int maxTries, double timeout, bool *cancelConnect) { // Start trying to connect (async with timeout.) errno = 0; if (connect(sock, possible->ai_addr, (int)possible->ai_addrlen) < 0) { - if (errno != 0 && errno != EINPROGRESS) { - char addrStr[128]; +#if PPSSPP_PLATFORM(WINDOWS) + int errorCode = WSAGetLastError(); + std::string errorString = GetStringErrorMsg(errno); + bool unreachable = errorCode == WSAENETUNREACH; + bool inProgress = errorCode == WSAEINPROGRESS || errorCode == WSAEWOULDBLOCK; +#else + int errorCode = errno; + std::string errorString = strerror(errno); + bool unreachable = errorCode == ENETUNREACH; + bool inProgress = errorCode == EINPROGRESS || errorCode == EWOULDBLOCK; +#endif + if (!inProgress) { + char addrStr[128]{}; FormatAddr(addrStr, sizeof(addrStr), possible); - if (errno != ENETUNREACH) { - ERROR_LOG(HTTP, "connect(%d) call to %s failed (%d: %s)", sock, addrStr, errno, strerror(errno)); + if (!unreachable) { + ERROR_LOG(HTTP, "connect(%d) call to %s failed (%d: %s)", sock, addrStr, errorCode, errorString.c_str()); } else { INFO_LOG(HTTP, "connect(%d): Ignoring unreachable resolved address %s", sock, addrStr); }