+39
-1
src/stda/net/dns.zig
+39
-1
src/stda/net/dns.zig
···
250
250
// MX = 15,
251
251
// TXT = 16,
252
252
AAAA = 28,
253
-
// SRV = 33,
253
+
SRV = 33,
254
254
// OPT = 41,
255
255
};
256
256
257
257
pub const Answer = union(ResourceType) {
258
258
A: [4]u8,
259
259
AAAA: [16]u8,
260
+
SRV: struct {
261
+
priority: u16,
262
+
weight: u16,
263
+
port: u16,
264
+
target: []const u8,
265
+
},
260
266
};
261
267
262
268
pub const Response = struct {
···
347
353
self.bytes[self.offset + 13],
348
354
self.bytes[self.offset + 14],
349
355
self.bytes[self.offset + 15],
356
+
} };
357
+
},
358
+
359
+
.SRV => {
360
+
assert(rd_len > 6);
361
+
const rdata = self.bytes[self.offset..];
362
+
const priority = std.mem.readInt(u16, rdata[0..2], .big);
363
+
const weight = std.mem.readInt(u16, rdata[2..4], .big);
364
+
const port = std.mem.readInt(u16, rdata[4..6], .big);
365
+
366
+
var buf: [256]u8 = undefined;
367
+
var idx: usize = 0;
368
+
var offset: usize = 6;
369
+
while (true) {
370
+
const len = rdata[offset];
371
+
if (len == 0x00) break;
372
+
373
+
if (idx > 0) {
374
+
buf[idx] = '.';
375
+
idx += 1;
376
+
}
377
+
offset += 1;
378
+
@memcpy(buf[idx .. idx + len], rdata[offset .. offset + len]);
379
+
offset += len;
380
+
idx += len;
381
+
}
382
+
383
+
return .{ .SRV = .{
384
+
.priority = priority,
385
+
.weight = weight,
386
+
.port = port,
387
+
.target = buf[0..idx],
350
388
} };
351
389
},
352
390
}