From d4e2e0048263d65c5096fca16b130bd04c7dcc1c Mon Sep 17 00:00:00 2001 From: Denis CLAVIER <30313991+Crivaledaz@users.noreply.github.com> Date: Tue, 24 Jan 2023 12:46:10 +0100 Subject: [PATCH] Fix multicast leave group (#3929) * Fix multicast leave group * Add test to join and leave a multicast group Co-authored-by: Denis CLAVIER --- Net/src/MulticastSocket.cpp | 3 +-- Net/testsuite/src/MulticastSocketTest.cpp | 3 +++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/Net/src/MulticastSocket.cpp b/Net/src/MulticastSocket.cpp index f624026f4..e48f3ed35 100644 --- a/Net/src/MulticastSocket.cpp +++ b/Net/src/MulticastSocket.cpp @@ -257,8 +257,7 @@ NetworkInterface MulticastSocket::findFirstInterface(const IPAddress& groupAddre void MulticastSocket::leaveGroup(const IPAddress& groupAddress) { - NetworkInterface intf; - leaveGroup(groupAddress, intf); + leaveGroup(groupAddress, findFirstInterface(groupAddress)); } diff --git a/Net/testsuite/src/MulticastSocketTest.cpp b/Net/testsuite/src/MulticastSocketTest.cpp index 56559f44c..942cc49f0 100644 --- a/Net/testsuite/src/MulticastSocketTest.cpp +++ b/Net/testsuite/src/MulticastSocketTest.cpp @@ -51,6 +51,8 @@ void MulticastSocketTest::testMulticast() { MulticastEchoServer echoServer; MulticastSocket ms(SocketAddress::IPv4); + SocketAddress multicastAddress("234.2.2.2", 4040); + ms.joinGroup(multicastAddress.host()); ms.setReceiveTimeout(Poco::Timespan(5, 0)); int n = ms.sendTo("hello", 5, echoServer.group()); assertTrue (n == 5); @@ -58,6 +60,7 @@ void MulticastSocketTest::testMulticast() n = ms.receiveBytes(buffer, sizeof(buffer)); assertTrue (n == 5); assertTrue (std::string(buffer, n) == "hello"); + ms.leaveGroup(multicastAddress.host()); ms.close(); } catch (Poco::NotImplementedException&)