aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorHimbeerserverDE <himbeerserverde@gmail.com>2023-11-15 15:21:36 +0100
committerHimbeerserverDE <himbeerserverde@gmail.com>2023-11-15 15:21:36 +0100
commitfa4720e74d3f93f6c908e479d9fbb90d54b9ba8c (patch)
tree2a82682230e3f275d9c23c12f276139843ab66fe /src
parentd12f01295f4a108073e7e8f9f50fc57257300950 (diff)
add function to get the numeric index to an interface name0.2.0
Diffstat (limited to 'src')
-rw-r--r--src/blocking.rs1
-rw-r--r--src/link.rs17
2 files changed, 18 insertions, 0 deletions
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)
+}