summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: ed619425c82a20f31512758560761f86a745d833 (plain)
1
2
3
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
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);
    };
}