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") handle error {
        println(f"operation failed: {error}");
        return;
    };
    for addr in addrs {
        println(addr);
    }

    let first = dns.lookup_host("localhost") handle error {
        println(f"operation failed: {error}");
        return;
    };
    println(first);
}

Contents

Functions

Function resolve

pub fn resolve(hostname: string) -> Result<Vec<string>, net.NetError>

Resolve a hostname to all associated IP addresses.

Returns Err(NetError.Other(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) -> Result<string, net.NetError>

Resolve a hostname to its first IP address.

Returns Err(NetError.Other(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 or resolution failure returns an empty vector. The resolver keeps running after the deadline; its late answer is discarded.

Examples

import std.net.dns;

fn main() {
    let addrs = dns.resolve_timed("slow.example.com", 500);
    for addr in addrs {
        println(addr);
    }
}

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.