#linux #parser #host #dns #conf #file #config

unixism

A set of tools for working with linux from Rust

1 unstable release

0.1.0 Apr 5, 2024

#10 in #conf

MIT license

17KB
370 lines

Work with linux from Rust.

Software License Crates.io

Installation

cargo add unixism

Contents

resolv.conf

Parsing an /etc/resolv.conf file.

use unixism::dns;

fn main() {
    let config = dns::resolv::parse_default().unwrap();

    for nameserver in config.nameservers {
        println!("{}", nameserver.to_string());
    }

    for domain in config.search_domains {
        println!("{domain}");
    }

    for option in config.options {
        match option {
            dns::resolv::ConfigOption::Timeout(timeout) => {
                println!("timeout: {timeout}");
            }
            _ => {}
        }
    }
}

Parsing any kind of io::Read type.

use std::fs;
use unixism::dns;

fn main() {
    let config = dns::resolv::parse(fs::File::open("local.conf").unwrap()).unwrap();

    for nameserver in config.nameservers {
        println!("{}", nameserver.to_string());
    }

    for domain in config.search_domains {
        println!("{domain}");
    }

    for option in config.options {
        match option {
            dns::resolv::ConfigOption::Timeout(timeout) => {
                println!("timeout: {timeout}");
            }
            _ => {}
        }
    }
}

hosts

Parsing an /etc/hosts file.

use unixism::hosts;

fn main() {
    for host in hosts::parse_default().unwrap() {
        println!("ip: {}, names: {:#?}", host.ip, host.names);
    }
}

Parsing any kind of io::Read type.

use std::fs;
use unixism::hosts;

fn main() {
    for host in hosts::parse(fs::File::open("local.conf").unwrap()).unwrap() {
        println!("ip: {}, names: {:#?}", host.ip, host.names);
    }
}

No runtime deps

Features