gping
gping copied to clipboard
pinger: refactor "OS" detection?
i use Gentoo and i got Error: Unsupported OS Gentoo Linux, also in Gentoo ping may be from both iputils and busybox (related to #140)
for me this error appears in gping-1.3.2, in gping-1.3.1 everything works fine
here is code which choose what ping executable to use, but there are may be endless number of linux distros and they can have different ping implementation
https://github.com/orf/gping/blob/9697f84ad3ad47d0d25b4cffe1822fec13653ade/pinger/src/lib.rs#L142-L184
so my suggestion is:
- detect most popular ping version (from
iputilsor frombusybox) - don't match all supported OS by
os_info(Type::), just matchType::Alpine,Type::Macosand othervice use "default" ping
here is dirty example of how first suggestion can be implemented:
pub fn ping_with_interval(addr: String, interval: Duration) -> Result<mpsc::Receiver<PingResult>> {
#[cfg(windows)]
{
let mut p = windows::WindowsPinger::default();
p.set_interval(interval);
return p.start::<windows::WindowsParser>(addr);
}
#[cfg(unix)]
{
return if cfg!(target_os = "macos") {
let mut p = macos::MacOSPinger::default();
p.set_interval(interval);
p.start::<macos::MacOSParser>(addr)
} else {
if busybox_ping() {
let mut p = linux::LinuxPinger::default();
p.set_interval(interval);
p.start::<linux::LinuxParser>(addr)
} else if iptools_ping() {
let mut p =linux::AlpinePinger::default();
p.set_interval(interval);
p.start::<linux::LinuxParser>(addr)
} else {
Err(anyhow!("unsupported ping"))?
}
}
}
Err(anyhow!("some error msg about unsupported os"))?
}