Re: gethostbyname problem with XCode ?
Re: gethostbyname problem with XCode ?
- Subject: Re: gethostbyname problem with XCode ?
- From: Vincent Lubet <email@hidden>
- Date: Tue, 10 Feb 2004 10:26:46 -0800
There is nothing wrong with the code itself except it relies on the
misconception that gethostname() and gethostbyname() are related. The
very same topic has been discussed at length last week on this mailing
list in the thread "gethostname returns loginname on "Pather Server"
version". Please dig into the archives for a complete description of
the common mistake of using the string returned by gethostname() to
resolve to an IP address. One should not expect this to work most of
the time as it depends how the system is configured.
Vincent
On Feb 10, 2004, at 5:55 AM, Matt Mashyna wrote:
I've been playing with unix again after a long time away. It's good
to be back and rid of OT! When I call this code to set up a listening
socket it works fine in the debugger. It worked with Project Builder.
But when I turn off XCode's zero link and the other debugging
options, gethostbyname fails. gethostname does work. Should I cheat
and set hostname to "127.0.0.1" ?
Any ideas what could be wrong with the non-debug build ?
*hostname = '\0';
/*
* Get my hostname and IP address.
*/
if (hostname[0] == '\0') {
if (gethostname(hostname, sizeof(hostname)) == -1) {
syslog(LOG_ERR, "Can't get hostname\n");
exit(1);
}
}
hep = gethostbyname(hostname);
if (!hep) {
syslog(LOG_ERR, "Can't get my IP address\n");
exit(1);
}
--
----------------------------------------------------------------
Matt Mashyna
email@hidden
The Frodis Co
_______________________________________________
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.
_______________________________________________
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.