Skip to content

Commit d147e78

Browse files
committed
Small code improvements
1 parent 57c7ae9 commit d147e78

File tree

3 files changed

+20
-7
lines changed

3 files changed

+20
-7
lines changed

src/main.rs

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,31 +99,32 @@ fn main() {
9999
println!("Sending {} ARP requests (waiting at least {}ms, {}ms request interval)", network_size, scan_options.timeout_ms, interval_ms);
100100
}
101101

102-
let finish_sleep = Arc::new(AtomicBool::new(false));
103-
let cloned_finish_sleep = Arc::clone(&finish_sleep);
102+
let has_reached_timeout = Arc::new(AtomicBool::new(false));
103+
let cloned_reached_timeout = Arc::clone(&has_reached_timeout);
104104

105105
ctrlc::set_handler(move || {
106106
eprintln!("[warn] Receiving halt signal, ending scan with partial results");
107-
cloned_finish_sleep.store(true, Ordering::Relaxed);
107+
cloned_reached_timeout.store(true, Ordering::Relaxed);
108108
}).unwrap_or_else(|err| {
109109
eprintln!("Could not set CTRL+C handler ({})", err);
110110
process::exit(1);
111111
});
112112

113+
let source_ip = network::find_source_ip(selected_interface, scan_options.source_ipv4);
114+
113115
// The retry count does right now use a 'brute-force' strategy without
114116
// synchronization process with the already known hosts.
115117
for _ in 0..scan_options.retry_count {
116118

117-
if finish_sleep.load(Ordering::Relaxed) {
119+
if has_reached_timeout.load(Ordering::Relaxed) {
118120
break;
119121
}
120122

121123
let ip_addresses = NetworkIterator::new(&ip_networks, scan_options.randomize_targets);
122-
let source_ip = network::find_source_ip(selected_interface, scan_options.source_ipv4);
123124

124125
for ip_address in ip_addresses {
125126

126-
if finish_sleep.load(Ordering::Relaxed) {
127+
if has_reached_timeout.load(Ordering::Relaxed) {
127128
break;
128129
}
129130

@@ -138,7 +139,7 @@ fn main() {
138139
// (where T is the timeout option). After the sleep phase, the response
139140
// thread will receive a stop request through the 'timed_out' mutex.
140141
let mut sleep_ms_mount: u64 = 0;
141-
while !finish_sleep.load(Ordering::Relaxed) && sleep_ms_mount < scan_options.timeout_ms {
142+
while !has_reached_timeout.load(Ordering::Relaxed) && sleep_ms_mount < scan_options.timeout_ms {
142143

143144
thread::sleep(Duration::from_millis(100));
144145
sleep_ms_mount += 100;

src/time.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,10 @@ pub fn parse_to_milliseconds(time_arg: &str) -> Result<u64, &str> {
4545
}
4646
}
4747

48+
/**
49+
* Format milliseconds to a human-readable string. This will of course give an
50+
* approximation, but will be readable.
51+
*/
4852
pub fn format_milliseconds(milliseconds: u128) -> String {
4953

5054
if milliseconds < 1000 {

src/utils.rs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,10 @@ pub fn display_prescan_details(ip_networks: &[&IpNetwork], selected_interface: &
109109
}
110110
}
111111

112+
/**
113+
* Computes multiple IPv4 networks total size, IPv6 network are not being
114+
* supported by this function.
115+
*/
112116
pub fn compute_network_size(ip_networks: &[&IpNetwork]) -> u128 {
113117

114118
ip_networks.iter().fold(0u128, |total_size, ip_network| {
@@ -209,6 +213,10 @@ struct SerializableGlobalResult {
209213
results: Vec<SerializableResultItem>
210214
}
211215

216+
/**
217+
* Transforms an ARP scan result (including KPI and target details) to a structure
218+
* that can be serialized for export (JSON, YAML, CSV, ...)
219+
*/
212220
fn get_serializable_result(response_summary: ResponseSummary, target_details: Vec<TargetDetails>) -> SerializableGlobalResult {
213221

214222
let exportable_results: Vec<SerializableResultItem> = target_details.into_iter()

0 commit comments

Comments
 (0)