Baseline for querying mDNS

This commit is contained in:
Muaz Ahmad 2024-05-10 20:38:09 +05:00
parent a2a066dac2
commit f913dc5506

View file

@ -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 = "",
}; };
} }