use socket2::{Domain, Protocol, Socket, Type}; use std::net::Ipv4Addr; struct Init; struct Master; struct Backup; impl Init { fn new() -> Init { Init {} } } trait VRRPv2StateMachine { fn next(&self) -> impl VRRPv2StateMachine; } impl VRRPv2StateMachine for Init { fn next(&self) -> impl VRRPv2StateMachine { Master {} } } impl VRRPv2StateMachine for Master { fn next(&self) -> impl VRRPv2StateMachine { Backup {} } } impl VRRPv2StateMachine for Backup { fn next(&self) -> impl VRRPv2StateMachine { Init {} } } fn run() { let sm = Init::new(); loop { let _ = sm.next(); } } fn main() { let res = Socket::new(Domain::IPV4, Type::RAW, Some(Protocol::from(112))); let Ok(sock) = res else { eprintln!("Socket::new(): {}", res.err().unwrap()); std::process::exit(1); }; let res = sock.join_multicast_v4( &Ipv4Addr::new(224, 0, 0, 18), &Ipv4Addr::UNSPECIFIED, ); let Ok(_) = res else { eprintln!("join_multicast_v4(): {}", res.err().unwrap()); std::process::exit(1); }; }