diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2018-02-19 12:50:17 +0100 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2018-02-19 14:21:36 +0000 |
commit | 4d5a04a0793ef05ade54a09cd469c9934f102753 (patch) | |
tree | 5f0da7e94d4604a0d8171cecc104920ca2d21fcf | |
parent | adb144ca9d1ee8d51bea7af39fd33d499fa3ac87 (diff) |
Specify the interface to use for multicast messagesv5.11.0-beta1
Fixes an issue on Windows where the multi-cast message was
send on a WI-FI interface but never received, because the
multicast group was joined with the first multicast capable
interface (here eth0) found.
Change-Id: I49c747faeb1d19810e7fd304a3685be357ffaac4
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | src/knx/netip/qknxnetipserverdiscoveryagent.cpp | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/src/knx/netip/qknxnetipserverdiscoveryagent.cpp b/src/knx/netip/qknxnetipserverdiscoveryagent.cpp index 0ed5061..25ae3cd 100644 --- a/src/knx/netip/qknxnetipserverdiscoveryagent.cpp +++ b/src/knx/netip/qknxnetipserverdiscoveryagent.cpp @@ -30,6 +30,8 @@ #include "qknxnetipserverdiscoveryagent.h" #include "qknxnetipserverdiscoveryagent_p.h" +#include <QtNetwork/qnetworkinterface.h> + QT_BEGIN_NAMESPACE /*! @@ -91,7 +93,25 @@ void QKnxNetIpServerDiscoveryAgentPrivate::setupSocket() setAndEmitStateChanged(QKnxNetIpServerDiscoveryAgent::State::Running); if (type == QKnxNetIpServerDiscoveryAgent::ResponseType::Multicast) { - if (socket->joinMulticastGroup(multicastAddress)) { + QNetworkInterface mni; + const auto interfaces = QNetworkInterface::allInterfaces(); + for (const auto &iface : interfaces) { + if (!iface.flags().testFlag(QNetworkInterface::CanMulticast)) + continue; + + const auto entries = iface.addressEntries(); + for (const auto &entry : entries) { + auto ip = entry.ip(); + if (ip.protocol() != QAbstractSocket::NetworkLayerProtocol::IPv4Protocol) + continue; + if (ip != address) + continue; + mni = iface; + break; + } + } + + if (socket->joinMulticastGroup(multicastAddress, mni)) { usedPort = multicastPort; usedAddress = multicastAddress; } else { |