From f913dc5506bcca21d1fdc69441dc284eb4245b13 Mon Sep 17 00:00:00 2001 From: Muaz Ahmad Date: Fri, 10 May 2024 20:38:09 +0500 Subject: [PATCH] Baseline for querying mDNS --- src/mdns.zig | 32 ++++++++++++++++++++++++++++---- 1 file changed, 28 insertions(+), 4 deletions(-) diff --git a/src/mdns.zig b/src/mdns.zig index f4c08b6..27ef84a 100644 --- a/src/mdns.zig +++ b/src/mdns.zig @@ -1,10 +1,34 @@ const std = @import("std"); const util = @import("util.zig"); -pub fn get_mdns(domain: util.Domain) !util.IPs { - std.debug.print("{}\n", .{domain}); +pub fn get_mdns(domain: util.Domain, ip_ver: util.IP_VER_ENUM) !util.IPs { + 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{ - .v4 = "stub v4", - .v6 = "stub v6", + .v4 = "", + .v6 = "", }; }