summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2011-05-20 19:18:56 +1000
committerQt Continuous Integration System <qt-info@nokia.com>2011-05-20 19:18:56 +1000
commit4bd181fb5abc4c85e4f097262d36a409258b1561 (patch)
tree802b6ef18d4cd23eadda9e41d0988b69e0118590 /src
parentacc98b9b36c61bb661701cd98d70d2ebae4ee2f6 (diff)
parentdf2d6753acff2dde79f99effc1a779f5c7f0a2c0 (diff)
Merge branch 'master' of git://scm.dev.nokia.troll.no/qt/qtbase-staging
* 'master' of git://scm.dev.nokia.troll.no/qt/qtbase-staging: tst_qhostinfo: Fix IPv6 lookup detection on Windows. Fix incorrect hardware address on systems without getifaddrs() Make QHostAddress.toString() follow RFC-5952 for IPv6 address format.
Diffstat (limited to 'src')
-rw-r--r--src/network/kernel/qhostaddress.cpp31
-rw-r--r--src/network/kernel/qnetworkinterface_unix.cpp2
2 files changed, 29 insertions, 4 deletions
diff --git a/src/network/kernel/qhostaddress.cpp b/src/network/kernel/qhostaddress.cpp
index ae7d7a1486..4e7c286d80 100644
--- a/src/network/kernel/qhostaddress.cpp
+++ b/src/network/kernel/qhostaddress.cpp
@@ -720,7 +720,8 @@ Q_IPV6ADDR QHostAddress::toIPv6Address() const
Returns the address as a string.
For example, if the address is the IPv4 address 127.0.0.1, the
- returned string is "127.0.0.1".
+ returned string is "127.0.0.1". For IPv6 the string format will
+ follow the RFC5952 recommendation.
\sa toIPv4Address()
*/
@@ -741,8 +742,32 @@ QString QHostAddress::toString() const
ugle[i] = (quint16(d->a6[2*i]) << 8) | quint16(d->a6[2*i+1]);
}
QString s;
- s.sprintf("%X:%X:%X:%X:%X:%X:%X:%X",
- ugle[0], ugle[1], ugle[2], ugle[3], ugle[4], ugle[5], ugle[6], ugle[7]);
+ QString temp;
+ bool zeroDetected = false;
+ bool zeroShortened = false;
+ for (int i = 0; i < 8; i++) {
+ if ((ugle[i] != 0) || zeroShortened) {
+ temp.sprintf("%X", ugle[i]);
+ s.append(temp);
+ if (zeroDetected)
+ zeroShortened = true;
+ } else {
+ if (!zeroDetected) {
+ if (i<7 && (ugle[i+1] == 0)) {
+ s.append(QLatin1Char(':'));
+ zeroDetected = true;
+ } else {
+ temp.sprintf("%X", ugle[i]);
+ s.append(temp);
+ if (i<7)
+ s.append(QLatin1Char(':'));
+ }
+ }
+ }
+ if (i<7 && ((ugle[i] != 0) || zeroShortened || (i==0 && zeroDetected)))
+ s.append(QLatin1Char(':'));
+ }
+
if (!d->scopeId.isEmpty())
s.append(QLatin1Char('%') + d->scopeId);
return s;
diff --git a/src/network/kernel/qnetworkinterface_unix.cpp b/src/network/kernel/qnetworkinterface_unix.cpp
index 6098bdeee0..7f251a782b 100644
--- a/src/network/kernel/qnetworkinterface_unix.cpp
+++ b/src/network/kernel/qnetworkinterface_unix.cpp
@@ -219,7 +219,7 @@ static QNetworkInterfacePrivate *findInterface(int socket, QList<QNetworkInterfa
#ifdef SIOCGIFHWADDR
// Get the HW address
if (qt_safe_ioctl(socket, SIOCGIFHWADDR, &req) >= 0) {
- uchar *addr = (uchar *)&req.ifr_addr;
+ uchar *addr = (uchar *)req.ifr_addr.sa_data;
iface->hardwareAddress = iface->makeHwAddress(6, addr);
}
#endif