feat(examples): allow selecting the multicast interface#2
Merged
Conversation
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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_reassemblejoins the group on the chosen interface (join_multicast_v4(&group, &interface)).send_multicastbinds 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) andIP_MULTICAST_IFboth 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.stdhas noIP_MULTICAST_IF, so the sender binds to the interface address — reliable on Windows, documented as a hint on other platforms.Usage
Testing
cargo fmt --all --checkcleancargo clippy --examples -- -D warningsclean