• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: Obtaining local host name
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

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


References: 
 >Re: Obtaining local host name (From: Ryan McGann <email@hidden>)
 >Re: Obtaining local host name (From: Josh Graessley <email@hidden>)

  • Prev by Date: Re: INADDR_ANY not wokring
  • Next by Date: Re: Airport 1st generation Vs 'n' routers
  • Previous by thread: Re: Obtaining local host name
  • Next by thread: Re: Obtaining local host name
  • Index(es):
    • Date
    • Thread