8 releases

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

#1411 in Network programming

Download history 78/week @ 2024-08-04 58/week @ 2024-08-11 250/week @ 2024-08-18 205/week @ 2024-08-25 96/week @ 2024-09-01 51/week @ 2024-09-08 254/week @ 2024-09-15 213/week @ 2024-09-22 101/week @ 2024-09-29 172/week @ 2024-10-06 191/week @ 2024-10-13 11/week @ 2024-10-20 30/week @ 2024-10-27 34/week @ 2024-11-03 86/week @ 2024-11-10 71/week @ 2024-11-17

221 downloads per month
Used in 2 crates

MIT/Apache

26KB
549 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

~1.9–8.5MB
~76K SLoC