surge_ping/icmp/
mod.rs

1use std::fmt;
2
3pub mod icmpv4;
4pub mod icmpv6;
5
6/// Represents the ICMP reply packet.
7#[derive(Debug)]
8pub enum IcmpPacket {
9    /// An ICMPv4 packet abstraction.
10    V4(icmpv4::Icmpv4Packet),
11    /// An ICMPv6 packet abstraction.
12    V6(icmpv6::Icmpv6Packet),
13}
14
15impl IcmpPacket {
16    pub fn get_identifier(&self) -> PingIdentifier {
17        match self {
18            IcmpPacket::V4(packet) => packet.get_identifier(),
19            IcmpPacket::V6(packet) => packet.get_identifier(),
20        }
21    }
22
23    pub fn get_sequence(&self) -> PingSequence {
24        match self {
25            IcmpPacket::V4(packet) => packet.get_sequence(),
26            IcmpPacket::V6(packet) => packet.get_sequence(),
27        }
28    }
29}
30
31#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
32pub struct PingIdentifier(pub u16);
33
34impl PingIdentifier {
35    pub fn into_u16(self) -> u16 {
36        self.0
37    }
38}
39
40impl fmt::Display for PingIdentifier {
41    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
42        self.0.fmt(f)
43    }
44}
45
46impl From<u16> for PingIdentifier {
47    fn from(ident: u16) -> Self {
48        Self(ident)
49    }
50}
51
52#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
53pub struct PingSequence(pub u16);
54
55impl PingSequence {
56    pub fn into_u16(self) -> u16 {
57        self.0
58    }
59}
60
61impl fmt::Display for PingSequence {
62    fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
63        self.0.fmt(f)
64    }
65}
66
67impl From<u16> for PingSequence {
68    fn from(seq_cnt: u16) -> Self {
69        Self(seq_cnt)
70    }
71}