#host #parser #linux #dns #domain #conf #file

unixism

A set of tools for working with linux from Rust

1 unstable release

0.1.0 Apr 5, 2024

#1754 in Network programming

Download history 118/week @ 2024-04-04 3/week @ 2024-04-11

121 downloads per month

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