unix::hosts+x86_64 +linux

unix::hosts provides a parser and support code for working with a Unix /etc/hosts file to look up hostnames from a fixed list of hostname/IP assignments.

Index

Types

type host = struct {
	addr: ip::addr,
	names: []str,
};

// Undocumented types:
type reader = struct {
	scan: bufio::scanner,
	names: []str,
};

Errors

type error = !(io::error | invalid | utf8::invalid | ip::invalid | fs::error);
type invalid = !void;

Functions

fn finish(rd: *reader) void;
fn host_dup(src: *host) (host | nomem);
fn host_finish(host: *host) void;
fn lookup(name: const str) ([]ip::addr | nomem | error);
fn next(rd: *reader) (host | done | nomem | error);
fn read(in: io::handle) reader;
fn strerror(err: error) const str;

Types

type host[permalink] [source]

type host = struct {
	addr: ip::addr,
	names: []str,
};

Represents a host line in /etc/hosts, guaranteed to have at least a single name. The first name is the canonical one.

type reader[permalink] [source]

Show undocumented member
type reader = struct {
	scan: bufio::scanner,
	names: []str,
};

Errors

type error[permalink] [source]

type error = !(io::error | invalid | utf8::invalid | ip::invalid | fs::error);

All possible errors returned from this module.

type invalid[permalink] [source]

type invalid = !void;

Returned when an invalid host line was found.

Functions

fn finish[permalink] [source]

fn finish(rd: *reader) void;

Frees resources associated with a reader.

fn host_dup[permalink] [source]

fn host_dup(src: *host) (host | nomem);

Duplicates a host value.

fn host_finish[permalink] [source]

fn host_finish(host: *host) void;

Frees resources associated with a host.

fn lookup[permalink] [source]

fn lookup(name: const str) ([]ip::addr | nomem | error);

Looks up a slice of addresses from /etc/hosts. The caller must free the return value.

fn next[permalink] [source]

fn next(rd: *reader) (host | done | nomem | error);

Returns the next host line as a host type. The host value is borrowed from the reader; see host_dup to extend its lifetime.

fn read[permalink] [source]

fn read(in: io::handle) reader;

Read from an /etc/hosts-formatted file. Call next to enumerate entries and finish to free state associated with the reader.

fn strerror[permalink] [source]

fn strerror(err: error) const str;

Converts an error to a human-friendly representation.