{"id":13712438,"url":"https://github.com/lun-4/zigdig","last_synced_at":"2025-08-03T10:30:59.240Z","repository":{"id":45225153,"uuid":"186216277","full_name":"lun-4/zigdig","owner":"lun-4","description":"naive dns client library in zig","archived":false,"fork":false,"pushed_at":"2024-08-07T05:10:10.000Z","size":609,"stargazers_count":33,"open_issues_count":2,"forks_count":5,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-12-01T10:54:22.384Z","etag":null,"topics":["dns","zig","zig-package"],"latest_commit_sha":null,"homepage":"","language":"Zig","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/lun-4.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2019-05-12T05:39:02.000Z","updated_at":"2024-09-04T17:14:08.000Z","dependencies_parsed_at":"2023-01-31T05:15:13.439Z","dependency_job_id":"fd5661af-04b2-48ec-8132-8ccd4d6c3324","html_url":"https://github.com/lun-4/zigdig","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lun-4%2Fzigdig","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lun-4%2Fzigdig/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lun-4%2Fzigdig/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/lun-4%2Fzigdig/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/lun-4","download_url":"https://codeload.github.com/lun-4/zigdig/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":228540827,"owners_count":17934029,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dns","zig","zig-package"],"created_at":"2024-08-02T23:01:18.469Z","updated_at":"2025-08-03T10:30:59.211Z","avatar_url":"https://github.com/lun-4.png","language":"Zig","readme":"# zigdig\n\nnaive dns client library in zig\n\nhelp me decide if this api is good: https://github.com/lun-4/zigdig/issues/10\n\n## what does it do\n - serialization and deserialization of dns packets as per rfc1035\n - supports a subset of rdata (i do not have any plans to support 100% of DNS, but SRV/MX/TXT/A/AAAA\n  are there, which most likely will be enough for your use cases)\n - has helpers for reading `/etc/resolv.conf` (not that much, really)\n\n## what does it not do\n - no edns0\n - support all resolv.conf options\n - can deserialize pointer labels, but does not serialize into pointers\n - follow CNAME records, this provides only the basic\n   serialization/deserializtion\n\n## how do\n\n - zig 0.14.0: https://ziglang.org\n - have a `/etc/resolv.conf`\n - tested on linux, should work on bsd i think\n\n```\ngit clone ...\ncd zigdig\n\nzig build test\nzig build install --prefix ~/.local/\n```\n\nand then\n\n```bash\nzigdig google.com a\n```\n\nor, for the host(1) equivalent\n\n```bash\nzigdig-tiny google.com\n```\n\n## using the library\n\n### getAddressList-style api\n\n```zig\nconst dns = @import(\"dns\");\n\npub fn main() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    defer {\n        _ = gpa.deinit();\n    }\n    var allocator = gpa.alloator();\n\n    var addresses = try dns.helpers.getAddressList(\"ziglang.org\", allocator);\n    defer addresses.deinit();\n\n    for (addresses.addrs) |address| {\n        std.debug.print(\"we live in a society {}\\n\", .{address});\n    }\n}\n```\n\n### full api\n\n```zig\nconst dns = @import(\"dns\");\n\npub fn main() !void {\n    var gpa = std.heap.GeneralPurposeAllocator(.{}){};\n    defer {\n        _ = gpa.deinit();\n    }\n    var allocator = gpa.alloator();\n\n    var name_buffer: [128][]const u8 = undefined;\n    const name = try dns.Name.fromString(\"ziglang.org\", \u0026name_buffer);\n\n    var questions = [_]dns.Question{\n        .{\n            .name = name,\n            .typ = .A,\n            .class = .IN,\n        },\n    };\n\n    var packet = dns.Packet{\n        .header = .{\n            .id = dns.helpers.randomHeaderId(),\n            .is_response = false,\n            .wanted_recursion = true,\n            .question_length = 1,\n        },\n        .questions = \u0026questions,\n        .answers = \u0026[_]dns.Resource{},\n        .nameservers = \u0026[_]dns.Resource{},\n        .additionals = \u0026[_]dns.Resource{},\n    };\n\n    // use helper function to connect to a resolver in the systems'\n    // resolv.conf\n\n    const conn = try dns.helpers.connectToSystemResolver();\n    defer conn.close();\n\n    try conn.sendPacket(packet);\n\n    // you can also do this to support any Writer\n    // const written_bytes = try packet.writeTo(some_fun_writer_goes_here);\n\n    const reply = try conn.receivePacket(allocator, 4096);\n    defer reply.deinit();\n\n    // you can also do this to support any Reader\n    // const packet = try dns.Packet.readFrom(some_fun_reader, allocator);\n    // defer packet.deinit();\n\n    const reply_packet = reply.packet;\n    logger.info(\"reply: {}\", .{reply_packet});\n\n    try std.testing.expectEqual(packet.header.id, reply_packet.header.id);\n    try std.testing.expect(reply_packet.header.is_response);\n\n    // ASSERTS that there's one A resource in the answer!!! you should verify\n    // reply_packet.header.opcode to see if there's any errors\n\n    const resource = reply_packet.answers[0];\n    var resource_data = try dns.ResourceData.fromOpaque(\n        reply_packet,\n        resource.typ,\n        resource.opaque_rdata,\n        allocator\n    );\n    defer resource_data.deinit(allocator);\n\n    // you now have an std.net.Address to use to your hearts content\n    const ziglang_address = resource_data.A;\n}\n\n```\n\nit is recommended to look at zigdig's source on `src/main.zig` to understand\nhow things tick using the library, but it boils down to three things:\n - packet generation and serialization\n - sending/receiving (via a small shim on top of std.os.socket)\n - packet deserialization\n","funding_links":[],"categories":["Network","Libraries","Network \u0026 Web"],"sub_categories":["Network"],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flun-4%2Fzigdig","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flun-4%2Fzigdig","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flun-4%2Fzigdig/lists"}