added mac_to_string

This commit is contained in:
asxalex 2024-10-06 15:44:33 +08:00
parent ea5d463216
commit b7aafc68d6

View File

@ -3,3 +3,10 @@ pub type Mac = [u8; 6];
pub const BROADCAST_MAC: Mac = [0xff, 0xff, 0xff, 0xff, 0xff, 0xff];
pub const MULTICAST_MAC: Mac = [0x01, 0x00, 0x5E, 0x00, 0x00, 0x00]; /* First 3 bytes are meaningful */
pub const IPV6_MULTICAST_MAC: Mac = [0x33, 0x33, 0x00, 0x00, 0x00, 0x00]; /* First 2 bytes are meaningful */
pub fn mac_to_string(mac: &Mac) -> String {
format!(
"[{:02x}:{:02x}:{:02x}:{:02x}:{:02x}:{:02x}]",
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]
)
}