use super::constants::*;
use super::operation::ArpOperation;
pub fn arp_hardware_type_label(hardware_type: u16) -> Option<&'static str> {
match hardware_type {
ARP_HRD_ETHERNET => Some("ethernet"),
ARP_HRD_IEEE_802 => Some("ieee-802"),
ARP_HRD_FIBRE_CHANNEL => Some("fibre-channel"),
ARP_HRD_ATM => Some("atm"),
ARP_HRD_MAPOS => Some("mapos"),
ARP_HRD_INFINIBAND => Some("infiniband"),
_ => None,
}
}
pub fn arp_protocol_type_label(protocol_type: u16) -> Option<&'static str> {
match protocol_type {
ARP_PRO_IPV4 => Some("ipv4"),
_ => None,
}
}
pub(in crate::protocols::link) fn operation_summary(operation: u16) -> String {
match ArpOperation::from_opcode(operation) {
Some(named) => named.label().to_string(),
None => operation.to_string(),
}
}
pub(in crate::protocols::link) fn operation_inspection(operation: u16) -> String {
match ArpOperation::from_opcode(operation) {
Some(named) => format!("{} ({operation})", named.label()),
None => operation.to_string(),
}
}
pub(in crate::protocols::link) fn hardware_type_inspection(hardware_type: u16) -> String {
match arp_hardware_type_label(hardware_type) {
Some(label) => format!("{label} (0x{hardware_type:04x})"),
None => format!("0x{hardware_type:04x}"),
}
}
pub(in crate::protocols::link) fn protocol_type_inspection(protocol_type: u16) -> String {
match arp_protocol_type_label(protocol_type) {
Some(label) => format!("{label} (0x{protocol_type:04x})"),
None => format!("0x{protocol_type:04x}"),
}
}