diff options
author | Karsten Heimrich <karsten.heimrich@qt.io> | 2018-07-25 22:33:41 +0200 |
---|---|---|
committer | Karsten Heimrich <karsten.heimrich@qt.io> | 2018-07-27 08:24:07 +0000 |
commit | a003ef17d930641f37b063fc2927266b2a892e62 (patch) | |
tree | 265cffde5167a76206aa858a27f0f588ed44355d | |
parent | 90dd86f7a51fc5a0b9f860d5148d006acbcec391 (diff) |
Avoid sending a multicast search request via loopback device
Initially the QKnxNetIpServerDiscoveryAgent was joining the
multicast group on the default interface chosen by the operating
system. This lead to strange behavior on windows with several
interfaces up and running. A fix for this was applied in change
4d5a04a0793ef05ade54a09cd469c9934f102753 that explicitly defines
the interface to use. No if we use localhost as default address,
the loopback device gets picked and no multicast search request
will be send to the network and one would always need to specify
the target address to respond to, making multicast obsolete.
Change-Id: I4fd0fbff72d0a6f7b3e497976d70293aa8decc64
Reviewed-by: Andrew O'Doherty <andrew.odoherty@qt.io>
Reviewed-by: Karsten Heimrich <karsten.heimrich@qt.io>
-rw-r--r-- | examples/knx/discoverer/main.cpp | 6 | ||||
-rw-r--r-- | src/knx/netip/qknxnetiphpai.h | 2 | ||||
-rw-r--r-- | tests/auto/qknxnetiphpai/tst_qknxnetiphpai.cpp | 4 |
3 files changed, 8 insertions, 4 deletions
diff --git a/examples/knx/discoverer/main.cpp b/examples/knx/discoverer/main.cpp index 5ecf364..ed7b60f 100644 --- a/examples/knx/discoverer/main.cpp +++ b/examples/knx/discoverer/main.cpp @@ -111,7 +111,11 @@ int main(int argc, char *argv[]) agent.setNatAware(parser.isSet("nat")); agent.setLocalPort(parser.value("localPort").toUInt()); agent.setTimeout(parser.value("timeout").toInt() * 1000); - agent.setLocalAddress(QHostAddress(parser.value("localAddress"))); + + if (parser.isSet("localAddress")) { + agent.setLocalAddress(QHostAddress(parser.value("localAddress"))); + agent.setResponseType(QKnxNetIpServerDiscoveryAgent::ResponseType::Unicast); + } if (parser.isSet("unicast")) agent.setResponseType(QKnxNetIpServerDiscoveryAgent::ResponseType::Unicast); diff --git a/src/knx/netip/qknxnetiphpai.h b/src/knx/netip/qknxnetiphpai.h index 445e721..f6fcabf 100644 --- a/src/knx/netip/qknxnetiphpai.h +++ b/src/knx/netip/qknxnetiphpai.h @@ -62,7 +62,7 @@ public: private: QKnxNetIp::HostProtocol m_code { QKnxNetIp::HostProtocol::UDP_IPv4 }; - QHostAddress m_address { QHostAddress::LocalHost }; + QHostAddress m_address { QHostAddress::Null }; quint16 m_port { 0 }; }; static QKnxNetIpHpaiProxy::Builder builder(); diff --git a/tests/auto/qknxnetiphpai/tst_qknxnetiphpai.cpp b/tests/auto/qknxnetiphpai/tst_qknxnetiphpai.cpp index 38ed92c..f83e29a 100644 --- a/tests/auto/qknxnetiphpai/tst_qknxnetiphpai.cpp +++ b/tests/auto/qknxnetiphpai/tst_qknxnetiphpai.cpp @@ -150,7 +150,7 @@ void tst_QKnxNetIpHpai::testSetFunctions() // Setting code only hpai = builder.setHostProtocol(QKnxNetIp::HostProtocol::TCP_IPv4).create(); QCOMPARE(view.hostProtocol(), QKnxNetIp::HostProtocol::TCP_IPv4); - QCOMPARE(view.hostAddress(), QHostAddress(QHostAddress::LocalHost)); + QCOMPARE(view.hostAddress(), QHostAddress("0.0.0.0")); QCOMPARE(view.port(), quint16(0)); QCOMPARE(view.isValid(), true); @@ -220,7 +220,7 @@ void tst_QKnxNetIpHpai::testDebugStream() } _(myMessageHandler); qDebug() << QKnxNetIpHpaiProxy::builder().create(); - QCOMPARE(s_msg, QString::fromLatin1("0x08017f0000010000")); + QCOMPARE(s_msg, QString::fromLatin1("0x0801000000000000")); qDebug() << QKnxNetIpHpaiProxy::builder() .setHostProtocol(QKnxNetIp::HostProtocol::UDP_IPv4) |