From b6154631638364cce8b67b3ee4a033d8bd2c1033 Mon Sep 17 00:00:00 2001 From: Nbiba Bedis Date: Fri, 19 Jun 2020 23:20:11 +0100 Subject: [PATCH] (part2)parse /proc/net/dev manually instead of using ifconfig because its not portable --- src/eltrafico_main/utils.rs | 43 ++++++++++++------------------------- 1 file changed, 14 insertions(+), 29 deletions(-) diff --git a/src/eltrafico_main/utils.rs b/src/eltrafico_main/utils.rs index 5f7c187..e75ceb6 100644 --- a/src/eltrafico_main/utils.rs +++ b/src/eltrafico_main/utils.rs @@ -49,35 +49,20 @@ fn tifconfig() { } // ifconfig pub fn ifconfig() -> CatchAll> { - let output = run!("ifconfig -a")?; - let output = String::from_utf8(output.stdout)?; - - // get the first line of each paragraph of the output then parse it - let output: Vec<&str> = output.lines().collect(); - let interfaces = output - // split by paragraph - .split(|l| l.is_empty()) - // get the first line of each paragraph - .filter_map(|p| p.iter().next()) - // parse the interface name and status - .filter_map(|row| { - let status = if row.contains("UP") { - Status::Up - } else { - Status::Down - }; - let name = match row.split(':').next() { - Some(name) => name, - None => return None, - }; - Some(Interface { - name: name.to_string(), - status, - }) - }) - .collect(); - - Ok(interfaces) + let raw_data = std::fs::read_to_string("/proc/net/dev")?; + + //TODO: actually parse statue + raw_data + .lines() + .skip(2) + .filter_map(|l| l.split(':').next()) + .map(|name| { + Ok(Interface { + name: name.trim().to_string(), + status: Status::Down, + }) + }) + .collect() } #[derive(PartialEq, Eq, Debug)]