Skip to content

feat(examples): allow selecting the multicast interface#2

Merged
SpaceK33z merged 2 commits into
mainfrom
kees/example-interface-selection
Jul 13, 2026
Merged

feat(examples): allow selecting the multicast interface#2
SpaceK33z merged 2 commits into
mainfrom
kees/example-interface-selection

Conversation

@SpaceK33z

@SpaceK33z SpaceK33z commented Jul 13, 2026

Copy link
Copy Markdown
Collaborator

Summary

Ports the intent of upstream madmappersoftware/Ponk#16 ("Add network interface selection for multicast send/receive") to this Rust crate.

Both multicast examples hard-coded INADDR_ANY, so on Windows a Wi-Fi interface is often not selected by default and PONK multicast never crosses the WLAN. Both examples now take an optional local interface IPv4 address:

  • receive_reassemble joins the group on the chosen interface (join_multicast_v4(&group, &interface)).
  • send_multicast binds to the interface address to steer egress.

Omitting the argument preserves the previous all-interfaces behavior; an invalid address is a hard error rather than a silent revert to the default.

Scope: why this lives in the examples, not the library

This crate is a zero-dependency, #![forbid(unsafe_code)] codec/reassembler where socket ownership and I/O deliberately remain with the application. The upstream PR's interface enumeration (getifaddrs / GetAdaptersAddresses) and IP_MULTICAST_IF both require unsafe OS calls, so they are intentionally kept out of the library. The examples are the crate's I/O-owning layer and exhibit the exact Windows/WLAN failure the upstream PR fixes, so interface selection is applied there as an application-level policy. std has no IP_MULTICAST_IF, so the sender binds to the interface address — reliable on Windows, documented as a hint on other platforms.

Usage

cargo run --example receive_reassemble -- 192.168.1.20
cargo run --example send_multicast -- 192.168.1.20

Testing

  • cargo fmt --all --check clean
  • cargo clippy --examples -- -D warnings clean
  • Verified end-to-end: send/receive over a real interface, missing arg still defaults to all interfaces, invalid arg exits non-zero with a clear error.

The send_multicast and receive_reassemble examples hardcoded INADDR_ANY,
so on Windows a Wi-Fi interface is often not selected by default and PONK
multicast never crosses the WLAN. Both examples now take an optional local
interface IPv4 address: the sender binds to it to pin egress, the receiver
joins the group on it. Omitting the address preserves the previous
all-interfaces behavior; an unparseable address warns and falls back.

Interface selection stays an application-level policy in the examples,
keeping the codec socket-agnostic and unsafe-free. Ports the intent of
madmappersoftware/Ponk#16 to this Rust crate's I/O-owning layer.
A typo in the interface argument silently reverted to INADDR_ANY — the
exact default-selection behavior the argument exists to override — so the
example looked broken over WLAN rather than reporting the typo. An invalid
address is now a hard error; a missing argument still defaults to all
interfaces. Also scope the sender's bind() comment: it reliably steers
multicast egress on Windows, but binding a unicast source address is not
IP_MULTICAST_IF and is only a hint on other platforms.
@SpaceK33z
SpaceK33z merged commit 5c28d05 into main Jul 13, 2026
4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant