Skip to content

fix handling of port 0 on multicast locator #1968

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions io/zenoh-links/zenoh-link-udp/src/multicast.rs
Original file line number Diff line number Diff line change
Expand Up @@ -191,7 +191,7 @@ impl LinkManagerMulticastUdp {
config: Config<'_>,
bind_socket: Option<&str>,
dscp: Option<u32>,
) -> ZResult<(UdpSocket, UdpSocket, SocketAddr)> {
) -> ZResult<(UdpSocket, SocketAddr, UdpSocket, SocketAddr)> {
let domain = match mcast_addr.ip() {
IpAddr::V4(_) => Domain::IPV4,
IpAddr::V6(_) => Domain::IPV6,
Expand Down Expand Up @@ -382,8 +382,14 @@ impl LinkManagerMulticastUdp {
.local_addr()
.map_err(|e| zerror!("{}: {}", mcast_addr, e))?;
assert_eq!(ucast_addr.ip(), local_addr.ip());
// We may have bind to port 0, so we need to retrieve the actual port
let mcast_port = mcast_sock
.local_addr()
.map_err(|e| zerror!("{}: {}", mcast_addr, e))?
.port();
let mcast_addr = SocketAddr::new(mcast_addr.ip(), mcast_port);

Ok((mcast_sock, ucast_sock, ucast_addr))
Ok((mcast_sock, mcast_addr, ucast_sock, ucast_addr))
}
}

Expand All @@ -404,9 +410,9 @@ impl LinkManagerMulticastTrait for LinkManagerMulticastUdp {
.new_link_inner(&maddr, endpoint.config(), bind_socket, dscp)
.await
{
Ok((mcast_sock, ucast_sock, ucast_addr)) => {
Ok((mcast_sock, mcast_addr, ucast_sock, ucast_addr)) => {
let link = Arc::new(LinkMulticastUdp::new(
ucast_addr, ucast_sock, maddr, mcast_sock,
ucast_addr, ucast_sock, mcast_addr, mcast_sock,
));

return Ok(LinkMulticast(link));
Expand Down
Loading