diff --git a/core/backends/lan/landevicelink.h b/core/backends/lan/landevicelink.h --- a/core/backends/lan/landevicelink.h +++ b/core/backends/lan/landevicelink.h @@ -54,12 +54,15 @@ bool linkShouldBeKeptAlive() override; + QHostAddress hostAddress() const { return mHostAddress; } + private Q_SLOTS: void dataReceived(); private: SocketLineReader* mSocketLineReader; ConnectionStarted mConnectionSource; + QHostAddress mHostAddress; }; #endif diff --git a/core/backends/lan/landevicelink.cpp b/core/backends/lan/landevicelink.cpp --- a/core/backends/lan/landevicelink.cpp +++ b/core/backends/lan/landevicelink.cpp @@ -56,6 +56,9 @@ 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); } diff --git a/core/device.h b/core/device.h --- a/core/device.h +++ b/core/device.h @@ -25,6 +25,7 @@ #include #include #include +#include #include "networkpackage.h" #include "backends/devicelink.h" @@ -103,6 +104,8 @@ int protocolVersion() { return m_protocolVersion; } QStringList supportedPlugins() const { return m_supportedPlugins.toList(); } + QHostAddress getLocalIpAddress() const; + public Q_SLOTS: ///sends a @p np package to the device ///virtual for testing purposes. diff --git a/core/device.cpp b/core/device.cpp --- a/core/device.cpp +++ b/core/device.cpp @@ -35,6 +35,7 @@ #include "kdeconnectplugin.h" #include "pluginloader.h" #include "backends/devicelink.h" +#include "backends/lan/landevicelink.h" #include "backends/linkprovider.h" #include "networkpackage.h" #include "kdeconnectconfig.h" @@ -380,6 +381,17 @@ } } +QHostAddress Device::getLocalIpAddress() const +{ + for (DeviceLink* dl : m_deviceLinks) { + LanDeviceLink* ldl = dynamic_cast(dl); + if (ldl) { + return ldl->hostAddress(); + } + } + return QHostAddress::Null; +} + Device::DeviceType Device::str2type(const QString &deviceType) { if (deviceType == QLatin1String("desktop")) return Desktop; if (deviceType == QLatin1String("laptop")) return Laptop; diff --git a/plugins/sftp/mounter.cpp b/plugins/sftp/mounter.cpp --- a/plugins/sftp/mounter.cpp +++ b/plugins/sftp/mounter.cpp @@ -113,10 +113,17 @@ if (np.has(QStringLiteral("multiPaths"))) path = '/'; else path = np.get(QStringLiteral("path")); + QHostAddress addr = m_sftp->device()->getLocalIpAddress(); + if (addr == QHostAddress::Null) { + qCDebug(KDECONNECT_PLUGIN_SFTP) << "Device doesn't have a LanDeviceLink, unable to get IP address"; + return; + } + QString ip = addr.toString(); + const QStringList arguments = QStringList() << QStringLiteral("%1@%2:%3").arg( np.get(QStringLiteral("user")), - np.get(QStringLiteral("ip")), + ip, path) << m_mountPoint << QStringLiteral("-p") << np.get(QStringLiteral("port"))