Skip to content

Commit cd73ac0

Browse files
committed
add hostnames
1 parent 3ba1f9c commit cd73ac0

1 file changed

Lines changed: 28 additions & 0 deletions

File tree

src/display/ui.rs

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -177,9 +177,37 @@ where
177177
utilization: Utilization,
178178
ip_to_host: HashMap<IpAddr, String>,
179179
) {
180+
let hostnames: Vec<String> = self
181+
.state
182+
.excluded_ips
183+
.clone()
184+
.unwrap_or_default()
185+
.iter()
186+
.filter_map(|hf| match hf {
187+
HostFilter::Hostname(s) => Some(s.clone()),
188+
_ => None,
189+
})
190+
.collect();
191+
for (k, v) in &ip_to_host {
192+
if hostnames.contains(v) {
193+
match &self.state.excluded_ips {
194+
None => {}
195+
Some(_) => match k {
196+
IpAddr::V4(ip) => self.push_to_excluded_ips(HostFilter::Ipv4Addr(*ip)),
197+
IpAddr::V6(ip) => self.push_to_excluded_ips(HostFilter::Ipv6Addr(*ip)),
198+
},
199+
}
200+
}
201+
}
180202
self.state.update(connections_to_procs, utilization);
181203
self.ip_to_host.extend(ip_to_host);
182204
}
205+
fn push_to_excluded_ips(&mut self, ip: HostFilter) {
206+
let mut vec = self.state.excluded_ips.take().unwrap_or_default();
207+
vec.push(ip);
208+
println!("\x1b[91m the new vector {:?}\x1b[0m", vec);
209+
self.state.excluded_ips = Some(vec);
210+
}
183211
pub fn set_excluded(&mut self, ex: Option<Vec<HostFilter>>) {
184212
self.state.excluded_ips = ex;
185213
}

0 commit comments

Comments
 (0)