adds logic to selectively compile for windows or linux and handle the respective ping return codes.
0 = good on linux 1 = good on wintendos
This commit is contained in:
parent
f9cf88911f
commit
7bd745635b
@ -39,21 +39,31 @@ fn spawn_single_ping(request: PingRequest, sender: Sender<PingResult>) {
|
|||||||
let local_request = request.clone();
|
let local_request = request.clone();
|
||||||
thread::spawn(move || {
|
thread::spawn(move || {
|
||||||
|
|
||||||
|
let mut result = 0;
|
||||||
|
let mut success = true;
|
||||||
let start_time = SystemTime::now();
|
let start_time = SystemTime::now();
|
||||||
|
#[cfg(any(target_os="windows"))] {
|
||||||
let result = Command::new("/usr/bin/ping").arg(request.target.to_string())
|
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("-c 1")
|
||||||
.arg("-4")
|
.arg("-4")
|
||||||
.arg("-w 10")
|
.arg("-w 10")
|
||||||
.arg("-W 1")
|
.arg("-W 1")
|
||||||
.output().unwrap().status.code().unwrap_or(255);
|
.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));
|
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;
|
let success = ping_duration.as_millis() >= SECONDS_BETWEEN_PING as u128 && result == 0;
|
||||||
|
|
||||||
|
|
||||||
// println!("Attempt for for {}", local_request.target);
|
// 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,
|
last_rtt: response.rtt,
|
||||||
};
|
};
|
||||||
state.targets[index] = new_state.clone();
|
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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user