aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--Cargo.toml2
-rw-r--r--src/blocking.rs1
-rw-r--r--src/link.rs17
3 files changed, 19 insertions, 1 deletions
diff --git a/Cargo.toml b/Cargo.toml
index dfbbc07..dad0f17 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -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)
+}