Check if the IPv6 to v4 conversion succeeds, use v6 if it doesn't.

This commit is contained in:
Albert Vaca 2017-07-22 11:25:07 +02:00
parent 25b86c6c7f
commit df61e8f0e6
2 changed files with 18 additions and 4 deletions

View file

@ -56,13 +56,27 @@ void LanDeviceLink::reset(QSslSocket* socket, ConnectionStarted connectionSource
mConnectionSource = connectionSource;
QHostAddress addr = socket->peerAddress();
mHostAddress = (addr.protocol() == QAbstractSocket::IPv6Protocol) ? QHostAddress(addr.toIPv4Address()) : addr;
QString certString = KdeConnectConfig::instance()->getDeviceProperty(deviceId(), QStringLiteral("certificate"));
DeviceLink::setPairStatus(certString.isEmpty()? PairStatus::NotPaired : PairStatus::Paired);
}
QHostAddress LanDeviceLink::hostAddress() const
{
if (!mSocketLineReader) {
return QHostAddress::Null;
}
QHostAddress addr = mSocketLineReader->mSocket->peerAddress();
if (addr.protocol() == QAbstractSocket::IPv6Protocol) {
bool success;
QHostAddress convertedAddr = QHostAddress(addr.toIPv4Address(&success));
if (success) {
qCDebug(KDECONNECT_CORE) << "Converting IPv6" << addr << "to IPv4" << convertedAddr;
addr = convertedAddr;
}
}
return addr;
}
QString LanDeviceLink::name()
{
return QStringLiteral("LanLink"); // Should be same in both android and kde version

View file

@ -54,7 +54,7 @@ public:
bool linkShouldBeKeptAlive() override;
QHostAddress hostAddress() const { return mHostAddress; }
QHostAddress hostAddress() const;
private Q_SLOTS:
void dataReceived();