Module: net.dns
Source: ./net/dns.reef
Overview
net.dns - DNS hostname resolution
Provides hostname resolution and reverse DNS lookup for IPv4 and IPv6.
The 5 fallible ops (dns_lookup/dns_lookup_ipv4/dns_lookup_ipv6/ dns_lookup_first/dns_reverse) return result.Result[T, error.Error].
Classification note (Phase E1 Task 3): unlike tcp/udp/unix, DNS failures are NOT classified via net.socket's net_err(). The runtime's reef_dns_lookup()/reef_dns_reverse() wrap getaddrinfo()/getnameinfo(), which -- on the common failure paths (unknown host, no PTR record) -- do NOT set errno at all (only the rare EAI_SYSTEM case does); reading errno via net_err() in those cases would report a stale/unrelated errno as if it were the DNS failure reason. So every failure here (count <= 0, or a negative return from reef_dns_reverse) maps to Err(ErrorKind_NotFound()) instead.
Example - Lookup: let r = dns_lookup("example.com") if result.is_ok(r) for addr in result.unwrap_ok(r) println(addr) end for end if
Example - Reverse lookup: let r = dns_reverse("8.8.8.8") if result.is_ok(r) println("Hostname: ${result.unwrap_ok(r)}") end if
Functions
fn MAX_HOSTNAME_LEN(): int
Maximum hostname length
fn dns_lookup(hostname: string): result.Result[[string], error.Error]
Lookup all IP addresses for a hostname (IPv4 and IPv6) Ok(addresses) when at least one record is found; Err(NotFound) on resolution failure or no records (see module doc comment for why this isn't net_err()-classified).
fn dns_lookup_ipv4(hostname: string): result.Result[[string], error.Error]
Lookup IPv4 addresses only Ok(addresses) when at least one IPv4 record is found; Err(NotFound) if the hostname fails to resolve at all, or resolves but has no IPv4 records.
fn dns_lookup_ipv6(hostname: string): result.Result[[string], error.Error]
Lookup IPv6 addresses only Ok(addresses) when at least one IPv6 record is found; Err(NotFound) on resolution failure or no IPv6 records.
fn dns_lookup_first(hostname: string): result.Result[string, error.Error]
Lookup and return first address Ok(first address) on success; Err(NotFound) if the hostname has no records.
fn dns_reverse(addr: string): result.Result[string, error.Error]
Reverse DNS lookup - get hostname from IP address Ok(hostname) on success; Err(NotFound) if the address doesn't parse or has no PTR record (see module doc comment for why this isn't net_err()-classified).
fn dns_is_valid_hostname(hostname: string): bool
Validate hostname format (basic check)
fn array_append(arr: [string], item: string): [string]
Helper: append to string array
fn array_str_length(arr: [string]): int
Helper: get array length
Generated by reefc doc