diff options
author | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-15 15:21:36 +0100 |
---|---|---|
committer | HimbeerserverDE <himbeerserverde@gmail.com> | 2023-11-15 15:21:36 +0100 |
commit | fa4720e74d3f93f6c908e479d9fbb90d54b9ba8c (patch) | |
tree | 2a82682230e3f275d9c23c12f276139843ab66fe | |
parent | d12f01295f4a108073e7e8f9f50fc57257300950 (diff) |
add function to get the numeric index to an interface name0.2.0
-rw-r--r-- | Cargo.toml | 2 | ||||
-rw-r--r-- | src/blocking.rs | 1 | ||||
-rw-r--r-- | src/link.rs | 17 |
3 files changed, 19 insertions, 1 deletions
@@ -1,6 +1,6 @@ [package] name = "rsdsl_netlinklib" -version = "0.1.2" +version = "0.2.0" edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html diff --git a/src/blocking.rs b/src/blocking.rs index 587dd1b..8483452 100644 --- a/src/blocking.rs +++ b/src/blocking.rs @@ -56,6 +56,7 @@ pub mod link { blockify!(wait_up, link::wait_up, link: String); blockify!(exists -> bool, link::exists, link: String); blockify!(wait_exists, link::wait_exists, link: String); + blockify!(index -> u32, link::index, link: String); } #[cfg(feature = "route")] diff --git a/src/link.rs b/src/link.rs index 209b8a6..ffbaa99 100644 --- a/src/link.rs +++ b/src/link.rs @@ -147,3 +147,20 @@ pub async fn wait_exists(link: String) -> Result<()> { Ok(()) } + +/// Returns the index of an interface. +pub async fn index(link: String) -> Result<u32> { + let (conn, handle, _) = rtnetlink::new_connection()?; + tokio::spawn(conn); + + let link = handle + .link() + .get() + .match_name(link.clone()) + .execute() + .try_next() + .await? + .ok_or(Error::LinkNotFound(link))?; + + Ok(link.header.index) +} |