| Crates.io | smac |
| lib.rs | smac |
| version | 0.1.0 |
| created_at | 2025-08-24 02:04:16.885059+00 |
| updated_at | 2025-08-24 02:04:16.885059+00 |
| description | A small MAC address parser in no_std Rust |
| homepage | |
| repository | https://github.com/AlexanderFlesher/smac |
| max_upload_size | |
| id | 1808016 |
| size | 7,871 |
The MacAddress struct is six bytes, and implements FromStr and
Display. The FromStr implementation expects a string of six hex bytes
unseparated, or separated by space (' ') or colon (':'). The following
is a basic example of parsing a MAC address using the ip tool on Linux.
use once_cell::sync::Lazy;
use regex::Regex;
use subprocess::Exec;
use smac::{MacAddress, ParseError};
fn read_mac(interface: &str) -> Result<MacAddress, ParseError> {
static MAC_PATTERN: Lazy<Regex> =
Lazy::new(|| Regex::new("link/ether ((([a-fA-F0-9]){2}[:]){5}[a-fA-F0-9]{2})").unwrap());
let command_result = match Exec::cmd("ip").args(&["link", "show", interface]).capture() {
Ok(capture) => capture.stdout_str(),
Err(_) => return Err(ParseError),
};
match MAC_PATTERN.captures(&command_result) {
Some(matches) => matches[1].parse::<MacAddress>(),
None => return Err(ParseError),
}
}
smac uses no_std and only the unit tests depend on alloc.