A Rust library to represent and parse IEEE EUI-48 also known as MAC-48 media access control addresses. The IEEE claims trademarks on the names EUI-48 and EUI-64, in which EUI is an abbreviation for Extended Unique Identifier.
Add this to your Cargo.toml
:
```toml [dependencies]
eui48 = "1.0.0" ```
and this to your crate root:
rust
extern crate eui48;
To create a new MAC address and print it out in canonical form:
```rust extern crate eui48; use eui48::{MacAddress, Eui48};
fn main() { let eui: Eui48 = [ 0x12, 0x34, 0x56, 0xAB, 0xCD, 0xEF ]; let mac = MacAddress::new( eui );
println!("{}", mac.to_canonical());
println!("{}", mac.to_hex_string());
println!("{}", mac.to_dot_string());
println!("{}", mac.to_hexadecimal());
println!("{}", mac.to_interfaceid());
println!("{}", mac.to_link_local());
let mac = MacAddress::parse_str( "01-02-03-0A-0b-0f" ).expect("Parse error {}");
let mac = MacAddress::parse_str( "01:02:03:0A:0b:0f" ).expect("Parse error {}");
let mac = MacAddress::parse_str( "0102.030A.0b0f" ).expect("Parse error {}");
let mac = MacAddress::parse_str( "0x1234567890ab" ).expect("Parse error {}");
} ```
01-02-03-04-05-06
unless a compile time feature disp_hexstring
is enabled, then the default format is of the form 01:02:03:04:05:06
.Version 1.0.0 and above allows a more flexible parsing of MAC address strings, compliments of Stan Drozd: * Enables the library's caller to parse the MACs that don't follow fixed-length MAC address convention (I'm looking at you, ebtables!). In general, the parsing function tries harder to interpret a given string than before. * Rewrite parse_str to use a regex and be more lenient (now it permits one-off string chopping errors and mixed delimiters are accepted as long as we manage to read 6 bytes) * Exchange the InvalidCharacter error enum value for InvalidByteCount - InvalidCharacter is no longer supported. See versions >=0.5.0 and < 1.0.0 if you need legacy behavior.