Skip to content

Commit

Permalink
Optimize get ips
Browse files Browse the repository at this point in the history
  • Loading branch information
zu1k committed Nov 4, 2021
1 parent 2130221 commit 43c24f0
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions src/utils.rs
Original file line number Diff line number Diff line change
@@ -1,18 +1,18 @@
use std::{io, net::IpAddr, vec};
use std::{io, net::IpAddr};

fn get_ips() -> Vec<IpAddr> {
let mut ips = vec![];
let ifs = pnet_datalink::interfaces();
for i in ifs {
if i.is_up() && i.is_multicast() {
for ip in i.ips {
if ip.is_ipv4() {
ips.push(ip.ip())
}
}
}
}
ips
pnet_datalink::interfaces()
.iter()
.filter(|i| i.is_up() && i.is_multicast())
.map(|i| -> Vec<IpAddr> {
i.ips
.iter()
.filter(|ip| ip.is_ipv4())
.map(|ip| ip.ip())
.collect()
})
.flatten()
.collect()
}

pub fn select_ip() -> Option<String> {
Expand Down

0 comments on commit 43c24f0

Please sign in to comment.