Skip to content

DnsRecord

Description

One decoded resource record.

Fields

Name Description
name decoded label string (e.g. “example.com.”)
type record type
rclass record class (typically 1 = IN)
ttl seconds the record may be cached
ipv4 valid when type == DNS_TYPE_A; otherwise zero
ipv6 valid when type == DNS_TYPE_AAAA; otherwise zero
target valid when type is CNAME / NS / PTR; otherwise empty
rdata raw rdata bytes; always populated regardless of type

Usage example (Cross-references)

Usage examples (Cross-references)
    
        if (match) {
            DnsRecord *r0 = &resp.answers.data[0];
            match         = r0->type == DNS_TYPE_A && r0->ttl == 300 && r0->ipv4[0] == 93 && r0->ipv4[1] == 184 &&
                    r0->ipv4[2] == 216 && r0->ipv4[3] == 34 && r0->name.length > 0 &&
        }
        if (match) {
            DnsRecord *r1 = &resp.answers.data[1];
            match = r1->type == DNS_TYPE_AAAA && r1->ipv6[0] == 0x26 && r1->ipv6[1] == 0x06 && r1->ipv6[14] == 0x19 &&
                    r1->ipv6[15] == 0x46;
        bool        match = ok && resp.answers.length == 1;
        if (match) {
            DnsRecord *r = &resp.answers.data[0];
            match = r->type == DNS_TYPE_CNAME && r->target.length > 0 && ZstrCompare(r->target.data, "example.com") == 0;
        }
    
    // Decode one resource record. Advances `*pos` past the record.
    static bool decode_record(const u8 *buf, u64 len, u64 *pos, DnsRecord *rec, Allocator *alloc) {
        rec->name   = StrInit(alloc);
        rec->target = StrInit(alloc);
    static bool decode_record_list(const u8 *buf, u64 len, u64 *pos, u16 count, DnsRecords *out, Allocator *alloc) {
        for (u16 i = 0; i < count; ++i) {
            DnsRecord rec = {0};
            if (!decode_record(buf, len, pos, &rec, alloc)) {
                DnsRecordDeinit(&rec);
    // ---------------------------------------------------------------------------
    
    void DnsRecordDeinit(DnsRecord *self) {
        if (!self) {
            return;
            Str        target;
            DnsWireBuf rdata;
        } DnsRecord;
    
        typedef Vec(DnsRecord) DnsRecords;
        } DnsRecord;
    
        typedef Vec(DnsRecord) DnsRecords;
    
        ///
    
        void DnsResponseDeinit(DnsResponse *self);
        void DnsRecordDeinit(DnsRecord *self);
    
    #ifdef __cplusplus
Last updated on