Does any one know why the following returns NULL after the call to
gethostbyname?
myname.node name contains the correct Host Name.
//## operation MyAddrs()
char ** MyAddrs() {
//#[ operation MyAddrs()
struct hostent *hptr;
struct utsname myname;
if (uname(&myname) < 0 )
{
return NULL;
}
if ((hptr = gethostbyname(myname.nodename)) == NULL)
{
return NULL;
}
return (hptr->h_addr_list);
//#]
}
Look at the docs for /etc/resolv.conf in the utilities reference
for info on specifying your name server(s) and / or setting up your
/etc/hosts file.
-seanb
Ian Macafee <imacafee@radamec.co.uk> wrote:
Does any one know why the following returns NULL after the call to
gethostbyname?
myname.node name contains the correct Host Name.
//## operation MyAddrs()
char ** MyAddrs() {
//#[ operation MyAddrs()
struct hostent *hptr;
struct utsname myname;
if (uname(&myname) < 0 )
{
return NULL;
}
if ((hptr = gethostbyname(myname.nodename)) == NULL)
{
return NULL;
}
return (hptr->h_addr_list);
//#]
}