summaryrefslogtreecommitdiff
path: root/src/main.rs
blob: aca7b972ffb6890d31afe86974663585b7ee174b (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
use socket2::{Domain, Protocol, Socket, Type};
use std::mem::MaybeUninit;
use std::net::Ipv4Addr;

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);
    };
    let mut buf = [MaybeUninit::<u8>::uninit()];
    let Ok(_) = sock.recv_from(&mut buf) else {
        eprintln!("Socket::recv_from(): {}", res.err().unwrap());
        std::process::exit(1);
    };
}