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
impl ProbeBackend
Sourcepub fn new() -> Self
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
impl Default for ProbeBackend
Source§impl Reachability for ProbeBackend
impl Reachability for ProbeBackend
Source§fn ping(&self, ip: IpAddr, opts: PingOpts) -> NcResult<PingResult>
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>
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>
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>
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>>
fn trace(&self, ip: IpAddr, opts: TraceOpts) -> NcResult<Vec<Hop>>
Run a traceroute to
ip using opts.Source§fn capabilities(&self) -> ProbeCapabilities
fn capabilities(&self) -> ProbeCapabilities
What this backend can actually do on this system.
Auto Trait Implementations§
impl Freeze for ProbeBackend
impl RefUnwindSafe for ProbeBackend
impl Send for ProbeBackend
impl Sync for ProbeBackend
impl Unpin for ProbeBackend
impl UnsafeUnpin for ProbeBackend
impl UnwindSafe for ProbeBackend
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more