From 4a2f7023ec687c3ecf928632cc58aa30ade3268a Mon Sep 17 00:00:00 2001 From: Cameron Gutman Date: Sun, 3 Dec 2023 21:45:10 -0600 Subject: [PATCH] Fix discovery of Windows hosts by Apple devices --- src/platform/windows/publish.cpp | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/platform/windows/publish.cpp b/src/platform/windows/publish.cpp index 187868b6..30aa30e2 100644 --- a/src/platform/windows/publish.cpp +++ b/src/platform/windows/publish.cpp @@ -119,6 +119,21 @@ namespace platf::publish { instance.wPort = map_port(nvhttp::PORT_HTTP); instance.pszHostName = host.data(); + // Setting these values ensures Windows mDNS answers comply with RFC 1035. + // If these are unset, Windows will send a TXT record that has zero strings, + // which is illegal. Setting them to a single empty value causes Windows to + // send a single empty string for the TXT record, which is the correct thing + // to do when advertising a service without any TXT strings. + // + // Most clients aren't strictly checking TXT record compliance with RFC 1035, + // but Apple's mDNS resolver does and rejects the entire answer if an invalid + // TXT record is present. + PWCHAR keys[] = { nullptr }; + PWCHAR values[] = { nullptr }; + instance.dwPropertyCount = 1; + instance.keys = keys; + instance.values = values; + DNS_SERVICE_REGISTER_REQUEST req {}; req.Version = DNS_QUERY_REQUEST_VERSION1; req.pQueryContext = alarm.get();