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 /src/link.rs | |
parent | d12f01295f4a108073e7e8f9f50fc57257300950 (diff) |
add function to get the numeric index to an interface name0.2.0
Diffstat (limited to 'src/link.rs')
-rw-r--r-- | src/link.rs | 17 |
1 files changed, 17 insertions, 0 deletions
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) +} |