Resolver structv0.1.0

Source
Asks name servers for a host's addresses.
pub struct Resolver {
    // private fields
}

Not copied. A query goes to each server in turn, for the IPv4 addresses and then the IPv6 ones, until a server answers; the whole round is tried again as many times as the attempts allow. Each query waits for its answer up to the timeout, and a name the server says does not exist ends the lookup at once.

Associated functions

WithServers

pub func WithServers(
    allocator: Allocator,
    servers: SocketAddress[..]
) -> Resolver

A resolver that asks servers, waiting five seconds for each answer and going round them twice.

NameTypeDescription
allocatorAllocatorwhat the server list and every lookup's results are kept in
serversSocketAddress[..]the name servers, in the order they are asked; port 53 is DNS's own

Returns: the resolver

Source

FromSystem

pub func FromSystem(allocator: Allocator) -> Resolver

A resolver configured as the C library's would be: the name servers, and the timeout and attempts options, of /etc/resolv.conf on Linux. With no servers to read, the one on this machine is asked.

NameTypeDescription
allocatorAllocatorwhat the server list and every lookup's results are kept in

Returns: the resolver

Source

Methods

SetTimeout

pub func SetTimeout(self: &var Resolver, timeout: Duration)

How long a query waits for its answer.

NameTypeDescription
timeoutDurationthe wait for each answer

Source

SetAttempts

pub func SetAttempts(self: &var Resolver, attempts: uint)

How many times the servers are gone round before a lookup gives up.

NameTypeDescription
attemptsuintthe number of rounds, at least one

Source

Lookup

pub func Lookup(
    self: &Resolver,
    allocator: Allocator,
    host: char8[..],
    port: uint16
) -> Vector<SocketAddress> ! IoError

Asks the servers for host's addresses: its IPv4 addresses first, then its IPv6 ones, each with port. The hosts file is not read; Resolve reads it first.

NameTypeDescription
allocatorAllocatorwhat the list is kept in
hostchar8[..]the name, such as example.com
portuint16the port every address gets

Returns: the addresses; NotFound when the name has none or does not exist, TimedOut when no server answered

Source