1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
// SPDX-License-Identifier: MIT
#![cfg(feature = "tokio_socket")]
use futures::stream::TryStreamExt;
use rtnetlink::{new_connection, Error, Handle, IpVersion};
#[tokio::main]
async fn main() -> Result<(), ()> {
let (connection, handle, _) = new_connection().unwrap();
tokio::spawn(connection);
println!("dumping neighbours");
if let Err(e) = dump_neighbours(handle.clone()).await {
eprintln!("{e}");
}
println!();
Ok(())
}
async fn dump_neighbours(handle: Handle) -> Result<(), Error> {
let mut neighbours = handle
.neighbours()
.get()
.set_family(IpVersion::V4)
.execute();
while let Some(route) = neighbours.try_next().await? {
println!("{route:?}");
}
Ok(())
}
|