• 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: Josh Graessley <email@hidden>
  • Date: Sat, 24 May 2008 15:51:17 -0700


On May 24, 2008, at 3:29 PM, Nathan Kinsinger wrote:


On May 24, 2008, at 3:02 PM, Josh Graessley wrote:

On May 24, 2008, at 1:57 PM, Ryan McGann wrote:

On May 24, 2008, at 12:05 PM, macnetworkprog- email@hidden wrote:

gethostname isn't going to work.  You're looking for
SCDynamicStoreCopyLocalHostName.
Mark,

I'm curious, why won't gethostname work? The hostname command seems to return the correct string, and according to the sources, it simply calls gethostname. What's different about the SytemConfig call?

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.


-josh

Are you talking about all unix networking APIs or just gethostname. For example getaddrinfo and gethostbyname can return multiple addresses, should all networking code switch to the apple APIs?

Just gethostname. getaddrinfo is fine, though it sure would be nice if there was a cross platform asynchronous version of the API.


And correct me if I'm wrong, but SCDynamicStoreCopyLocalHostName returns a CFStringRef with a single name, so how is that better?

SCDynamicStoreCopyLocalHostName gives you a very specific name, the dot-local name. gethostname will return you a name, but it's hard to know which name or what you can do with that name, where it came from, or what it means.


Also (for the OP's question) would [[NSHost currentHost] names] (or name) work?

I have no idea what that API does.

-josh

_______________________________________________
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


  • Follow-Ups:
    • Re: Obtaining local host name
      • From: Nathan Kinsinger <email@hidden>
References: 
 >Re: Obtaining local host name (From: Ryan McGann <email@hidden>)
 >Re: Obtaining local host name (From: Josh Graessley <email@hidden>)
 >Re: Obtaining local host name (From: Nathan Kinsinger <email@hidden>)

  • Prev by Date: Re: Obtaining local host name
  • Next by Date: Re: Obtaining local host name
  • Previous by thread: Re: Obtaining local host name
  • Next by thread: Re: Obtaining local host name
  • Index(es):
    • Date
    • Thread