Skip to content

Commit

Permalink
Add simple example
Browse files Browse the repository at this point in the history
  • Loading branch information
shutton committed Mar 11, 2024
1 parent 0b03ace commit 130e484
Showing 1 changed file with 19 additions and 0 deletions.
19 changes: 19 additions & 0 deletions examples/simple.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
use anyhow::Result;
use macos_routing_table::{RouteEntry, RoutingTable};

#[tokio::main]
async fn main() -> Result<()> {
let rt = RoutingTable::load_from_netstat().await?;
let addr = "1.1.1.1".parse()?;

if let Some(RouteEntry {
net_if, gateway, ..
}) = rt.find_route_entry(addr)
{
println!("{addr:?} => {gateway} via {net_if}");
} else {
println!("No route to {addr:?}");
}

Ok(())
}

0 comments on commit 130e484

Please sign in to comment.