summaryrefslogtreecommitdiffstats
path: root/src/network/kernel/qhostinfo_win.cpp
diff options
context:
space:
mode:
authorThiago Macieira <thiago.macieira@nokia.com>2009-08-18 16:52:45 (GMT)
committerThiago Macieira <thiago.macieira@nokia.com>2009-08-20 10:36:50 (GMT)
commitc7c7b364d9816d03c7475d6592d50dec5401c151 (patch)
treef24fcc1bca4108b990fdce9eb856b2e00c2a8b93 /src/network/kernel/qhostinfo_win.cpp
parent909cdf082fd99ce8bdcb99a9db38d09f52d869aa (diff)
downloadQt-c7c7b364d9816d03c7475d6592d50dec5401c151.zip
Qt-c7c7b364d9816d03c7475d6592d50dec5401c151.tar.gz
Qt-c7c7b364d9816d03c7475d6592d50dec5401c151.tar.bz2
Fix literal IPv6 hostname resolution in QHostInfo.
With the series of commits ending in ff1280178, I made QUrl::toAce fail if the parameter is not a well-formed hostname (i.e., if it violates STD3). IPv6 hostnames do, so we can't preemptively run ToACE. Instead, delay running ToACE until we've tried literal matching. Reviewed-by: TrustMe
Diffstat (limited to 'src/network/kernel/qhostinfo_win.cpp')
-rw-r--r--src/network/kernel/qhostinfo_win.cpp21
1 files changed, 18 insertions, 3 deletions
diff --git a/src/network/kernel/qhostinfo_win.cpp b/src/network/kernel/qhostinfo_win.cpp
index 93dc720..8fd3a3f 100644
--- a/src/network/kernel/qhostinfo_win.cpp
+++ b/src/network/kernel/qhostinfo_win.cpp
@@ -129,7 +129,6 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
}
QHostInfo results;
- results.setHostName(hostName);
#if defined(QHOSTINFO_DEBUG)
qDebug("QHostInfoAgent::fromName(%p): looking up \"%s\" (IPv6 support is %s)",
@@ -178,12 +177,28 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
}
}
+ // IDN support
+ QByteArray aceHostname;
+ if (results.hostName().isEmpty()) {
+ // it's a hostname resolution
+ aceHostname = QUrl::toAce(hostName);
+ results.setHostName(hostName);
+ if (aceHostname.isEmpty()) {
+ results.setError(QHostInfo::HostNotFound);
+ results.setErrorString(hostName.isEmpty() ? QObject::tr("No host name given") : QObject::tr("Invalid hostname"));
+ return results;
+ }
+ } else {
+ // it's an IP reverse resolution
+ aceHostname = results.hostName().toLatin1();
+ }
+
if (local_getaddrinfo && local_freeaddrinfo) {
// Call getaddrinfo, and place all IPv4 addresses at the start
// and the IPv6 addresses at the end of the address list in
// results.
qt_addrinfo *res;
- int err = local_getaddrinfo(hostName.toLatin1().constData(), 0, 0, &res);
+ int err = local_getaddrinfo(aceHostname.constData(), 0, 0, &res);
if (err == 0) {
QList<QHostAddress> addresses;
for (qt_addrinfo *p = res; p != 0; p = p->ai_next) {
@@ -218,7 +233,7 @@ QHostInfo QHostInfoAgent::fromName(const QString &hostName)
}
} else {
// Fall back to gethostbyname, which only supports IPv4.
- hostent *ent = gethostbyname(hostName.toLatin1().constData());
+ hostent *ent = gethostbyname(aceHostname.constData());
if (ent) {
char **p;
QList<QHostAddress> addresses;