Skip to content

Commit

Permalink
Add README.md with example
Browse files Browse the repository at this point in the history
  • Loading branch information
shutton committed Mar 11, 2024
1 parent 7c1c30a commit d97f7e3
Showing 1 changed file with 29 additions and 0 deletions.
29 changes: 29 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# macos-routing-table

A basic parser and route testing API for macOS devices. Parses a static or live routing table (via the `netstat` command) and provides an interface to inspect tht table, and to determine which gateway and interface would be used to route traffic to a given address.

Analyzes both the IPv4 and IPv6 routing tables. Minimal support for zones (parsing only at this time).

## Example - find the gateway for an address

``` rust
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 d97f7e3

Please sign in to comment.