From 3bd45ad19ce5cc8f124b2006b96c8d0b2670f043 Mon Sep 17 00:00:00 2001 From: rex-schilasky <49162693+rex-schilasky@users.noreply.github.com> Date: Fri, 27 Oct 2023 08:52:28 +0200 Subject: [PATCH] join multicast group "localhost" in case of network_mode disabled --- ecal/core/src/io/udp_receiver_asio.cpp | 19 +++++++++---------- ecal/core/src/io/udp_receiver_npcap.cpp | 22 +++++++++------------- 2 files changed, 18 insertions(+), 23 deletions(-) diff --git a/ecal/core/src/io/udp_receiver_asio.cpp b/ecal/core/src/io/udp_receiver_asio.cpp index cce8ef354d..7ae158e328 100644 --- a/ecal/core/src/io/udp_receiver_asio.cpp +++ b/ecal/core/src/io/udp_receiver_asio.cpp @@ -43,16 +43,8 @@ namespace eCAL return; } - // define endpoint - asio::ip::udp::endpoint ext_endpoint(asio::ip::udp::v4(), static_cast(attr_.port)); - asio::ip::udp::endpoint loc_endpoint(asio::ip::address::from_string("127.0.0.1"), static_cast(attr_.port)); - asio::ip::udp::endpoint& listen_endpoint = ext_endpoint; - if (m_localhost) - { - listen_endpoint = loc_endpoint; - } - // create socket + const asio::ip::udp::endpoint listen_endpoint(asio::ip::udp::v4(), static_cast(attr_.port)); { asio::error_code ec; m_socket.open(listen_endpoint.protocol(), ec); @@ -110,7 +102,14 @@ namespace eCAL } // join multicast group - AddMultiCastGroup(attr_.ipaddr.c_str()); + if (m_localhost) + { + AddMultiCastGroup("127.0.0.1"); + } + else + { + AddMultiCastGroup(attr_.ipaddr.c_str()); + } // state successful creation m_created = true; diff --git a/ecal/core/src/io/udp_receiver_npcap.cpp b/ecal/core/src/io/udp_receiver_npcap.cpp index e0db705d0e..4bf005ac49 100644 --- a/ecal/core/src/io/udp_receiver_npcap.cpp +++ b/ecal/core/src/io/udp_receiver_npcap.cpp @@ -40,19 +40,8 @@ namespace eCAL std::cerr << "CUDPReceiverPcap: Unable to set receive buffer size." << std::endl; } - // define host address - Udpcap::HostAddress host_address; - if (m_localhost) - { - host_address = Udpcap::HostAddress::LocalHost(); - } - else - { - host_address = Udpcap::HostAddress::Any(); - } - // bind socket - if (!m_socket.bind(host_address, static_cast(attr_.port))) + if (!m_socket.bind(Udpcap::HostAddress::Any(), static_cast(attr_.port))) { std::cerr << "CUDPReceiverPcap: Unable to bind socket." << std::endl; return; @@ -65,7 +54,14 @@ namespace eCAL } // join multicast group - AddMultiCastGroup(attr_.ipaddr.c_str()); + if (m_localhost) + { + AddMultiCastGroup("127.0.0.1"); + } + else + { + AddMultiCastGroup(attr_.ipaddr.c_str()); + } // state successful creation m_created = true;