smac

Crates.iosmac
lib.rssmac
version0.1.0
created_at2025-08-24 02:04:16.885059+00
updated_at2025-08-24 02:04:16.885059+00
descriptionA small MAC address parser in no_std Rust
homepage
repositoryhttps://github.com/AlexanderFlesher/smac
max_upload_size
id1808016
size7,871
Alexander Flesher (AlexanderFlesher)

documentation

README

smac

A small MAC address parsing library in no_std Rust

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.

Commit count: 4

cargo fmt