How do I find the device's Bonjour hostname?
How do I find the device's Bonjour hostname?
- Subject: How do I find the device's Bonjour hostname?
- From: Jens Alfke <email@hidden>
- Date: Tue, 20 Dec 2016 09:26:32 -0800
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”, which indeed points to my IP address. “ 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 (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden