Operating System - HP-UX
1832978 Members
3092 Online
110048 Solutions
New Discussion

gethostbyname fails with unknown error

 
SOLVED
Go to solution
Sandeep Chaturvedi
Occasional Advisor

gethostbyname fails with unknown error

hi,

We are facing a problem with gethostbyname() in our application code. It returns NULL and the h_errno is set to zero.

/etc/nssswitch.conf file looks ok.
/etc/hosts file has an entry for the local machine.

What could be the possible reasons for such a behaviour?

Is this problem introduced by any HP-UX patch?

Also, if we gethostbyname returns correct information if IP address is being passed as a parameter.

Also a simple program as the folloing returns the correct values:
#include
#include

main(int argc, char** argv)
{
struct hostent *infoPtr;

infoPtr = gethostbyname(argv[1]);

if(!infoPtr){
fprintf(stderr, "error! \n");
}
else{
fprintf(stdout, "h_name: %s\n", infoPtr->h_name);
fprintf(stdout, "h_addrtype: %d\n", infoPtr->h_addrtype);
}
}

Any help would be appreciated.

Thanks and Regards,
Medha
14 REPLIES 14
Alan Casey
Trusted Contributor

Re: gethostbyname fails with unknown error

What happens if you try
nslookup on the same hostname?
Alan Casey
Trusted Contributor

Re: gethostbyname fails with unknown error

Please also check the permissions on:
-r--r--r-- 1 root sys 41 Jun 2 16:23 /etc/resolv.conf

should be as above
Sandeep Chaturvedi
Occasional Advisor

Re: gethostbyname fails with unknown error

Hi,

We have already checked for these two things. They are fine. Thus, we dont understand is why the sample program works and the application program does not?

Thanks and Regards,
Medha
Roger Baptiste
Honored Contributor

Re: gethostbyname fails with unknown error

hi,

If the C code you showed is working and the application is not working, the problem could be something related to your application.


Does this application work on other systems? or was it ever working on this box?

What is the exact error it returns?

-raj
Take it easy.
Sandeep Chaturvedi
Occasional Advisor

Re: gethostbyname fails with unknown error

Hi,

The code was previously compiled on HP-UX 11.00 OS and a 32-bit box.
Following was the environment:

$ what `which CC`
/bin/CC:
HP C++ HPCPLUSPLUS A.12.00 (971008) AR

$ what /usr/lib/libc.a
/usr/lib/libc.a:
$ PATCH/11.00:PHCO_15768 Jun 26 1998 15:29:51 $


Now we are attempting a build on HP-UX 11.00 and a 64-bit box.
Following is the environment on this machine:

$ what `which CC`
/home/medha/bin/CC:
HP C++ HPCPLUSPLUS A.12.14 (980921)

$ what /usr/lib/libc.a
/usr/lib/libc.a:
$ PATCH/11.00:PHCO_23770 Mar 29 2001 11:10:50


The code compiled on the 32-bit box worked fine on both the 32-bit and 64-bit boxes.

The 32-bit code being compiled on 64-bit box fails. gethostbyname results in an error. The h_errno for the function is zero.

Thanks and Regards,
Medha






Sanjay_6
Honored Contributor

Re: gethostbyname fails with unknown error

Hi Sandeep,

Do a nslookup and see that the hostname resolution is working okay on your system.

nslookup
> system_name
> system_ip_add
>exit

Hope this helps.

Regds
Sandeep Chaturvedi
Occasional Advisor

Re: gethostbyname fails with unknown error

Hi

We have already checked the nslookup output. It is fine.

Regards,
Medha
Steven Gillard_2
Honored Contributor
Solution

Re: gethostbyname fails with unknown error

This sounds a little like the problem documented in:

http://europe-support.external.hp.com/cki/bin/doc.pl/sid=664f46e90e024acf9b/screen=ckiDisplayDocument?docId=200000057171900

Are you mixing archive & shared libraries while using libpthread? If so ensure you link with the shared version of libpthread with -l:libpthread.1.

Regards,
Steve
Sandeep Chaturvedi
Occasional Advisor

Re: gethostbyname fails with unknown error

Hi,

Thanks for the pointer. It solved our problem.

Thanks and Regards,
Medha
JUP
Regular Advisor

Re: gethostbyname fails with unknown error

I have the same problem.
GetHostByName fails.
Can someone access the link given above (for Europe) as I can not - maybe this link can help me.

Thanks in advance
PA
Bill Hassell
Honored Contributor

Re: gethostbyname fails with unknown error

An alternative to nslookup is to use nsquery which is a direct interface to gethostbyname, etc. nsquery provides all the flexibility that is missing in nslookup including testing of nsswitch directives. man nsquery gives you the details. Another command is getip.


Bill Hassell, sysadmin
JUP
Regular Advisor

Re: gethostbyname fails with unknown error

Hi Bill

thanks for your response, but nslookup and nsquery all work.
When I write a small program to test gethostbyname it works too.

Its only when its in my application it fails.
Very similar to the earlier problem by Sandeep.

I think that link above may help but I can't access it (it says login failed). I was wondering if anyone can get there and if so and relay the info back to me.

Thanks again in advance
PA
Suresh Patoria
Super Advisor

Re: gethostbyname fails with unknown error

Hi,
Check the /etc/nsswitch.conf file

over there host resolution should files, dns, nis .......

check the /etc/resolve.conf file
system uses the any name server host resolution

pls remove the entry

to check the host resolution from the /etc/hosts file use the nslookup or hosts utility

JUP
Regular Advisor

Re: gethostbyname fails with unknown error

Thanks Suresh for your reply.
1. nsswitch.conf reads files, files, files ( i changed it in sam to be make sure it only reads from /etc/hosts).
2. /etc/resolve.conf does not exist. This is a system with only 2 servers allowed on the network. We are not using any DNS etc.
3. nslookup works well too. It returns the ip address of the host. Its only the gethostbyname() function not working.

I have written a small C program it gethostbyname() works well. When its in the main application it does not work.

I am going to start a new thread so I can assign points.