• 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: Marc Krochmal <email@hidden>
  • Date: Sat, 24 May 2008 14:36:41 -0700


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

On May 24, 2008, at 12:05 PM, 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?

Allan Nathanson has probably answered this a million times, but I couldn't find it in the archives, so here goes. The original question was, "is there a programmatic way (Objc method or C function call) that will return the local host name string".


The way to get the "Local Hostname" from the Sharing pref pane is to use SCDynamicStoreCopyLocalHostName. The way to get some seemingly random "host name" is to use gethostname.

The following describes the algorithm used by configd's IPMonitor.bundle to set the BSD hostname (the name returned by the hostname(1) command).
• if available, use the name specified in the /etc/hostconfig file (HOSTNAME=my-host-name)
• and this name need not have any association with a DNS name
• if available, use the name stored in the system/network preferences file via the "scutil --set HostName my-host-name" command (introduced w/10.4 for server systems).
• and this name need not have any association with a DNS name
• if available, use the name provided by the DHCP/BOOTP server for the "primary" IP address
• and this name need not have any association with a DNS name
• if available, use the [first] name returned by a reverse DNS (address-->name) query for the "primary" IP address
• and IP addresses on a private (behind a NAT) network generally cannot be resolved
• if available, use the "Local Hostname" from the Sharing Pref Pane.
• use "localhost"
... and, NO, the BSD hostname need not have anything to do with the DNS name (or names) associated with the system.
... and, NO, the BSD hostname has no relationship to the hosts "Computer Name" which you would set in the Sharing Pref pane.


_______________________________________________
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>)

  • 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: PPTP VPN connection through pppd...
  • Index(es):
    • Date
    • Thread