Re: gethostname
Re: gethostname
- Subject: Re: gethostname
- From: Quinn <email@hidden>
- Date: Fri, 21 May 2004 11:58:46 +0100
At 15:21 -0700 20/5/04, Quick David L KPWA wrote:
I am moving some applications to Mac OS X from Solaris that use the
following code:
if (gethostname(name, sizeof(name)) == -1)
perror ("Dgps:OpenServerSocket:gethostname");
if ((host = gethostbyname(name)) == NULL)
perror ("Dgps:OpenServerSocket:gethostbyname");
This does not work in OS X unless host name entries are made in the
etc/hosts file. I would rather make the apps use the Netinfo entries or get
the values from the Systemname.local setting. Can anyone tell me how to do
this? Pretty new to OS X so any help would be appreciated.
This has been discussed (to death) on the list before. For the full
story, check out the archives, which you can access from the list's
web page.
<
http://www.lists.apple.com/macnetworkprog/>
The short summary is that the specification of the gethostname API
does not require it to return a valid DNS name. The man page
<x-man-page://3/gethostname> mentions nothing about DNS or the Single
UNIX Spec.
<
http://www.opengroup.org/onlinepubs/007908799/xns/gethostname.html>
<
http://www.opengroup.org/onlinepubs/000095399/functions/gethostname.html>
Thus, there's no guarantee that calling gethostbyname on gethostname
will return meaningful results.
What is this code trying to do? In most cases folks do this in order
to get the machine's IP address. If that's the case, check out the
advice in DTS Technote 1145 "Living in a Dynamic TCP/IP Environment".
<
http://developer.apple.com/technotes/tn/tn1145.html>
S+E
--
Quinn "The Eskimo!" <
http://www.apple.com/developer/>
Apple Developer Technical Support * Networking, Communications, Hardware
_______________________________________________
macnetworkprog mailing list | email@hidden
Help/Unsubscribe/Archives:
http://www.lists.apple.com/mailman/listinfo/macnetworkprog
Do not post admin requests to the list. They will be ignored.
References: | |
| >gethostname (From: Quick David L KPWA <email@hidden>) |