I need to listen 2 UDP multicast addresses. One is 233.113.216.75:21001
and the other is 233.113.216.70:21001
. Due to their ports are same I can't bind to them separately.
use std::net::UdpSocket;
let socket = UdpSocket::bind("0.0.0.0:21001").unwrap();
udp_socket.join_multicast_v4(&Ipv4Addr::new(233, 113, 216, 70), &Ipv4Addr::UNSPECIFIED)?;
udp_socket.join_multicast_v4(&Ipv4Addr::new(233, 113, 216, 75), &Ipv4Addr::UNSPECIFIED)?;
I can listen both of the feed with udp_socket.recv_from(&mut self.buffer)
without any issues. However, I can't know the incoming packet's multicast group. recv_from
returns the IP address of the client, not the multicast group. I need to know which group the incoming packet is belong to.
Is there any way to get the multicast group of the incoming datagram?
Thanks for your help in advance.
I tried to use the addr from recv_from, but it shows the source IP address.
@Jmb 's answer in the comment fixes the issue.
Don't bind to 0.0.0.0, instead bind to 233.113.216.70:21001 and 233.113.216.75:21001.