From d97f7e3b6e3d36d422eafdb246f24a6be2d2cb43 Mon Sep 17 00:00:00 2001 From: Scott Hutton Date: Mon, 11 Mar 2024 10:17:07 -0700 Subject: [PATCH] Add README.md with example --- README.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..b38a7b1 --- /dev/null +++ b/README.md @@ -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(()) +} +```