This commit is contained in:
lda
2025-12-06 02:21:33 +07:00 Unverified
parent 10c75dcffb
commit afffcd5528
10 changed files with 120 additions and 141 deletions
+15 -8
View File
@@ -19,17 +19,14 @@
// prefix seems to be a cidr. both 6 and 4 works. idfk dog
use std::{io, process::Output};
use anyhow::Context;
use super::AddrOutput;
pub async fn get(dev: Option<&str>) -> anyhow::Result<Vec<AddrOutput>> {
let mut cmd = tokio::process::Command::new("ip");
cmd.args(["-j", "address", "show"]);
if let Some(d) = dev {
cmd.args(["dev", d]);
}
let output = cmd.output().await?;
let output = _get(dev).await.context("Can not run command")?;
if !output.status.success() {
anyhow::bail!(String::from_utf8_lossy(&output.stderr).into_owned());
@@ -37,3 +34,13 @@ pub async fn get(dev: Option<&str>) -> anyhow::Result<Vec<AddrOutput>> {
Ok(serde_json::from_slice(&output.stdout)?)
}
pub async fn _get(dev: Option<&str>) -> io::Result<Output> {
let mut cmd = tokio::process::Command::new("ip");
cmd.args(["-j", "address", "show"]);
if let Some(d) = dev {
cmd.args(["dev", d]);
}
cmd.output().await
}
+13 -9
View File
@@ -1,8 +1,8 @@
//! idk what to put here
use std::net::IpAddr;
use std::{io, net::IpAddr, process::Output};
use anyhow::bail;
use anyhow::{Context, bail};
use super::{NUDState, NeighborItem};
@@ -19,6 +19,16 @@ pub async fn get(
dev: Option<&str>,
nud: &[NUDState],
) -> anyhow::Result<Vec<NeighborItem>> {
let output = _get(ip, dev, nud).await.context("Can not run command")?;
if !output.status.success() {
bail!(String::from_utf8_lossy(&output.stderr).into_owned())
} else {
Ok(serde_json::from_slice(&output.stdout)?)
}
}
pub async fn _get(ip: Option<IpAddr>, dev: Option<&str>, nud: &[NUDState]) -> io::Result<Output> {
let mut cmd = tokio::process::Command::new("ip");
cmd.args(["-j", "neigh", "show"]);
@@ -34,11 +44,5 @@ pub async fn get(
cmd.arg(nud.to_string());
}
let output = cmd.output().await?;
if !output.status.success() {
bail!(String::from_utf8_lossy(&output.stderr).into_owned())
} else {
Ok(serde_json::from_slice(&output.stdout)?)
}
cmd.output().await
}