use std::io;
#[cfg(feature = "net")]
fn main() -> io::Result<()> {
use dos::net::{NotificationType, get_ip_forward_entry, notify_route_change};
use std::thread;
use std::time::Duration;
println!("Starting network route change monitor...");
let _handle = notify_route_change(
None, |notification_type| {
match notification_type {
NotificationType::InitialNotification => {
println!("[INIT] Route change monitoring registered successfully");
}
NotificationType::AddInstance(row) => {
let dest = row.destination_prefix();
let next_hop = row.next_hop();
let updated = get_ip_forward_entry(row.interface_luid(), dest, next_hop);
let row = updated.as_ref().unwrap_or(row);
println!(
"[ADD] Route added - LUID: {:#x}, Destination: {:?}, Metric: {}",
*row.interface_luid(),
row.destination_prefix(),
row.metric(),
);
}
NotificationType::DeleteInstance(row) => {
let dest = row.destination_prefix();
let next_hop = row.next_hop();
let updated = get_ip_forward_entry(row.interface_luid(), dest, next_hop);
let row = updated.as_ref().unwrap_or(row);
println!(
"[DELETE] Route removed - LUID: {:#x}, Destination: {:?}",
*row.interface_luid(),
row.destination_prefix(),
);
}
NotificationType::ParameterNotification(row) => {
let dest = row.destination_prefix();
let next_hop = row.next_hop();
let updated = get_ip_forward_entry(row.interface_luid(), dest, next_hop);
let row = updated.as_ref().unwrap_or(row);
println!(
"[DELETE] Route changed - LUID: {:#x}, Destination: {:?}",
*row.interface_luid(),
row.destination_prefix(),
);
}
}
},
true, )?;
println!("Monitor registered");
println!();
loop {
thread::sleep(Duration::from_millis(100));
}
}
#[cfg(not(feature = "net"))]
fn main() -> io::Result<()> {
Ok(())
}