Skip to content

Commit

Permalink
add hostnames
Browse files Browse the repository at this point in the history
  • Loading branch information
ilyes-ced committed Dec 8, 2023
1 parent 3ba1f9c commit cd73ac0
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions src/display/ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,9 +177,37 @@ where
utilization: Utilization,
ip_to_host: HashMap<IpAddr, String>,
) {
let hostnames: Vec<String> = self
.state
.excluded_ips
.clone()
.unwrap_or_default()
.iter()
.filter_map(|hf| match hf {
HostFilter::Hostname(s) => Some(s.clone()),
_ => None,
})
.collect();
for (k, v) in &ip_to_host {
if hostnames.contains(v) {
match &self.state.excluded_ips {
None => {}
Some(_) => match k {
IpAddr::V4(ip) => self.push_to_excluded_ips(HostFilter::Ipv4Addr(*ip)),
IpAddr::V6(ip) => self.push_to_excluded_ips(HostFilter::Ipv6Addr(*ip)),
},
}
}
}
self.state.update(connections_to_procs, utilization);
self.ip_to_host.extend(ip_to_host);
}
fn push_to_excluded_ips(&mut self, ip: HostFilter) {
let mut vec = self.state.excluded_ips.take().unwrap_or_default();
vec.push(ip);
println!("\x1b[91m the new vector {:?}\x1b[0m", vec);
self.state.excluded_ips = Some(vec);
}
pub fn set_excluded(&mut self, ex: Option<Vec<HostFilter>>) {
self.state.excluded_ips = ex;
}
Expand Down

0 comments on commit cd73ac0

Please sign in to comment.