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 32 33 34 35 36 37 38
|
// SPDX-License-Identifier: MIT
#![cfg(feature = "tokio_socket")]
use futures::stream::TryStreamExt;
use rtnetlink::{new_connection, Error, Handle};
#[tokio::main]
async fn main() -> Result<(), ()> {
let (connection, handle, _) = new_connection().unwrap();
tokio::spawn(connection);
let link = "lo".to_string();
println!("dumping address for link \"{link}\"");
if let Err(e) = dump_addresses(handle, link).await {
eprintln!("{e}");
}
Ok(())
}
async fn dump_addresses(handle: Handle, link: String) -> Result<(), Error> {
let mut links = handle.link().get().match_name(link.clone()).execute();
if let Some(link) = links.try_next().await? {
let mut addresses = handle
.address()
.get()
.set_link_index_filter(link.header.index)
.execute();
while let Some(msg) = addresses.try_next().await? {
println!("{msg:?}");
}
Ok(())
} else {
eprintln!("link {link} not found");
Ok(())
}
}
|