dhcpd_parser

Crates.iodhcpd_parser
lib.rsdhcpd_parser
version0.4.3
sourcesrc
created_at2019-09-24 18:23:07.458185
updated_at2019-10-17 11:11:15.523875
descriptionParser for dhcpd configuration files. Currently supports only dhcpd.leases file of the OpenBSD base implementation
homepagehttps://github.com/mskrip/dhcpd-parser
repositoryhttps://github.com/mskrip/dhcpd-parser.git
max_upload_size
id167344
size34,189
Marián Skrip (mskrip)

documentation

README

dhcpd config parser

Rust library for parsing OpenBSD dhcpd configuration files.

The library currently supports only OpenBSD implementation of the dhcpd.leases file format. See man pages

Example usage

use dhcpd_parser::parser;
use dhcpd_parser::parser::LeasesMethods;


let res = parser::parse("
    lease 192.168.0.2 {
        starts 2 2019/01/01 22:00:00 UTC;
        ends 2 2019/01/01 22:00:00 UTC;
        hardware type 11:11:11:11:11:11;
        uid Client1;
        client-hostname \"CLIENTHOSTNAME\";
        hostname \"TESTHOSTNAME\";
        abandoned;
    }

    lease 192.168.0.3 {
        starts 1 1985/01/01 00:00:00 UTC;
        hardware type 22:22:22:22:22:22;
        uid Client2;
        hostname \"TESTHOSTNAME\";
    }
".to_string()).expect("This should be a correct lease file");

let leases = res.unwrap().leases;

assert_eq!(
    leases[0].hostname.as_ref().unwrap(),
    "TESTHOSTNAME",
);
assert_eq!(
    leases[1].dates.starts.unwrap().to_string(),
    "Monday 1985/01/01 00:00:00",
);
assert!(leases[1].dates.ends.is_none());

assert!(leases[0].abandoned);
assert!(!leases[1].abandoned);
assert_eq!(
    leases.client_hostnames(),
    ["CLIENTHOSTNAME".to_owned()]
        .iter()
        .cloned()
        .collect(),
);
Commit count: 25

cargo fmt