diff options
-rw-r--r-- | src/main.rs | 70 |
1 files changed, 45 insertions, 25 deletions
diff --git a/src/main.rs b/src/main.rs index f7eba0b..bc1e6a8 100644 --- a/src/main.rs +++ b/src/main.rs @@ -1,28 +1,48 @@ -// #[derive(Debug)] -// enum VRRPv2State { -// Initialize, -// Backup, -// Master, -// } - -// struct StateMachine { -// state: VRRPv2State, -// } - -// impl StateMachine { -// fn new() -> Self { -// StateMachine { -// state: VRRPv2State::Initialize, -// } -// } -// fn transit_to(&mut self, new_state: VRRPv2State) { -// std::println!("vvrpd: {:?} -> {:?}", self.state, new_state); -// self.state = new_state; -// } -// } +use socket2::{Domain, Protocol, Socket, Type}; + +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 mut sm = StateMachine::new(); - // sm.transit_to(VRRPv2State::Master); - // sm.transit_to(VRRPv2State::Backup); + 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); + }; } |