Re: Obtaining local host name
Re: Obtaining local host name
- Subject: Re: Obtaining local host name
- From: Quinn <email@hidden>
- Date: Tue, 27 May 2008 11:23:58 +0100
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