Skip to main content

ProbeBackend

Struct ProbeBackend 

Source
pub struct ProbeBackend { /* private fields */ }
Expand description

Reachability backend: ICMP ping, TCP connect, TLS handshake, HTTP HEAD, and traceroute. All methods are synchronous.

Implementations§

Source§

impl ProbeBackend

Source

pub fn new() -> Self

Detect available capabilities and return a new backend.

Examples found in repository?
examples/trace.rs (line 13)
10fn main() {
11    let target = std::env::args().nth(1).unwrap_or_else(|| "1.1.1.1".into());
12    let ip: IpAddr = target.parse().expect("pass an IP literal");
13    let b = ProbeBackend::new();
14    println!("caps = {:?}", b.capabilities());
15
16    println!("--- ping {ip} ---");
17    let r = b
18        .ping(
19            ip,
20            PingOpts {
21                count: 3,
22                timeout: Duration::from_millis(1000),
23            },
24        )
25        .expect("ping");
26    println!(
27        "sent={} recv={} min={:?} avg={:?} max={:?}",
28        r.sent, r.received, r.rtt_min, r.rtt_avg, r.rtt_max
29    );
30
31    println!("--- trace {ip} ---");
32    let hops = b
33        .trace(
34            ip,
35            TraceOpts {
36                max_hops: 15,
37                timeout_per_hop: Duration::from_millis(1000),
38                proto: L4Proto::Tcp,
39            },
40        )
41        .expect("trace");
42    for h in &hops {
43        println!(
44            "  {:2} {:>20} {:>10}",
45            h.ttl,
46            h.ip.map(|i| i.to_string()).unwrap_or_else(|| "*".into()),
47            h.rtt
48                .map(|d| format!("{:.1}ms", d.as_secs_f64() * 1000.0))
49                .unwrap_or_else(|| "-".into())
50        );
51    }
52}

Trait Implementations§

Source§

impl Default for ProbeBackend

Source§

fn default() -> Self

Returns the “default value” for a type. Read more
Source§

impl Reachability for ProbeBackend

Source§

fn ping(&self, ip: IpAddr, opts: PingOpts) -> NcResult<PingResult>

Send ICMP echo requests to ip according to opts.
Source§

fn tcp_connect( &self, sa: SocketAddr, timeout: Duration, ) -> NcResult<TcpProbeResult>

Attempt a TCP three-way handshake to sa within timeout.
Source§

fn tls_handshake( &self, sa: SocketAddr, sni: &str, timeout: Duration, ) -> NcResult<TlsProbeResult>

Perform a TLS handshake to sa with the given SNI within timeout.
Source§

fn http_head(&self, url: &Url, timeout: Duration) -> NcResult<HttpProbeResult>

Issue an HTTP HEAD request to url within timeout.
Source§

fn trace(&self, ip: IpAddr, opts: TraceOpts) -> NcResult<Vec<Hop>>

Run a traceroute to ip using opts.
Source§

fn capabilities(&self) -> ProbeCapabilities

What this backend can actually do on this system.

Auto Trait Implementations§

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = Infallible

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.