gping: Fails on FreeBSD 12.1

thread '<unnamed>' panicked at 'Error pinging: Unsupported OS Unknown', /root/.cargo/registry/src/github.com-1ecc6299db9ec823/gping-0.1.6/src/main.rs:122:33

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Reactions: 5
  • Comments: 16 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Oops, forgot bsd.rs:

use crate::{Parser, PingResult, Pinger};
use regex::Regex;
use std::time::Duration;

lazy_static! {
    static ref RE: Regex = Regex::new(r"time=(?:(?P<time>[0-9\.]+)\s+ms)").unwrap();
}

#[derive(Default)]
pub struct BSDPinger {
    interval: Duration,
}

impl Pinger for BSDPinger {
    fn set_interval(&mut self, interval: Duration) {
        self.interval = interval;
    }

    fn ping_args(&self, target: String) -> Vec<String> {
        vec![
            format!("-i{:.1}", self.interval.as_millis() as f32 / 1_000_f32),
            target,
        ]
    }
}

#[derive(Default)]
pub struct BSDParser {}

impl Parser for BSDParser {
    fn parse(&self, line: String) -> Option<PingResult> {
        if line.starts_with("PING ") {
            return None;
        }
        if line.starts_with("Request timeout") {
            return Some(PingResult::Timeout(line));
        }
        self.extract_regex(&RE, line)
    }
}

Sure, if you look at the patch @yonas posted it doesn’t actually include the BSD specific code, hence the errors.