title: How do I find out my multicast (Bonjour) hostname?
body: <p>I've registered a record using the Bonjour API. Now I want to know the contents of the record I just published. I created it by specifying a NULL hostname, meaning, "use the daemon's default", but I can't find a simple way to query what that is!</p>
  
  <p>With avahi, it's easy: I call <code>avahi_client_get_host_name()</code> to get the starting value of the machine's hostname.</p>
  
  <p>For both avahi and Bonjour, the value of the SRV record can change during the lifetime of the registration - if the registration was done with a NULL hostname, the record's hostname is updated automatically when necessary. All I want here is a way to get the <em>initial</em> value of the hostname, at the time when I perform the registration.</p>
  
  <p>Note that on my Snow Leopard test machine, the default multicast hostname is <em>not</em> the same as the machine's name from <code>gethostname(2)</code>.</p>
  
  <p>Four solutions I can think of:</p>
  
  <ol>
  <li>Grab hostname in my process. It may be in there somewhere. I did a <code>strings(3)</code> search on a memory dump of my process, and found four instances of the multicast hostname in my address space, but that could be coincidence given the name is used for other things. Even if the string I'm after is in my process somewhere, I can't find an API to retrieve it sanely.</li>
  <li>Query the hostname from the daemon. There may be some query I can send over the mach port to the daemon that fetches it? I can't find an API again. The relevant chunk of code is in the uDNS.c file in mDNSResponder, and doesn't seem to be exposed via the RPC interface.</li>
  <li>I could just lookup the service I registered. This may involve a bit of network traffic though, so unless there's some guarantee that won't happen, I'm loathe to do it.</li>
  <li><p>Re-implement the logic in uDNS.c. It grabs the machine's hostname from a combination of:</p>
  
  <ul>
  <li>Dynamic DNS configuration</li>
  <li>Statically configured multicast hostname</li>
  <li>Reverse lookup of the primary interface's IPv4 address</li>
  <li>It specifically doesn't use <code>gethostname(2)</code> or equivalent</li>
  </ul>
  
  <p>Re-implementing that logic seems infeasible.</p></li>
  </ol>
  
  <p>At the moment, I'm tending towards doing a lookup to grab the value of the initial SRV registration, but it doesn't seem ideal. What's the correct solution?</p>