diff --git a/src/NameService.cxx b/src/NameService.cxx index 2930276689901b03b2c723e1cb3f37f18558e30f..b11f78403dce20c89e0f845aa6cdf7e7c2730d89 100644 --- a/src/NameService.cxx +++ b/src/NameService.cxx @@ -74,11 +74,11 @@ namespace daq { auto& mask = std::get<1>(network); if(addr.is_v4() && intf->family() == AF_INET) { - auto addr4(addr.to_v4()); - auto mask4(mask.to_v4()); + auto addr4(addr.to_v4()); + auto mask4(mask.to_v4()); - if(htonl((addr4.to_ulong() & mask4.to_ulong())) == intf->network()) { - info.Addresses.push_back(intf->address_string() + '/' + intf->netmask_string()); + if(htonl(addr4.to_ulong() & mask4.to_ulong()) == (intf->network() & htonl(mask4.to_ulong()))) { + info.Addresses.push_back(intf->address_string() + '/' + mask4.to_string()); } } else if(addr.is_v6() && intf->family() == AF_INET6) { @@ -124,7 +124,7 @@ namespace daq { // compare IPV4 address if(addr.is_v4() && intf->family() == AF_INET) { - if(htonl((addr.to_v4().to_ulong() & mask.to_v4().to_ulong())) == intf->network()) { + if(htonl(addr.to_v4().to_ulong() & mask.to_v4().to_ulong()) == (intf->network() & htonl(mask.to_v4().to_ulong()))) { // found one, first match will be used return true; } @@ -280,6 +280,13 @@ namespace daq { { auto addr = boost::asio::ip::address::from_string(netmask).to_v4(); + // hack to pass additional mask for finding the multicast interface to use + std::string mc_mask("255.255.255.255"); + if(getenv("TDAQ_ASYNCMSG_MULTICAST_MASK")) { + mc_mask = getenv("TDAQ_ASYNCMSG_MULTICAST_MASK"); + } + auto mask = boost::asio::ip::address::from_string(mc_mask).to_v4(); + auto interfaces = daq::transport::Interface::interfaces(); for(auto intf : interfaces) { if(!intf->has_flag(IFF_UP) || intf->has_flag(IFF_LOOPBACK)) { @@ -294,7 +301,7 @@ namespace daq { continue; } - if(intf->network() == htonl(addr.to_ulong())) { + if((intf->network() & htonl(mask.to_ulong())) == htonl(addr.to_ulong())) { return boost::asio::ip::address::from_string(intf->address_string()); } } diff --git a/src/UDPSession.cxx b/src/UDPSession.cxx index 17f1582419a8df6ebf86945392d894c6e00c9a48..d7736a41e08f8843c9fb3bdd9582fc4509259ee4 100644 --- a/src/UDPSession.cxx +++ b/src/UDPSession.cxx @@ -210,8 +210,15 @@ void UDPSession::setOutgoingInterface(const boost::asio::ip::address& ip_address boost::asio::ip::multicast::outbound_interface option(ip_address.to_v4()); m_socket.set_option(option); - // we never want to go beyond one hop (I hope) - boost::asio::ip::multicast::hops hops_option(1); + // TTL Scope + // ---------------------------------------------------------------------- + // 0 Restricted to the same host. Won't be output by any interface. + // 1 Restricted to the same subnet. Won't be forwarded by a router. + // <32 Restricted to the same site, organization or department. + // <64 Restricted to the same region. + // <128 Restricted to the same continent. + // <255 Unrestricted in scope. Global. + boost::asio::ip::multicast::hops hops_option(31); m_socket.set_option(hops_option); }