Discovering all advertised Bonjour service types

Q: Is it possible to dynamically discover every Bonjour service type being advertised on the network?

A: Yes. Devices running mDNSResponder-58.6 (Mac OS X 10.3.4) or later will respond to the "Service Type Enumeration" meta-query described in Section 10 of the DNS-SD specification. Issuing a Multicast DNS PTR record query for the name "_services._dns-sd._udp.local." will return a list of service types being advertised on the local network.

Queries for "_services._dns-sd._udp.local." behave somewhat differently than standard mDNS queries. Normal mDNS long-lived queries will return ADD/REMOVE events as records are registered and deregistered, however, a service type enumeration meta-query will not be told about REMOVE events when a service is deregistered. Otherwise, the meta-query behaves identically to a standard mDNS query. It will receive REMOVE events when a network interface is disabled or if the PTR record expires from the cache naturally.

Note: This non-standard behavior helps to reduce network traffic. Since multiple devices on the network will typically register the exact same meta-query PTR record, if one of the devices were to send a goodbye packet for that record, then at least one other device would be required to respond in order to "rescue" the record from being deleted. It's for that reason that goodbye packets are not sent for meta-query PTR records. For more information about goodbye packets, please see Section 13.2 of the Multicast DNS specification.

You can issue this meta-query by using DNSServiceQueryRecord from the socket-based DNSServiceDiscovery API, located in /usr/include/dns_sd.h. For each DNS-SD service type being advertised, the callback will return a DNS PTR record containing a service type and domain. For example, if someone is advertising an HTTP service on the local network, the DNSServiceQueryRecord callback will return a PTR record which points to "_http._tcp.local.".

The DNSServiceMetaQuery sample code shows how to issue the service type enumeration meta-query.

Document Revision History

DateNotes
2004-06-01Explains how to discover all Bonjour service types being advertised on the local network.

Posted: 2004-06-01


Did this document help you?
Yes: Tell us what works for you.
It’s good, but: Report typos, inaccuracies, and so forth.
It wasn’t helpful: Tell us what would have helped.