summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarsten Heimrich <karsten.heimrich@qt.io>2019-08-16 10:03:44 +0200
committerKarsten Heimrich <karsten.heimrich@qt.io>2019-08-20 15:53:46 +0200
commit5e95b06d82cc3e6fe8443e56325b5a6741f30943 (patch)
treecdf820a1edc20a6f0248066cda97e05a735d8efd
parent677de500f64aa23c4bf552eb1bbba7b98def6562 (diff)
Introduce method to fetch interface from a discovery result
Change-Id: Iade4ea527e1bc2e47c2211b5b887431661284a12 Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r--examples/knx/discoverer/main.cpp3
-rw-r--r--src/knx/netip/qknxnetipserverdiscoveryagent.cpp4
-rw-r--r--src/knx/netip/qknxnetipserverinfo.cpp31
-rw-r--r--src/knx/netip/qknxnetipserverinfo.h17
-rw-r--r--src/knx/netip/qknxnetipserverinfo_p.h1
5 files changed, 46 insertions, 10 deletions
diff --git a/examples/knx/discoverer/main.cpp b/examples/knx/discoverer/main.cpp
index 3cf564b..0e539bc 100644
--- a/examples/knx/discoverer/main.cpp
+++ b/examples/knx/discoverer/main.cpp
@@ -204,6 +204,9 @@ int main(int argc, char *argv[])
qInfo().noquote() << endl << QString::fromLatin1("%1 server(s) found on the network.")
.arg(servers.size());
for (auto server : servers) {
+ qInfo().noquote() << QString::fromLatin1(" Network interface: %1, address: %2")
+ .arg(server.networkInterface().humanReadableName(),
+ server.networkInterface().addressEntries().value(1).ip().toString());
qInfo().noquote() << QString::fromLatin1(" Server: %1").arg(server.deviceName());
qInfo().noquote() << QString::fromLatin1(" Individual address: %1").arg(server
.individualAddress().toString());
diff --git a/src/knx/netip/qknxnetipserverdiscoveryagent.cpp b/src/knx/netip/qknxnetipserverdiscoveryagent.cpp
index 8fc5491..e73ddcf 100644
--- a/src/knx/netip/qknxnetipserverdiscoveryagent.cpp
+++ b/src/knx/netip/qknxnetipserverdiscoveryagent.cpp
@@ -324,7 +324,8 @@ void QKnxNetIpServerDiscoveryAgentPrivate::setupSocket()
.setHostAddress(datagram.senderAddress())
.setPort(datagram.senderPort()).create()
: response.controlEndpoint()
- ), response.deviceHardware(), response.supportedFamilies()
+ ), response.deviceHardware(), response.supportedFamilies(),
+ QNetworkInterface::interfaceFromIndex(datagram.interfaceIndex())
});
}
@@ -337,6 +338,7 @@ void QKnxNetIpServerDiscoveryAgentPrivate::setupSocket()
.setPort(datagram.senderPort()).create()
: response.controlEndpoint()
), response.deviceHardware(), response.supportedFamilies(),
+ QNetworkInterface::interfaceFromIndex(datagram.interfaceIndex()),
[&optionalDibs]() -> QKnxNetIpDib {
for (const auto &dib : qAsConst(optionalDibs)) {
if (dib.code() == QKnxNetIp::DescriptionType::TunnelingInfo)
diff --git a/src/knx/netip/qknxnetipserverinfo.cpp b/src/knx/netip/qknxnetipserverinfo.cpp
index 31ac706..d0203ad 100644
--- a/src/knx/netip/qknxnetipserverinfo.cpp
+++ b/src/knx/netip/qknxnetipserverinfo.cpp
@@ -254,6 +254,19 @@ QKnxNetIpDib QKnxNetIpServerInfo::extendedHardware() const
}
/*!
+ \since 5.14
+
+ Returns the network interface which has been used to discover the KNXnet/IP
+ server hardware.
+
+ \sa QNetworkInterface
+*/
+QNetworkInterface QKnxNetIpServerInfo::networkInterface() const
+{
+ return d_ptr->interface;
+}
+
+/*!
Constructs a copy of \a other.
*/
QKnxNetIpServerInfo::QKnxNetIpServerInfo(const QKnxNetIpServerInfo &other)
@@ -321,16 +334,13 @@ void QKnxNetIpServerInfo::swap(QKnxNetIpServerInfo &other) Q_DECL_NOTHROW
d_ptr.swap(other.d_ptr);
}
+#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
/*!
\internal
*/
QKnxNetIpServerInfo::QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNetIpDib &hardware,
-#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
QKnxNetIpDib services)
-#else
- const QKnxNetIpDib &services) // ### Qt6: pass services as const reference
-#endif
: QKnxNetIpServerInfo()
{
d_ptr->hpai = hpai;
@@ -338,12 +348,22 @@ QKnxNetIpServerInfo::QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNe
d_ptr->services = services;
}
-
/*!
\internal
*/
QKnxNetIpServerInfo::QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNetIpDib &hardware,
const QKnxNetIpDib &services, const QKnxNetIpDib &tunneling, const QKnxNetIpDib &extHardware)
+ : QKnxNetIpServerInfo(hpai, hardware, services, {}, tunneling, extHardware)
+{}
+
+#endif
+
+/*!
+ \internal
+*/
+QKnxNetIpServerInfo::QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNetIpDib &hardware,
+ const QKnxNetIpDib &services, const QNetworkInterface &iface, const QKnxNetIpDib &tunneling,
+ const QKnxNetIpDib &extHardware)
: QKnxNetIpServerInfo()
{
d_ptr->hpai = hpai;
@@ -351,6 +371,7 @@ QKnxNetIpServerInfo::QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNe
d_ptr->services = services;
d_ptr->tunnelingInfo = tunneling;
d_ptr->extendedHardware = extHardware;
+ d_ptr->interface = iface;
}
/*!
diff --git a/src/knx/netip/qknxnetipserverinfo.h b/src/knx/netip/qknxnetipserverinfo.h
index 772586f..da0a402 100644
--- a/src/knx/netip/qknxnetipserverinfo.h
+++ b/src/knx/netip/qknxnetipserverinfo.h
@@ -39,6 +39,7 @@
#include <QtKnx/qknxnetiptunnelinginfodib.h>
#include <QtNetwork/qhostaddress.h>
+#include <QtNetwork/qnetworkinterface.h>
QT_BEGIN_NAMESPACE
@@ -72,6 +73,8 @@ public:
QKnxNetIpDib tunnelingInfo() const;
QKnxNetIpDib extendedHardware() const;
+ QNetworkInterface networkInterface() const;
+
QKnxNetIpServerInfo(const QKnxNetIpServerInfo &other);
QKnxNetIpServerInfo &operator=(const QKnxNetIpServerInfo &other);
@@ -84,16 +87,22 @@ public:
void swap(QKnxNetIpServerInfo &other) Q_DECL_NOTHROW;
private:
- QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNetIpDib &hardware,
#if QT_VERSION < QT_VERSION_CHECK(6, 0, 0)
+ QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNetIpDib &hardware,
QKnxNetIpDib services);
-#else
- const QKnxNetIpDib &services);
-#endif
QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai, const QKnxNetIpDib &hardware,
const QKnxNetIpDib &services, const QKnxNetIpDib &tunnelingInfo,
const QKnxNetIpDib &extendedHardware);
+#endif
+
+ QKnxNetIpServerInfo(const QKnxNetIpHpai &hpai,
+ const QKnxNetIpDib &hardware,
+ const QKnxNetIpDib &services,
+ const QNetworkInterface &iface,
+ const QKnxNetIpDib &tunnelingInfo = {},
+ const QKnxNetIpDib &extendedHardware = {});
+
explicit QKnxNetIpServerInfo(QKnxNetIpServerInfoPrivate &dd);
private:
diff --git a/src/knx/netip/qknxnetipserverinfo_p.h b/src/knx/netip/qknxnetipserverinfo_p.h
index 869d909..b1099db 100644
--- a/src/knx/netip/qknxnetipserverinfo_p.h
+++ b/src/knx/netip/qknxnetipserverinfo_p.h
@@ -59,6 +59,7 @@ struct Q_KNX_EXPORT QKnxNetIpServerInfoPrivate final : public QSharedData
QKnxNetIpDib services;
QKnxNetIpDib tunnelingInfo;
QKnxNetIpDib extendedHardware;
+ QNetworkInterface interface;
};
QT_END_NAMESPACE