Skip to main content

sniffnet_packet_parser/
arp_type.rs

1use std::fmt::{Display, Formatter};
2
3use etherparse::ArpOperation;
4
5#[derive(Copy, Clone, PartialEq, Eq, Hash, Debug)]
6/// The ARP message type.
7pub enum ArpType {
8    Request,
9    Reply,
10    Unknown,
11}
12
13impl ArpType {
14    #[must_use]
15    pub(crate) fn from_etherparse(arp_operation: ArpOperation) -> ArpType {
16        match arp_operation {
17            ArpOperation(1) => Self::Request,
18            ArpOperation(2) => Self::Reply,
19            ArpOperation(_) => Self::Unknown,
20        }
21    }
22}
23
24impl Display for ArpType {
25    fn fmt(&self, f: &mut Formatter<'_>) -> std::fmt::Result {
26        write!(
27            f,
28            "{}",
29            match self {
30                ArpType::Request => "Request",
31                ArpType::Reply => "Reply",
32                ArpType::Unknown => "?",
33            }
34        )
35    }
36}