smac 0.1.0

A small MAC address parser in no_std Rust
Documentation
  • Coverage
  • 28.57%
    2 out of 7 items documented0 out of 5 items with examples
  • Size
  • Source code size: 7.4 kB This is the summed size of all the files inside the crates.io package for this release.
  • Documentation size: 1.16 MB This is the summed size of all files generated by rustdoc for all configured targets
  • Ø build duration
  • this release: 11s Average build duration of successful builds.
  • all releases: 10s Average build duration of successful builds in releases after 2024-10-23.
  • Links
  • AlexanderFlesher/smac
    1 0 0
  • crates.io
  • Dependencies
  • Versions
  • Owners
  • AlexanderFlesher

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.