rust-lang / rust-lang/rust

[MacOS] UDP Multicast: Can't assign requested address on interface 0 (as suggested in the documentation)

Open
#123,715 17 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

C-bug O-macos T-libs
Dominant language
Rust
Stars
119k
Forks
16.1k
PR merge metrics
PR metrics pending

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

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by reproducing the example on macOS and trace the UdpSocket::join_multicast_v6 call with interface 0. Compare the observed behavior with the documentation and Windows result; done means the documented interface-selection behavior is consistent or the documentation clearly reflects the supported behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
networking, operating-systems
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.