Skip to content

Commit 3104c2d

Browse files
committed
Moving to 2021 edition with code optimizations
1 parent 40a445b commit 3104c2d

File tree

4 files changed

+22
-11
lines changed

4 files changed

+22
-11
lines changed

Cargo.toml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ description = "A minimalistic ARP scan tool"
44
license = "AGPL-3.0-or-later"
55
version = "0.12.0"
66
authors = ["Saluki"]
7-
edition = "2018"
7+
edition = "2021"
88
readme = "README.md"
99
homepage = "https://github.com/Saluki/arp-scan-rs"
1010
repository = "https://github.com/Saluki/arp-scan-rs"
1111
keywords = ["arp", "scan", "network", "security"]
1212
categories = ["command-line-utilities"]
13+
exclude = ["/.semaphore", "/data", "/release.sh", ".*"]
1314

1415
[dependencies]
1516

src/network.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ pub fn compute_network_configuration<'a>(interfaces: &'a [NetworkInterface], sca
7474
Some(name) => String::from(name),
7575
None => {
7676

77-
let name = utils::select_default_interface(&interfaces).map(|interface| interface.name);
77+
let name = utils::select_default_interface(interfaces).map(|interface| interface.name);
7878

7979
match name {
8080
Some(name) => name,
@@ -237,9 +237,14 @@ pub fn send_arp_request(tx: &mut Box<dyn DataLinkSender>, interface: &NetworkInt
237237
ethernet_packet.set_payload(arp_packet.packet_mut());
238238
}
239239

240-
tx.send_to(&ethernet_packet.to_immutable().packet(), Some(interface.clone()));
240+
tx.send_to(ethernet_packet.to_immutable().packet(), Some(interface.clone()));
241241
}
242242

243+
/**
244+
* A network iterator for iterating over multiple network ranges in with a
245+
* low-memory approach. This iterator was crafted to allow iteration over huge
246+
* network ranges (192.168.0.0/16) without consuming excessive memory.
247+
*/
243248
pub struct NetworkIterator {
244249
current_iterator: Option<ipnetwork::IpNetworkIterator>,
245250
networks: Vec<IpNetwork>,
@@ -268,6 +273,11 @@ impl NetworkIterator {
268273
}
269274
}
270275

276+
/**
277+
* The functions below are not public and only used by the Iterator trait
278+
* to help keep the next() code clean.
279+
*/
280+
271281
fn has_no_items_left(&self) -> bool {
272282
self.current_iterator.is_none() && self.networks.is_empty() && self.random_pool.is_empty()
273283
}
@@ -391,7 +401,7 @@ pub fn receive_arp_responses(rx: &mut Box<dyn DataLinkReceiver>, options: Arc<Sc
391401
};
392402
packet_count += 1;
393403

394-
let ethernet_packet = match EthernetPacket::new(&arp_buffer[..]) {
404+
let ethernet_packet = match EthernetPacket::new(arp_buffer) {
395405
Some(packet) => packet,
396406
None => continue
397407
};

src/utils.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -158,13 +158,13 @@ pub fn display_scan_results(response_summary: ResponseSummary, mut target_detail
158158
for detail in target_details.iter() {
159159

160160
let hostname: &str = match &detail.hostname {
161-
Some(hostname) => &hostname,
162-
None if !options.resolve_hostname => &"(disabled)",
163-
None => &""
161+
Some(hostname) => hostname,
162+
None if !options.resolve_hostname => "(disabled)",
163+
None => ""
164164
};
165165
let vendor: &str = match &detail.vendor {
166-
Some(vendor) => &vendor,
167-
None => &""
166+
Some(vendor) => vendor,
167+
None => ""
168168
};
169169
println!("| {: <15} | {: <18} | {: <h_max$} | {: <v_max$} |", detail.ipv4, detail.mac, hostname, vendor, h_max=hostname_len, v_max=vendor_len);
170170
}

src/vendor.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,10 @@ impl Vendor {
6161
eprintln!("Could not read CSV record ({})", err);
6262
process::exit(1);
6363
});
64-
let potential_oui = record.get(1).unwrap_or(&"");
64+
let potential_oui = record.get(1).unwrap_or("");
6565

6666
if vendor_oui.eq(potential_oui) {
67-
return Some(record.get(2).unwrap_or(&"(no vendor)").to_string())
67+
return Some(record.get(2).unwrap_or("(no vendor)").to_string())
6868
}
6969
}
7070

0 commit comments

Comments
 (0)