tangled
alpha
login
or
join now
altagos.dev
/
aether
this repo has no description
0
fork
atom
overview
issues
pulls
pipelines
define types for basic A query
altagos.dev
6 months ago
afdba8a6
388d893e
verified
This commit was signed with the committer's
known signature
.
altagos.dev
SSH Key Fingerprint:
SHA256:UbTjEcCZlc6GzQWLCuDK3D//HESWD2xFPkzue9XMras=
+60
1 changed file
expand all
collapse all
unified
split
src
root.zig
+60
src/root.zig
···
1
1
const std = @import("std");
2
2
const assert = std.debug.assert;
3
3
const io = std.io;
4
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
288
+
pub const DnsHeader = packed struct {
289
289
+
id: u16 = 0,
290
290
+
291
291
+
recursion_desired: bool = false,
292
292
+
truncated_message: bool = false,
293
293
+
authoritative_answer: bool = false,
294
294
+
opcode: u4 = 0,
295
295
+
response: bool = false,
296
296
+
297
297
+
rescode: enum(u4) {
298
298
+
noerror = 0,
299
299
+
formerr = 1,
300
300
+
servfail = 2,
301
301
+
nxdomain = 3,
302
302
+
notimp = 4,
303
303
+
refused = 5,
304
304
+
} = .noerror,
305
305
+
checking_disabled: bool = false,
306
306
+
authed_data: bool = false,
307
307
+
z: bool = false,
308
308
+
recursion_available: bool = false,
309
309
+
310
310
+
questions: u16 = 0,
311
311
+
answers: u16 = 0,
312
312
+
authoritative_entries: u16 = 0,
313
313
+
resource_entries: u16 = 0,
314
314
+
};
315
315
+
316
316
+
pub const QueryType = enum(u16) {
317
317
+
a = 1,
318
318
+
unknown,
319
319
+
};
320
320
+
321
321
+
pub const DnsQuestion = struct {
322
322
+
name: []const u8,
323
323
+
qtype: QueryType,
324
324
+
325
325
+
pub fn read(self: *DnsQuestion, buffer: *BytePacketBuffer, alloc: std.mem.Allocator) !void {
326
326
+
self.name = try buffer.readQnameAlloc(alloc);
327
327
+
self.qtype = @enumFromInt(try buffer.reader().readInt(u16, .big));
328
328
+
_ = try buffer.reader().readInt(u16, .big); // class
329
329
+
}
330
330
+
};
331
331
+
332
332
+
// TODO: add DnsQuestion.read test
333
333
+
334
334
+
pub const DnsRecord = union(QueryType) {
335
335
+
unknown: struct {
336
336
+
domain: []const u8,
337
337
+
qtype: u16,
338
338
+
data_len: u16,
339
339
+
ttl: u32,
340
340
+
},
341
341
+
a: struct {
342
342
+
domain: []const u8,
343
343
+
addr: net.Ip4Address,
344
344
+
ttl: u32,
345
345
+
},
346
346
+
};