summaryrefslogtreecommitdiffstats
path: root/src/network/kernel/qdnslookup_win.cpp
diff options
context:
space:
mode:
authorMandeep Sandhu <mandeepsandhu.chd@gmail.com>2013-09-27 15:03:04 +0530
committerThe Qt Project <gerrit-noreply@qt-project.org>2014-02-16 11:46:20 +0100
commit62f01d581bdda6f67cd96af179ae1953e30fa218 (patch)
treec920f34cbbf922cdfbd76bbedaf27bf8f0ad39e2 /src/network/kernel/qdnslookup_win.cpp
parent44ee7984fccbeae57e108c1a152050e9d3437174 (diff)
QDnsLookup: Add support for custom DNS server
Implemented the use of the new QDnsLookup property "nameserver". On the Linux platform, we can specify both IPv4 and IPv6 addresses for the nameserver. On Windows since we are using DnsQuery_W(), which does not have a way of accepting IPv6 addresses, passing IPv6 nameserver address is not supported. On OSX/BSD platforms, specifying IPv6 addresses for nameserver require access to the __res_state_ext structure which is in a private header of libresolv (this header is different for BSDs and OSX). If this feature has to be enabled in the future, we have to figure out a way to access this struct by either accessing the private header or by specifying one of our own. Currently, I'm disabling it till such a solution is arrived at. Nameserver support on different platforms: Platform | IPv4 | IPv6 -------------+---------------+--------------- Linux/X11 | supported | supported -------------+---------------+--------------- Windows | supported | not supported -------------+---------------+--------------- OSX | supported | not supported -------------+---------------+--------------- WinRT | not supported | not supported -------------+---------------+--------------- Others | supported | not supported | (not tested) | -------------+---------------+--------------- Task-number: QTBUG-30166 Change-Id: Iedbddf15b9a62738ce4c2cfa0fce051514d64766 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/network/kernel/qdnslookup_win.cpp')
-rw-r--r--src/network/kernel/qdnslookup_win.cpp22
1 files changed, 20 insertions, 2 deletions
diff --git a/src/network/kernel/qdnslookup_win.cpp b/src/network/kernel/qdnslookup_win.cpp
index bf80a23297..6f58e64440 100644
--- a/src/network/kernel/qdnslookup_win.cpp
+++ b/src/network/kernel/qdnslookup_win.cpp
@@ -48,15 +48,33 @@
#include <qt_windows.h>
#include <windns.h>
+#include <memory.h>
QT_BEGIN_NAMESPACE
-void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, QDnsLookupReply *reply)
+void QDnsLookupRunnable::query(const int requestType, const QByteArray &requestName, const QHostAddress &nameserver, QDnsLookupReply *reply)
{
// Perform DNS query.
PDNS_RECORD dns_records = 0;
const QString requestNameUtf16 = QString::fromUtf8(requestName.data(), requestName.size());
- const DNS_STATUS status = DnsQuery_W(reinterpret_cast<const wchar_t*>(requestNameUtf16.utf16()), requestType, DNS_QUERY_STANDARD, NULL, &dns_records, NULL);
+ IP4_ARRAY srvList;
+ memset(&srvList, 0, sizeof(IP4_ARRAY));
+ if (!nameserver.isNull()) {
+ if (nameserver.protocol() == QAbstractSocket::IPv4Protocol) {
+ // The below code is referenced from: http://support.microsoft.com/kb/831226
+ srvList.AddrCount = 1;
+ srvList.AddrArray[0] = htonl(nameserver.toIPv4Address());
+ } else if (nameserver.protocol() == QAbstractSocket::IPv6Protocol) {
+ // For supoprting IPv6 nameserver addresses, we'll need to switch
+ // from DnsQuey() to DnsQueryEx() as it supports passing an IPv6
+ // address in the nameserver list
+ qWarning() << Q_FUNC_INFO << "IPv6 addresses for nameservers is currently not supported";
+ reply->error = QDnsLookup::ResolverError;
+ reply->errorString = tr("IPv6 addresses for nameservers is currently not supported");
+ return;
+ }
+ }
+ const DNS_STATUS status = DnsQuery_W(reinterpret_cast<const wchar_t*>(requestNameUtf16.utf16()), requestType, DNS_QUERY_STANDARD, &srvList, &dns_records, NULL);
switch (status) {
case ERROR_SUCCESS:
break;