diff --git a/src/bin/threads.rs b/src/bin/threads.rs index 0cd3961..bc11d51 100644 --- a/src/bin/threads.rs +++ b/src/bin/threads.rs @@ -39,21 +39,31 @@ fn spawn_single_ping(request: PingRequest, sender: Sender) { let local_request = request.clone(); thread::spawn(move || { + let mut result = 0; + let mut success = true; let start_time = SystemTime::now(); - - let result = Command::new("/usr/bin/ping").arg(request.target.to_string()) - .arg("-c 1") - .arg("-4") - .arg("-w 10") - .arg("-W 1") - .output().unwrap().status.code().unwrap_or(255); + #[cfg(any(target_os="windows"))] { + result = Command::new("c:/windows/system32/ping.exe").arg(request.target.to_string()) + .arg("-n 1") + .arg("-w 10") + .arg("-4") + .output().unwrap().status.code().unwrap_or(255); + success = result == 1; + } + #[cfg(any(target_os="linux"))] { + result = Command::new("/usr/bin/ping").arg(request.target.to_string()) + .arg("-c 1") + .arg("-4") + .arg("-w 10") + .arg("-W 1") + .output().unwrap().status.code().unwrap_or(255); + success = result == 0; + } let ping_duration = SystemTime::now().duration_since(start_time).unwrap_or(Duration::from_secs(600)); - + sender.send(PingResult { target: local_request.target, success: result == 0, rtt: ping_duration.as_millis() as u32 }).expect("Unable to send response"); let success = ping_duration.as_millis() >= SECONDS_BETWEEN_PING as u128 && result == 0; - // println!("Attempt for for {}", local_request.target); - sender.send(PingResult { target: local_request.target, success, rtt: ping_duration.as_millis() as u32 }) }); } @@ -131,7 +141,7 @@ fn main() { last_rtt: response.rtt, }; state.targets[index] = new_state.clone(); - println!("({}) Found the target -> {}/{}/{}", state.targets.clone().len(), new_state.target, new_state.alive, new_state.last_rtt); + // println!("({}) Found the target -> {}/{}/{}", state.targets.clone().len(), new_state.target, new_state.alive, new_state.last_rtt); } } }