Enumerating Domains

The DNSServiceEnumerateDomains function finds domains that are recommended for registration and browsing. Each time your callback is called, information about one domain is provided, along with flags indicating whether to add or remove the domain from your list of domains or indicating that the domain is a default domain, or is no longer the default domain.

The parameters for calling DNSServiceEnumerateDomainsconsist of the following:

If the enumeration can be started, DNSServiceEnumerateDomains initializes the service discovery reference and creates a socket that is used to communicate with the mDNSResponder daemon. Use the service discovery reference to call DNSServiceRefSockFD and get the socket descriptor for the socket.

Set up a run loop or a select loop using the socket descriptor. When the loop indicates that a response from the mDNSResponder daemon is available, call DNSServiceProcessResult and pass to it the service discovery reference initialized by DNSServiceEnumerateDomains. DNSServiceProcessResult will call the callback function associated with the service discovery reference.

Instead of setting up a run or select loop, you can call DNSServiceEnumerate and immediately call DNSServiceProcessResult. The DNSServiceProcessResult function will block until the mDNSResponder daemon has a response, at which time the callback specified when DNSServiceEnumerate was called will be invoked.

Your callback will be called with the following parameters:

The run loop or the select loop will be notified for each recommended domain enumerated on per-interface basis and whenever a domain is added or removed. You are responsible for assembling the daemon’s responses into a list of current recommended domains.

To terminate the enumeration, remove the socket descriptor from the run loop or the select loop and call DNSServiceRefDeallocate, passing to it the service discovery reference that was initialized when DNSServiceEnumerateDomains was called. The service discovery reference is invalidated, and memory associated with the reference is deallocated. The socket that underlies the connection with the mDNSResponder daemon is closed, thereby terminating your application’s connection with the daemon.