Skip to content

DnsResolver

Description

In-tree resolver state. Created via DnsResolverInit (which reads /etc/hosts and /etc/resolv.conf from disk), torn down via DnsResolverDeinit. No globals, no shared cache; create one per subsystem that needs resolution.

Usage example (Cross-references)

Usage examples (Cross-references)
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        bool        ok = DnsResolverInit(&r, a);
        if (!ok) {
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
        Allocator       *a     = ALLOCATOR_OF(&alloc);
    
        DnsResolver r;
        DnsResolverInit(&r, a);
    // ---------------------------------------------------------------------------
    
    bool DnsResolverInit(DnsResolver *out, Allocator *alloc) {
        if (!out || !alloc) {
            return false;
    }
    
    void DnsResolverDeinit(DnsResolver *self) {
        if (!self) {
            return;
    // the response's transaction id.
    static bool try_one_query(
        DnsResolver      *self,
        const SocketAddr *ns,
        const char       *hostname,
    }
    
    bool DnsResolve_5(DnsResolver *self, const char *hostname, u16 port, SocketKind kind, DnsAddrs *out) {
        (void)kind; // protocol byte doesn't affect resolution
        if (!self || !hostname || !out) {
    }
    
    bool DnsResolve_4_vec(DnsResolver *self, const char *spec, SocketKind kind, DnsAddrs *out) {
        if (!self || !spec || !out) {
            return false;
    }
    
    bool DnsResolve_4_one(DnsResolver *self, const char *spec, SocketKind kind, SocketAddr *out) {
        if (!self || !spec || !out) {
            return false;
            u32        timeout_ms;
            u32        retries;
        } DnsResolver;
    
        ///
        /// FAILURE : Returns false on allocator OOM.
        ///
        bool DnsResolverInit(DnsResolver *out, Allocator *alloc);
    
        ///
        /// resolver.
        ///
        void DnsResolverDeinit(DnsResolver *self);
    
        ///
        ///           transport error, response with no A/AAAA).
        ///
        bool DnsResolve_5(DnsResolver *self, const char *hostname, u16 port, SocketKind kind, DnsAddrs *out);
    
        ///
        /// FAILURE : Returns false. Logs the failure cause.
        ///
        bool DnsResolve_4_vec(DnsResolver *self, const char *spec, SocketKind kind, DnsAddrs *out);
    
        ///
        /// FAILURE : Returns false; `out` untouched.
        ///
        bool DnsResolve_4_one(DnsResolver *self, const char *spec, SocketKind kind, SocketAddr *out);
    
        ///
            }
    
            DnsResolver resolver;
            if (!DnsResolverInit(&resolver, alloc)) {
                LOG_ERROR("failed to init DNS resolver");
            }
    
            DnsResolver r;
            if (!DnsResolverInit(&r, alloc)) {
                LOG_ERROR("failed to init resolver");
Last updated on