Baseline for querying mDNS
This commit is contained in:
parent
a2a066dac2
commit
f913dc5506
1 changed files with 28 additions and 4 deletions
32
src/mdns.zig
32
src/mdns.zig
|
@ -1,10 +1,34 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const util = @import("util.zig");
|
const util = @import("util.zig");
|
||||||
|
|
||||||
pub fn get_mdns(domain: util.Domain) !util.IPs {
|
pub fn get_mdns(domain: util.Domain, ip_ver: util.IP_VER_ENUM) !util.IPs {
|
||||||
std.debug.print("{}\n", .{domain});
|
var listener = try init(ip_ver);
|
||||||
|
try send_query(&listener, domain, ip_ver);
|
||||||
|
return receive_query(&listener);
|
||||||
|
}
|
||||||
|
|
||||||
|
fn init(ip_ver: util.IP_VER_ENUM) !std.net.Server {
|
||||||
|
return try std.net.Address.listen(try std.net.Address.parseIp(switch (ip_ver) {
|
||||||
|
util.IP_VER_ENUM.IPv4 => "0.0.0.0",
|
||||||
|
util.IP_VER_ENUM.IPv6 => "::",
|
||||||
|
}, 5353), .{});
|
||||||
|
}
|
||||||
|
|
||||||
|
fn send_query(listener: *std.net.Server, domain: util.Domain, ip_ver: util.IP_VER_ENUM) !void {
|
||||||
|
const header =
|
||||||
|
[_]u8{0x00} ** 4 ++ // transaction id + is question
|
||||||
|
[_]u8{ 0x00, 0x01 } ++ // 1 question
|
||||||
|
[_]u8{0x00} ** 6; // misc flags
|
||||||
|
_ = listener;
|
||||||
|
_ = domain;
|
||||||
|
_ = header;
|
||||||
|
_ = ip_ver;
|
||||||
|
}
|
||||||
|
|
||||||
|
fn receive_query(listener: *std.net.Server) !util.IPs {
|
||||||
|
_ = listener;
|
||||||
return util.IPs{
|
return util.IPs{
|
||||||
.v4 = "stub v4",
|
.v4 = "",
|
||||||
.v6 = "stub v6",
|
.v6 = "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue