7 releases

0.3.2 Dec 17, 2023
0.3.1 Dec 17, 2023
0.3.0 Jul 27, 2023
0.2.2 May 23, 2021
0.1.0 Aug 29, 2020

#1422 in Network programming

Download history 45/week @ 2023-12-19 14/week @ 2023-12-26 33/week @ 2024-01-02 68/week @ 2024-01-09 5/week @ 2024-02-06 125/week @ 2024-02-13 26/week @ 2024-02-20 43/week @ 2024-02-27 9/week @ 2024-03-05 17/week @ 2024-03-12 20/week @ 2024-03-19 29/week @ 2024-03-26 63/week @ 2024-04-02

131 downloads per month
Used in 2 crates

MIT/Apache

27KB
577 lines

multicast-socket

Single-socket to network across multiple interfaces

This crate provides an abstract struct that allows a single-socket to listen and respond to multicast packets on multiple interfaces.

By default, when binding a regular std::net::UdpSocket to the unspecified ip 0.0.0.0, the socket will only send messages to what the OS considers the deafult interface. This is less than ideal on computers with multiple interfaces (a.k.a. 'multihomed') like laptops, cellphones, desktops with wifi, VPNs, Windows with WSL, Mac with Adapters and various common computer cenarios nowadays.

Instead of creating multiples sockets for each interface, and providing a multi-socket writer, this crate uses a couple of C/C++ OS-specific syscalls and methods to provide a single-socket multi-interface multicast experience.

The create also provides a utility constructor which uses get_if_addrs syscalls to find all available interfaces to bind to it, providing an out-of-the-box multicast multihomed experience.

The crate is designed with IPv4 in mind because I didn't have a test project to validate what IPv6 needs, and this is why the structs are IPv4 specific. If there is a suggestion on how to test this for IPv6, it could be expanded later.

Examples

cargo run --example mdns

Usage

[dependencies]
multicast-socket = "0.2.1"

Targets

Main tier:

  • x86_64-unknown-linux-gnu
  • x86_64-pc-windows-msvc
  • x86_64-apple-darwin

Cross tier:

  • armv7-unknown-linux-gnueabihf
  • aarch64-linux-android
  • mips-unknown-linux-musl
  • x86_64-unknown-linux-musl
  • aarch64-unknown-linux-gnu

License

Licensed under either of

at your option.

Contribution

Unless you explicitly state otherwise, any contribution intentionally submitted for inclusion in the work by you, as defined in the Apache-2.0 license, shall be dual licensed as above, without any additional terms or conditions.

References

Dependencies

~2MB
~41K SLoC