Sample code for 30+ languages & platforms
Zig

DNS Query CAA Records

See more DNS Examples

Shows how to perform a DNS query to retrieve CAA records.

Note: This example requires Chilkat v9.5.0.96 or later.

Chilkat Zig Downloads

Zig
const std = @import("std");
const chilkat = @import("chilkat");

pub fn main(init: std.process.Init) !void {
    const alloc = init.arena.allocator();

    const dns = try chilkat.Dns.init();
    defer dns.deinit();

    const json = try chilkat.JsonObject.init();
    defer json.deinit();
    json.setEmitCompact(false);

    dns.query("CAA", "zoom.us", json) catch {
        std.debug.print("{s}\n", .{try dns.getLastErrorText(alloc)});
        return;
    };

    std.debug.print("{s}\n", .{try json.emit(alloc)});

    // Sample response.
    // Parsing code below..

    // {
    //   "answer": {
    //     "caa": [
    //       {
    //         "name": "zoom.us",
    //         "ttl": 300,
    //         "flags": 0,
    //         "tag": "iodef",
    //         "value": "mailto:security@zoom.us"
    //       },
    //       {
    //         "name": "zoom.us",
    //         "ttl": 300,
    //         "flags": 0,
    //         "tag": "issue",
    //         "value": "amazon.com"
    //       },
    //       {
    //         "name": "zoom.us",
    //         "ttl": 300,
    //         "flags": 0,
    //         "tag": "issue",
    //         "value": "digicert.com"
    //       },
    //       {
    //         "name": "zoom.us",
    //         "ttl": 300,
    //         "flags": 0,
    //         "tag": "issue",
    //         "value": "godaddy.com"
    //       },
    //       {
    //         "name": "zoom.us",
    //         "ttl": 300,
    //         "flags": 0,
    //         "tag": "issue",
    //         "value": "letsencrypt.org"
    //       },
    //       {
    //         "name": "zoom.us",
    //         "ttl": 300,
    //         "flags": 0,
    //         "tag": "issue",
    //         "value": "pki.goog"
    //       },
    //       {
    //         "name": "zoom.us",
    //         "ttl": 300,
    //         "flags": 0,
    //         "tag": "issue",
    //         "value": "sectigo.com"
    //       }
    //     ]
    //   }
    // }

    // Use this online tool to generate parsing code from sample JSON:
    // Generate Parsing Code from JSON

    var name: [:0]const u8 = "";
    var ttl: i32 = 0;
    var flags: i32 = 0;
    var tag: [:0]const u8 = "";
    var value: [:0]const u8 = "";

    var i: i32 = 0;
    const count_i = json.sizeOfArray("answer.caa");
    while (i < count_i) {
        json.setI(i);
        name = try json.stringOf(alloc, "answer.caa[i].name");
        ttl = json.intOf("answer.caa[i].ttl");
        flags = json.intOf("answer.caa[i].flags");
        tag = try json.stringOf(alloc, "answer.caa[i].tag");
        value = try json.stringOf(alloc, "answer.caa[i].value");
        i = i + 1;
    }
}