Skip to content

Commit

Permalink
join multicast group "localhost" in case of network_mode disabled
Browse files Browse the repository at this point in the history
  • Loading branch information
rex-schilasky committed Oct 27, 2023
1 parent 90c5566 commit 3bd45ad
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 23 deletions.
19 changes: 9 additions & 10 deletions ecal/core/src/io/udp_receiver_asio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,8 @@ namespace eCAL
return;
}

// define endpoint
asio::ip::udp::endpoint ext_endpoint(asio::ip::udp::v4(), static_cast<unsigned short>(attr_.port));
asio::ip::udp::endpoint loc_endpoint(asio::ip::address::from_string("127.0.0.1"), static_cast<unsigned short>(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<unsigned short>(attr_.port));
{
asio::error_code ec;
m_socket.open(listen_endpoint.protocol(), ec);
Expand Down Expand Up @@ -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;
Expand Down
22 changes: 9 additions & 13 deletions ecal/core/src/io/udp_receiver_npcap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<uint16_t>(attr_.port)))
if (!m_socket.bind(Udpcap::HostAddress::Any(), static_cast<uint16_t>(attr_.port)))
{
std::cerr << "CUDPReceiverPcap: Unable to bind socket." << std::endl;
return;
Expand All @@ -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;
Expand Down

0 comments on commit 3bd45ad

Please sign in to comment.