unix::hosts
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,
};
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
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
Show undocumented member
type reader = struct {
scan: bufio::scanner,
names: []str,
};
Errors
type error
type error = !(io::error | invalid | utf8::invalid | ip::invalid | fs::error);
All possible errors returned from this module.
type invalid
type invalid = !void;
Returned when an invalid host line was found.
Functions
fn finish
fn finish(rd: *reader) void;
Frees resources associated with a reader.
fn host_dup
fn host_dup(src: *host) (host | nomem);
Duplicates a host value.
fn host_finish
fn host_finish(host: *host) void;
Frees resources associated with a host.
fn lookup
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
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
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
fn strerror(err: error) const str;
Converts an error to a human-friendly representation.