Skip to content

Commit f1ef3be

Browse files
authored
feat: preserve IP address order (#749)
as part of #651, IP addresses are deduplicated; as this uses a `BTreeSet`, the original order is not necessarily retained. use [`retain()`](https://doc.rust-lang.org/std/vec/struct.Vec.html#method.retain) to remove duplicated and/or excluded IPs, mutating the original list of IPs but preserving the original order.
1 parent 71091bf commit f1ef3be

File tree

1 file changed

+6
-6
lines changed

1 file changed

+6
-6
lines changed

src/address.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -70,18 +70,18 @@ pub fn parse_addresses(input: &Opts) -> Vec<IpAddr> {
7070
}
7171

7272
// Finally, craft a list of addresses to be excluded from the scan.
73-
let mut excluded_ips: Vec<IpAddr> = Vec::new();
73+
let mut excluded_ips: BTreeSet<IpAddr> = BTreeSet::new();
7474
if let Some(exclude_addresses) = &input.exclude_addresses {
7575
for addr in exclude_addresses {
7676
excluded_ips.extend(parse_address(addr, &backup_resolver));
7777
}
7878
}
7979

80-
ips.into_iter()
81-
.collect::<BTreeSet<_>>()
82-
.into_iter()
83-
.filter(|ip| !excluded_ips.contains(ip))
84-
.collect()
80+
// Remove duplicated/excluded IPs.
81+
let mut seen = BTreeSet::new();
82+
ips.retain(|ip| seen.insert(*ip) && !excluded_ips.contains(ip));
83+
84+
ips
8585
}
8686

8787
/// Given a string, parse it as a host, IP address, or CIDR.

0 commit comments

Comments
 (0)