Files
roowho2/src/bin/roowhod.rs
h7x4 4d3afef6ab
Some checks failed
Build and test / check (push) Failing after 53s
Build and test / test (push) Failing after 1m22s
Build and test / build (push) Successful in 1m44s
Build and test / docs (push) Failing after 1m41s
WIP
2026-01-04 20:59:29 +09:00

33 lines
984 B
Rust

use std::net::SocketAddrV4;
use roowho2_lib::proto::Whod;
const RWHOD_BROADCAST_PORT: u16 = 513;
#[tokio::main]
async fn main() -> anyhow::Result<()> {
let addr = SocketAddrV4::new(std::net::Ipv4Addr::UNSPECIFIED, RWHOD_BROADCAST_PORT);
let socket = tokio::net::UdpSocket::bind(addr).await?;
socket.set_broadcast(true)?;
let mut buf = [0u8; Whod::MAX_SIZE];
loop {
let (len, src) = socket.recv_from(&mut buf).await?;
if len < Whod::HEADER_SIZE {
eprintln!(
"Received too short packet from {src}: {len} bytes (needs to be at least {} bytes)",
Whod::HEADER_SIZE
);
continue;
}
match Whod::from_bytes(&buf[..len]) {
Ok(whod) => {
println!("Received whod packet from {src}:\n{whod:#?}");
}
Err(err) => {
eprintln!("Failed to parse whod packet from {src}: {err}");
}
}
}
}