diff --git a/core/backends/lan/landevicelink.cpp b/core/backends/lan/landevicelink.cpp index 7fe1fd54c..0a8302a70 100644 --- a/core/backends/lan/landevicelink.cpp +++ b/core/backends/lan/landevicelink.cpp @@ -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 diff --git a/core/backends/lan/landevicelink.h b/core/backends/lan/landevicelink.h index 5438f85b9..6c0cd9cb7 100644 --- a/core/backends/lan/landevicelink.h +++ b/core/backends/lan/landevicelink.h @@ -54,7 +54,7 @@ public: bool linkShouldBeKeptAlive() override; - QHostAddress hostAddress() const { return mHostAddress; } + QHostAddress hostAddress() const; private Q_SLOTS: void dataReceived();