diff options
author | Shane Kearns <ext-shane.2.kearns@nokia.com> | 2012-02-17 15:14:01 (GMT) |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2012-03-07 04:09:17 (GMT) |
commit | 92b1f5479b822a15f0c16f7da9219875a4df5b89 (patch) | |
tree | db1cf4d8e6656166a3042a61579eabb74db26fc5 /src/network/kernel | |
parent | 093929e29f22f116584fc36ccb5d545799c2871a (diff) | |
download | Qt-92b1f5479b822a15f0c16f7da9219875a4df5b89.zip Qt-92b1f5479b822a15f0c16f7da9219875a4df5b89.tar.gz Qt-92b1f5479b822a15f0c16f7da9219875a4df5b89.tar.bz2 |
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 <miikka.heikkinen@digia.com>
Reviewed-by: Richard J. Moore <rich@kde.org>
(cherry picked from commit 844b096d674c3b803923357502435ef89ce0c738)
Diffstat (limited to 'src/network/kernel')
-rw-r--r-- | src/network/kernel/qhostinfo_win.cpp | 28 |
1 files changed, 18 insertions, 10 deletions
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp index 98b0c24..4988f6b 100644 --- a/src/network/kernel/qhostinfo_win.cpp +++ b/src/network/kernel/qhostinfo_win.cpp @@ -105,6 +105,22 @@ static void resolveLibrary() Q_GLOBAL_STATIC(QMutex, qPrivCEMutex) #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) { resolveLibrary(); @@ -201,12 +217,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. @@ -229,12 +241,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); } } |