如何更改 SRV 记录格式

问题描述

我使用 NsdManager 注册了服务:

    public void RegisterService(string serviceName,int port,Dictionary<string,string> attributes,string serviceType = "_itxpt_http._tcp.")
    {
        var serviceInfo = new NsdServiceInfo()
        {
            ServiceName = serviceName,Port = port,ServiceType = serviceType
        };

        if (attributes != null && attributes.Count > 0)
        {
            foreach (var keyvaluePair in attributes)
            {
                serviceInfo.SetAttribute(keyvaluePair.Key,keyvaluePair.Value ?? string.Empty);
            }
        }

        NsdManager.RegisterService(serviceInfo,NsdProtocol.DnsSd,new ListenerWrapper(_eventLogger));
    }

我得到了 TXT 和 SRV 记录。 SRV 记录的格式为 inventory._itxpt_http._tcp.local 120 CLASS32769 SRV 0 0 8090 Android-2.local

如何更改当前格式?我想在服务名称(库存)之后删除 DOT,我希望它看起来像这样:inventory_itxpt_http._tcp.local 120 CLASS32769 SRV 0 0 8090 Android-2.local

解决方法

除了您的问题与编程无关的事实之外,您无法“更改”SRV 记录的格式。这些记录必须以“_service._protocol”格式作为前缀。

因此,inventory._itxpt_http._tcp.local 名称不能附加到 SRV 记录,因为它不符合规范(即使您先删除 inventory,实际上也不是服务部分,因为服务部分通常是 IANA 服务列表中的一个令牌)。有关 SRV 记录的设计和预期如何工作和使用的更多详细信息和说明,请参阅 RFC 2782。

inventory_itxpt_http._tcp.local 的格式也不正确。

如果您想更多地解释您的问题以及为什么您希望将其记录在 SRV 记录中,因为您显然没有按照设计的方式使用它们,您可能会得到更好的答复,但可能不会在本网站上得到答复,除非您从编程开始问题。