QHostAddress: Revert auto-converting of IPv6 v4-mapped addresses to IPv4
In 85136496bc
, Shane made QHostAddress
automatically convert any IPv6 address that was v4-mapped to IPv4 in
QHostAddress. While that is an interesting trick, it prevents us from
being specific about what we want. On some OS (like FreeBSD and OS X),
the distinction is relevant, so keep it.
Moreover, it was inconsistent: it might fail depending on how the
QHostAddress was constructed and the order of comparison.
[ChangeLog][Important Behavior Changes] QHostAddress will no longer
convert IPv6 addresses of type "v4-mapped" to IPv4. To perform this
conversion manually, construct another QHostAddress with the result of
toIPv4Address().
Change-Id: I06afbc7018539804bb3044ef1fe6a49ac7a5f240
Reviewed-by: Richard J. Moore <rich@kde.org>
This commit is contained in:
parent
f6e6ef46b3
commit
c64d27a9f7
@ -153,10 +153,8 @@ void QHostAddressPrivate::setAddress(const quint8 *a_)
|
||||
for (int i = 0; i < 16; i++)
|
||||
a6[i] = a_[i];
|
||||
a = 0;
|
||||
if (parseMappedAddress(a, a6))
|
||||
protocol = QAbstractSocket::IPv4Protocol;
|
||||
else
|
||||
protocol = QAbstractSocket::IPv6Protocol;
|
||||
parseMappedAddress(a, a6);
|
||||
protocol = QAbstractSocket::IPv6Protocol;
|
||||
isParsed = true;
|
||||
}
|
||||
|
||||
@ -164,10 +162,8 @@ void QHostAddressPrivate::setAddress(const Q_IPV6ADDR &a_)
|
||||
{
|
||||
a6 = a_;
|
||||
a = 0;
|
||||
if (parseMappedAddress(a, a6))
|
||||
protocol = QAbstractSocket::IPv4Protocol;
|
||||
else
|
||||
protocol = QAbstractSocket::IPv6Protocol;
|
||||
parseMappedAddress(a, a6);
|
||||
protocol = QAbstractSocket::IPv6Protocol;
|
||||
isParsed = true;
|
||||
}
|
||||
|
||||
@ -197,7 +193,6 @@ bool QHostAddressPrivate::parse()
|
||||
quint8 maybeIp6[16];
|
||||
if (parseIp6(a, maybeIp6, &scopeId)) {
|
||||
setAddress(maybeIp6);
|
||||
protocol = QAbstractSocket::IPv6Protocol;
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@ -205,7 +200,6 @@ bool QHostAddressPrivate::parse()
|
||||
quint32 maybeIp4 = 0;
|
||||
if (QIPAddressUtils::parseIp4(maybeIp4, a.constBegin(), a.constEnd())) {
|
||||
setAddress(maybeIp4);
|
||||
protocol = QAbstractSocket::IPv4Protocol;
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -313,6 +313,10 @@ void tst_QHostAddress::compare_data()
|
||||
QTest::newRow("5") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::Broadcast) << false;
|
||||
QTest::newRow("6") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(QHostAddress::LocalHostIPv6) << false;
|
||||
QTest::newRow("7") << QHostAddress() << QHostAddress(QHostAddress::LocalHostIPv6) << false;
|
||||
|
||||
Q_IPV6ADDR localhostv4mapped = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 255, 255, 127, 0, 0, 1 };
|
||||
QTest::newRow("v4-v4mapped") << QHostAddress(QHostAddress::LocalHost) << QHostAddress("::ffff:127.0.0.1") << false;
|
||||
QTest::newRow("v4-v4mapped-2") << QHostAddress(QHostAddress::LocalHost) << QHostAddress(localhostv4mapped) << false;
|
||||
}
|
||||
|
||||
void tst_QHostAddress::compare()
|
||||
@ -322,6 +326,7 @@ void tst_QHostAddress::compare()
|
||||
QFETCH(bool, result);
|
||||
|
||||
QCOMPARE(first == second, result);
|
||||
QCOMPARE(second == first, result);
|
||||
if (result == true)
|
||||
QVERIFY(qHash(first) == qHash(second));
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user