What’s the programmatic way to determine the localhost’s Bonjour hostname, i.e. 
the one shown in the Sharing pref pane on macOS ("Computers on your local 
network can access your computer at: jens.local”)?

I’ve been doing this by calling gethostname() … but suddenly it’s not working, 
which is breaking unit tests in my project. That is, gethostname() used to 
return “jens.local” as expected, but now returns “jens”.

(I believe the change is due to my network environment; I’ve recently moved and 
now have a WiFi router installed by AT&T. The hostname “jens” expands to the 
FQDN “jens.attlocal.net <http://jens.attlocal.net/>”, which indeed points to my 
IP address. “attlocal.net <http://attlocal.net/>” resolves to the router’s 
address. This sounds like the router has its own little dynamic-DNS-like 
system, and is using DHCP to tell my computer that it has an assigned hostname, 
which gethostname then returns.)

So if gethostname() isn’t reliably going to return the .local hostname, what 
will do it? I’m guessing there’s some key in SystemConfiguration, but I have no 
idea what it would be.

—Jens

PS: And yes, I do need specifically my “.local” hostname, not just any 
hostname, because reasons.
 _______________________________________________
Do not post admin requests to the list. They will be ignored.
Macnetworkprog mailing list      (Macnetworkprog@lists.apple.com)
Help/Unsubscribe/Update your Subscription:
https://lists.apple.com/mailman/options/macnetworkprog/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to