From 3986a7b40c0043ec33c2c2b7cf5c615c65599997 Mon Sep 17 00:00:00 2001 From: "Matthias P. Braendli" Date: Mon, 22 Jul 2024 16:52:00 +0200 Subject: Rework STI/EDI/UDP multicast input group join --- src/input/Edi.cpp | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/input/Edi.cpp b/src/input/Edi.cpp index 3838541..fc380d8 100644 --- a/src/input/Edi.cpp +++ b/src/input/Edi.cpp @@ -81,6 +81,7 @@ void Edi::open(const std::string& name) { const std::regex re_udp("udp://:([0-9]+)"); const std::regex re_udp_multicast("udp://@([0-9.]+):([0-9]+)"); + const std::regex re_udp_multicast_bindto("udp://([0-9.])+@([0-9.]+):([0-9]+)"); const std::regex re_tcp("tcp://(.*):([0-9]+)"); lock_guard lock(m_mutex); @@ -97,13 +98,31 @@ void Edi::open(const std::string& name) m_udp_sock.reinit(udp_port); m_udp_sock.setBlocking(false); } + else if (std::regex_match(name, m, re_udp_multicast_bindto)) { + const string bind_to = m[1].str(); + const string multicast_address = m[2].str(); + const int udp_port = std::stoi(m[3].str()); + + m_input_used = InputUsed::UDP; + if (IN_MULTICAST(ntohl(inet_addr(multicast_address.c_str())))) { + m_udp_sock.init_receive_multicast(udp_port, bind_to, multicast_address); + } + else { + throw runtime_error(string("Address ") + multicast_address + " is not a multicast address"); + } + m_udp_sock.setBlocking(false); + } else if (std::regex_match(name, m, re_udp_multicast)) { const string multicast_address = m[1].str(); const int udp_port = std::stoi(m[2].str()); m_input_used = InputUsed::UDP; - m_udp_sock.reinit(udp_port); + if (IN_MULTICAST(ntohl(inet_addr(multicast_address.c_str())))) { + m_udp_sock.init_receive_multicast(udp_port, "0.0.0.0", multicast_address); + } + else { + throw runtime_error(string("Address ") + multicast_address + " is not a multicast address"); + } m_udp_sock.setBlocking(false); - m_udp_sock.joinGroup(multicast_address.c_str()); } else if (std::regex_match(name, m, re_tcp)) { m_input_used = InputUsed::TCP; -- cgit v1.2.3