1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
use core::time::Duration;
#[cfg(feature = "use_serde")]
use serde::{Deserialize, Serialize};
use crate::errors::Errors;
use crate::ipv4;
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
pub struct Configuration {
pub count: u32,
pub interval: Duration,
pub timeout: Duration,
pub data_size: u32,
pub tos: u8,
}
impl Default for Configuration {
fn default() -> Self {
Configuration {
count: 5,
interval: Duration::from_secs(1),
timeout: Duration::from_secs(1),
data_size: 56,
tos: 0,
}
}
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
pub struct Info {
pub addr: ipv4::Ipv4Addr,
pub seqno: u32,
pub ttl: u8,
pub elapsed_time: Duration,
pub recv_len: u32,
}
#[derive(Clone, Debug, PartialEq)]
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
pub enum Reply {
Timeout,
Success(Info),
}
#[derive(Clone, Debug, PartialEq, Default)]
#[cfg_attr(feature = "use_serde", derive(Serialize, Deserialize))]
pub struct Summary {
pub transmitted: u32,
pub received: u32,
pub time: Duration,
}
pub trait Ping: Errors {
fn ping(&mut self, ip: ipv4::Ipv4Addr, conf: &Configuration) -> Result<Summary, Self::Error>;
fn ping_details<F: Fn(&Summary, &Reply)>(
&mut self,
ip: ipv4::Ipv4Addr,
conf: &Configuration,
reply_callback: &F,
) -> Result<Summary, Self::Error>;
}