Module std::net::dns

DNS hostname resolution.

Resolve hostnames to IP address strings using the system resolver.

Examples

import std::net::dns;

fn main() {
    let addrs = dns.resolve("localhost");
    for i in 0..addrs.len() {
        println(addrs[i]);
    }

    let first = dns.lookup_host("localhost");
    println(first);
}

Contents

Functions

Function resolve

pub fn resolve(hostname: string) -> Vec<string>

Resolve a hostname to all associated IP addresses.

Returns a vector of IP address strings. Returns an empty vector if the hostname cannot be resolved.

Examples

let addrs = dns.resolve("localhost");  // ["127.0.0.1", "::1"]

Function try_resolve

pub fn try_resolve(hostname: string) -> Result<Vec<string>, fs.IoError>

Resolve a hostname to all associated IP addresses.

Returns Err(fs.io_error_from_errno(0)) when the hostname cannot be resolved. Use this when structured error handling with ? is preferred over an empty-vector sentinel.

Note: DNS has no OS errno channel; the errno payload is always 0. A follow-up issue will wire errno once hew_dns_resolve exposes it.

Function lookup_host

pub fn lookup_host(hostname: string) -> string

Resolve a hostname to its first IP address.

Returns the first resolved IP address as a string, or an empty string if the hostname cannot be resolved.

Examples

let ip = dns.lookup_host("localhost");  // "127.0.0.1"

Function try_lookup_host

pub fn try_lookup_host(hostname: string) -> Result<string, fs.IoError>

Resolve a hostname to its first IP address.

Returns Err(fs.io_error_from_errno(0)) when the hostname cannot be resolved. Use this when structured error handling with ? is preferred over an empty-string sentinel.

Note: DNS has no OS errno channel; the errno payload is always 0. A follow-up issue will wire errno once hew_dns_lookup_host exposes it.

Function resolve_timed

pub fn resolve_timed(hostname: string, deadline_ms: i64) -> Vec<string>

Resolve a hostname to all associated IP addresses with a deadline.

deadline_ms <= 0 disables the deadline. On deadline expiry returns an empty vector โ€” the underlying getaddrinfo keeps running on the shared blocking pool (its result is discarded), so the calling scheduler thread returns within deadline_ms even if the resolver is stalled.

Examples

let addrs = dns.resolve_timed("slow.example.com", 500);

Function lookup_host_timed

pub fn lookup_host_timed(hostname: string, deadline_ms: i64) -> string

Resolve a hostname to its first IP address with a deadline.

deadline_ms <= 0 disables the deadline. On deadline expiry or resolution failure returns an empty string.