I am trying to do service discovery based on subtypes.
For example i am running avahi-publish -s --domain=local --subtype="_ann._sub._http._tcp" "serviceName" "_http._tcp" 5353 "text Record".
Now i am querying for subtype ex: AT+MDNSSD=_ann,_sub,_http,_tcp,local.
But the response is from the avahi-publish is not containing the subtype. I am getting the response message with name as, "serviceNaem._http._tcp.local".
Can any body tell how i can register the service with avahi-publish, so that i can get response as "serviceName._ann._sub._http._tcp.local", in the resource record.
2 Answers
avahi-browse doesn't explicitly list the sub-types. If you know what you're looking for, you can filter for it, though:
[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 3012If you don't publish a sub-type, then filtering for it will return nothing:
[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 3026If you watch your traffic with [wire|t]shark, filtering for port 5353, you'll see that your sub-type is being returning in the DNS query as a PTR record.
You can register subtypes by using the <subtype></subtype> element in the service file (see the avahi.service manpage ).
The following example works for me:
<service> <type>_http._tcp</type> <subtype>_ann._sub._http._tcp</subtype> <name>MyService</name> <port>12345</port>
<service>