2013-02-18 37 views
0

我試圖做基於子類型的服務發現。需要mDNS響應服務發現與子類型

例如我正在運行avahi-publish -s --domain = local --subtype =「_ ann._sub._http._tcp」「serviceName」「_http._tcp」5353「text Record」。

現在我正在查詢子類型ex:AT + MDNSSD = _ann,_sub,_http,_tcp,local。

但是,反應是來自avahi-publish不包含子類型。我收到名稱爲「serviceNaem._http._tcp.local」的響應消息。

任何機構都可以告訴我如何使用avahi-publish註冊服務,以便我可以在資源記錄中獲得「serviceName._ann._sub._http._tcp.local」的響應。

回答

0

avahi-browse沒有明確列出子類型。如果你知道你在找什麼,你可以過濾它,但:

[localhost]$ avahi-publish -s --subtype=_ann._sub._http._tcp serviceName _http._tcp 5353 & 
[1] 3012 

[localhost]$ avahi-browse -t _http._tcp 
+ eth0 IPv4 serviceName         Web Site    local 
[localhost]$ avahi-browse -t _ann._sub._http._tcp 
+ eth0 IPv4 serviceName         Web Site    local 

[localhost]$ kill 3012 

如果不發佈分型,然後過濾它會返回任何結果:

[localhost]$ avahi-publish -s serviceName _http._tcp 5353 & 
[1] 3026 

[localhost]$ avahi-browse -t _http._tcp 
+ eth0 IPv4 serviceName         Web Site    local 
[localhost]$ avahi-browse -t _ann._sub._http._tcp 

[localhost]$ kill 3026 

如果您使用[wire | t]鯊魚觀察流量,過濾端口5353,則會看到您的子類型正在作爲PTR記錄返回到DNS查詢中。

1

您可以通過在服務文件中使用<subtype></subtype>元素(見avahi.service手冊頁https://linux.die.net/man/5/avahi.service)註冊亞型。

下面的例子爲我工作:

<service> 
    <type>_http._tcp</type> 
    <subtype>_ann._sub._http._tcp</subtype> 
    <name>MyService</name> 
    <port>12345</port> 
<service> 
相關問題