From 844b096d674c3b803923357502435ef89ce0c738 Mon Sep 17 00:00:00 2001 From: Shane Kearns Date: Fri, 17 Feb 2012 15:14:01 +0000 Subject: Fix error handling in QHostInfo windows backend If the DNS server returns a non authoritative host not found response, then windows returns WSATRY_AGAIN error code. This is now reported as HostNotFound and not UnknownError Change-Id: I212985acd4e85ff4b2bdb6c57ec403405a7695fb Reviewed-by: Miikka Heikkinen Reviewed-by: Richard J. Moore --- src/network/kernel/qhostinfo_win.cpp | 28 ++++++++++++++++++---------- 1 file changed, 18 insertions(+), 10 deletions(-) (limited to 'src/network') diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index a00389e3ed..8ace68d961 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -95,6 +95,22 @@ static void resolveLibrary() #endif } +static void translateWSAError(int error, QHostInfo *results) +{ + switch (error) { + case WSAHOST_NOT_FOUND: //authoritative not found + case WSATRY_AGAIN: //non authoritative not found + case WSANO_DATA: //valid name, no associated address + results->setError(QHostInfo::HostNotFound); + results->setErrorString(QHostInfoAgent::tr("Host not found")); + return; + default: + results->setError(QHostInfo::UnknownError); + results->setErrorString(QHostInfoAgent::tr("Unknown error (%1)").arg(error)); + return; + } +} + QHostInfo QHostInfoAgent::fromName(const QString &hostName) { #if defined(Q_OS_WINCE) @@ -200,12 +216,8 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) } results.setAddresses(addresses); local_freeaddrinfo(res); - } else if (WSAGetLastError() == WSAHOST_NOT_FOUND || WSAGetLastError() == WSANO_DATA) { - results.setError(QHostInfo::HostNotFound); - results.setErrorString(tr("Host not found")); } else { - results.setError(QHostInfo::UnknownError); - results.setErrorString(tr("Unknown error")); + translateWSAError(WSAGetLastError(), &results); } } else { // Fall back to gethostbyname, which only supports IPv4. @@ -228,12 +240,8 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName) break; } results.setAddresses(addresses); - } else if (WSAGetLastError() == 11001) { - results.setErrorString(tr("Host not found")); - results.setError(QHostInfo::HostNotFound); } else { - results.setErrorString(tr("Unknown error")); - results.setError(QHostInfo::UnknownError); + translateWSAError(WSAGetLastError(), &results); } } -- cgit v1.2.3