this repo has no description

define types for basic A query

altagos.dev afdba8a6 388d893e

verified
+60
+60
src/root.zig
··· 1 1 const std = @import("std"); 2 2 const assert = std.debug.assert; 3 3 const io = std.io; 4 + const net = std.net; 4 5 5 6 pub const BytePacketBuffer = struct { 6 7 buf: [512]u8 = undefined, ··· 284 285 try testing.expectEqualStrings(expected, outstr); 285 286 } 286 287 288 + pub const DnsHeader = packed struct { 289 + id: u16 = 0, 290 + 291 + recursion_desired: bool = false, 292 + truncated_message: bool = false, 293 + authoritative_answer: bool = false, 294 + opcode: u4 = 0, 295 + response: bool = false, 296 + 297 + rescode: enum(u4) { 298 + noerror = 0, 299 + formerr = 1, 300 + servfail = 2, 301 + nxdomain = 3, 302 + notimp = 4, 303 + refused = 5, 304 + } = .noerror, 305 + checking_disabled: bool = false, 306 + authed_data: bool = false, 307 + z: bool = false, 308 + recursion_available: bool = false, 309 + 310 + questions: u16 = 0, 311 + answers: u16 = 0, 312 + authoritative_entries: u16 = 0, 313 + resource_entries: u16 = 0, 314 + }; 315 + 316 + pub const QueryType = enum(u16) { 317 + a = 1, 318 + unknown, 319 + }; 320 + 321 + pub const DnsQuestion = struct { 322 + name: []const u8, 323 + qtype: QueryType, 324 + 325 + pub fn read(self: *DnsQuestion, buffer: *BytePacketBuffer, alloc: std.mem.Allocator) !void { 326 + self.name = try buffer.readQnameAlloc(alloc); 327 + self.qtype = @enumFromInt(try buffer.reader().readInt(u16, .big)); 328 + _ = try buffer.reader().readInt(u16, .big); // class 329 + } 330 + }; 331 + 332 + // TODO: add DnsQuestion.read test 333 + 334 + pub const DnsRecord = union(QueryType) { 335 + unknown: struct { 336 + domain: []const u8, 337 + qtype: u16, 338 + data_len: u16, 339 + ttl: u32, 340 + }, 341 + a: struct { 342 + domain: []const u8, 343 + addr: net.Ip4Address, 344 + ttl: u32, 345 + }, 346 + };