Open
Description
So far tested on:
- windows 11: works
- macos 14.4: doesn't work
The following code
use std::net::{Ipv6Addr, SocketAddrV6, UdpSocket};
use std::str::FromStr;
fn main() {
let local = SocketAddrV6::new(Ipv6Addr::UNSPECIFIED, 61666, 0, 0);
let multicast = Ipv6Addr::from_str("ff02::fb").unwrap();
let udp = UdpSocket::bind(&local).expect("Unable to bind!");
udp.join_multicast_v6(&multicast, 0).expect("Unable to join to multicast...");
match udp.send_to(b"Hello", "[::1]:61666") { // Trying to send a packet to multicast address...
Ok(bytes_sent) => println!("Sent {} bytes", bytes_sent),
Err(err) => eprintln!("Error sending data: {}", err),
}
}
produces the following error:
Unable to join to multicast...: Os { code: 49, kind: AddrNotAvailable, message: "Can't assign requested address" }
It is expected for the socket to join the group (in documentation it also says setting interface to 0 allows for the OS to decide on the interface).
However instead of that, on macOS the above error happens. On windows however, it does not and works as expected.
Meta
rustc --version --verbose
:
rustc 1.77.2 (25ef9e3d8 2024-04-09)
binary: rustc
commit-hash: 25ef9e3d85d934b27d9dada2f9dd52b1dc63bb04
commit-date: 2024-04-09
host: aarch64-apple-darwin
release: 1.77.2
LLVM version: 17.0.6