joecalsend/src/main.rs

40 lines
1.1 KiB
Rust
Raw Normal View History

2025-07-05 18:53:55 +00:00
use joecalsend::{Client, JoecalState, error, models::device::DeviceInfo};
2025-07-05 17:12:09 +00:00
use local_ip_address::local_ip;
use network_interface::{Addr, NetworkInterface, NetworkInterfaceConfig, V4IfAddr};
2025-07-04 00:00:11 +00:00
#[tokio::main]
2025-07-05 17:12:09 +00:00
async fn main() -> error::Result<()> {
2025-07-04 00:00:11 +00:00
let device = DeviceInfo::default();
2025-07-04 22:15:52 +00:00
dbg!(&device);
2025-07-04 00:00:11 +00:00
2025-07-05 18:53:55 +00:00
let std::net::IpAddr::V4(ip) = local_ip()? else {
unreachable!()
};
// for enumerating subnet peers when multicast fails (https://github.com/localsend/protocol?tab=readme-ov-file#32-http-legacy-mode)
let mut network_ip = ip;
let nifs = NetworkInterface::show().unwrap();
for addr in nifs.into_iter().flat_map(|i| i.addr) {
if let Addr::V4(V4IfAddr {
ip: ifip,
netmask: Some(netmask),
..
}) = addr
&& ip == ifip
{
network_ip = ip & netmask;
break;
}
}
dbg!(network_ip);
2025-07-04 22:15:52 +00:00
let client = Client::with_config(device, 53317, "/home/ardent/joecalsend".into())
.await
.unwrap();
2025-07-04 00:00:11 +00:00
let (h1, h2, h3) = client.start().await.unwrap();
2025-07-05 17:12:09 +00:00
2025-07-04 22:15:52 +00:00
let _ = tokio::join!(h1, h2, h3);
Ok(())
2025-07-04 00:00:11 +00:00
}