Re: Obtaining local host name
Re: Obtaining local host name
- Subject: Re: Obtaining local host name
- From: Peter Sichel <email@hidden>
- Date: Sun, 22 Nov 2009 09:20:35 -0500
I'm seeing some unexpected behavior around the "local host name" versus the "bonjour service name" I'd like to resolve. Per Quinn's post below, I specifically want the .local name that the user has set in the Sharing preferences panel and am using SCDynamicStoreCopyLocalHostName() to get it.
In the sharing preferences panel, if the computer name is "Peter Sichel's Computer", the text below says Computers on your local network can access this computer at "peter-sichels-imac.local" . Obviously there has been a translation from a user friendly name string to a DNS style name.
In my testing, SCDynamicStoreCopyLocalHostName() returns the DNS style name, but if you use NSNetService to advertise a service with the default name, it uses the name string.
So my question is should I try to get the user name string somehow, or is it better to set the Bonjour name of my Net Service explicitly to the ".local" name returned by SCDynamicStoreCopyLocalHostName()?
Thanks!
- Peter Sichel
Sustainable Softworks
On May 27, 2008, at 6:23 AM, Quinn wrote:
> At 14:02 -0700 24/5/08, Josh Graessley wrote:
>> gethostname is a legacy API from the days where the host had a single name. It's obsolete and exists only for compatibility. If you're using this API in modern code, it's a sign you're probably doing something wrong.
>
> OK, I would spin that a bit differently. gethostname is a perfectly fine API. It's well documented in <x-man-page://3/gethostname>, and it's even standardised.
>
> <http://www.opengroup.org/onlinepubs/009695399/functions/gethostname.html>
>
> The tricky part is that it's not documented to be a DNS name. Read the docs and the standard carefully: no mention of DNS at all!
>
> Unfortunately lots of folks have written code that assumes that it is a DNS name and thus, for compatibility purposes, we try to set it to a meaningful DNS name. However, as Marc posted, that's complicated code and it's not always going to give you the result you expect.
>
> So, if you specifically want the .local name that the user has set in the Sharing preferences panel, call SCDynamicStoreCopyLocalHostName. If you're looking for some other name, you'll need to be more specific about what name that is (-:
>
> S+E
> --
> Quinn "The Eskimo!" <http://www.apple.com/developer/>
> Apple Developer Relations, Developer Technical Support, Core OS/Hardware
> _______________________________________________
> 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
_______________________________________________
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