X-Git-Url: https://code.octet-stream.net/netwatcher/blobdiff_plain/db2bad72106542d4e785e6ed277e73ac8a11c9bc..addb589bf51bdc5b5e253c0b5cbd47394e293ba7:/src/list_unix.rs?ds=inline diff --git a/src/list_unix.rs b/src/list_unix.rs index a6b2bd3..fad4306 100644 --- a/src/list_unix.rs +++ b/src/list_unix.rs @@ -1,11 +1,9 @@ use std::fmt::Write; use std::{collections::HashMap, net::IpAddr}; -use block2::Block; -use nix::libc::c_long; use nix::{ifaddrs::getifaddrs, net::if_::if_nametoindex}; -use crate::{Error, IfIndex, Interface}; +use crate::{Error, Interface, List}; struct CandidateInterface { name: String, @@ -14,7 +12,7 @@ struct CandidateInterface { ips: Vec, } -pub(crate) fn list_interfaces() -> Result, Error> { +pub(crate) fn list_interfaces() -> Result { let addrs = getifaddrs().map_err(|_| Error::Internal)?; let mut candidates = HashMap::new(); @@ -59,16 +57,16 @@ pub(crate) fn list_interfaces() -> Result, Error> { }) }) .collect(); - Ok(ifs) + Ok(List(ifs)) } fn format_mac(bytes: &[u8]) -> Result { let mut mac = String::with_capacity(bytes.len() * 3); - for i in 0..bytes.len() { + for (i, b) in bytes.iter().enumerate() { if i != 0 { write!(mac, ":").map_err(|_| Error::Internal)?; } - write!(mac, "{:02X}", bytes[i]).map_err(|_| Error::Internal)?; + write!(mac, "{:02X}", b).map_err(|_| Error::Internal)?; } Ok(mac) }