Function multicast_socket::all_ipv4_interfaces
source · pub fn all_ipv4_interfaces() -> Result<Vec<Ipv4Addr>>
Examples found in repository?
examples/mdns.rs (line 10)
4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38
fn main() {
let mdns_multicast_address = SocketAddrV4::new([224, 0, 0, 251].into(), 5353);
// Validate that building with options works with the public API
let with_options = MulticastSocket::with_options(
mdns_multicast_address,
multicast_socket::all_ipv4_interfaces()
.expect("could not fetch all interfaces for options"),
multicast_socket::MulticastOptions {
..Default::default()
},
)
.expect("validate that we are starting with options");
drop(with_options);
let socket = MulticastSocket::all_interfaces(mdns_multicast_address)
.expect("could not create and bind socket");
let data = vec![1, 2];
socket
.broadcast(&data)
.expect("could not broadcast message to ips being listened");
loop {
if let Ok(message) = socket.receive() {
dbg!(&message.interface);
dbg!(&message.origin_address);
let data = vec![9, 8, 7];
socket
.send(&data, &message.interface)
.expect("could not send data");
};
}
}