- Community Home
- >
- Servers and Operating Systems
- >
- Operating Systems
- >
- Operating System - HP-UX
- >
- gethostbyname frustrating error.
Categories
Company
Local Language
Forums
Discussions
Forums
- Data Protection and Retention
- Entry Storage Systems
- Legacy
- Midrange and Enterprise Storage
- Storage Networking
- HPE Nimble Storage
Discussions
Discussions
Discussions
Discussions
Forums
Forums
Discussions
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
- BladeSystem Infrastructure and Application Solutions
- Appliance Servers
- Alpha Servers
- BackOffice Products
- Internet Products
- HPE 9000 and HPE e3000 Servers
- Networking
- Netservers
- Secure OS Software for Linux
- Server Management (Insight Manager 7)
- Windows Server 2003
- Operating System - Tru64 Unix
- ProLiant Deployment and Provisioning
- Linux-Based Community / Regional
- Microsoft System Center Integration
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Discussion Boards
Community
Resources
Forums
Blogs
- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 12:14 AM
тАО07-08-2003 12:14 AM
gethostbyname frustrating error.
My problem is that "gethostbyname()" does not work in my application. It fails to find the host name I give it in the /etc/hosts files.
This is what I have done to test it:
1. changed nsswitch.conf to look at files, files and then files (no DNS or NIS). This was done in SAM.
2. /etc/resolve.conf does not exist. We are not using a DNS.
3. Tried nslookup - this works well. I give nslookup ny host name and it returns the correct IP address from /etc/hosts.
4. I wrote a small C program that just calls GetHostByName() for my host name and it works well.
However in my main application (also in C) it does not work. It fails and returns a NULL.
I have read in another thread that there may be a solution to this and a link was given. As luck would have it, that link does not exist anymore.
Any ideas here would be greatly appreciated.
Thanks in advance
PA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 12:19 AM
тАО07-08-2003 12:19 AM
Re: gethostbyname frustrating error.
Regards
Rainer
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 01:20 AM
тАО07-08-2003 01:20 AM
Re: gethostbyname frustrating error.
You said:
changed nsswitch.conf to look at files, files and then files (no DNS or NIS). This was done in SAM.
Usually SAM can put some extra char in the files.
Did you check with a
cat -tve /etc/nsswitch.conf| more
to see ?
Check permission for /etc/hosts ?
HTH,
Massimo
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 02:38 AM
тАО07-08-2003 02:38 AM
Re: gethostbyname frustrating error.
The fact that NULL is returned simply means that the requested name was not found.
Are you able to debug your application to check EXACTLY what is being passed to gethostbyname()?
The most obvious thing to look for is non-printing characters embedded in the hostname string.
HTH,
Michael.
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 03:56 AM
тАО07-08-2003 03:56 AM
Re: gethostbyname frustrating error.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 04:09 AM
тАО07-08-2003 04:09 AM
Re: gethostbyname frustrating error.
system1.hp.com
Revert
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 04:07 PM
тАО07-08-2003 04:07 PM
Re: gethostbyname frustrating error.
To answer everyones questions:
1. yes I used the same compiler switches.
2. the nsswitch.conf file looks like this:
#cat -tve /etc/nsswitch.conf
hosts: files [NOTFOUND=continue UNAVAIL=continue] files [NOTFOUND=continue U
NAVAIL=continue TRYAGAIN=continue] files [NOTFOUND=return UNAVAIL=continue TRY
AGAIN=return] $
And the permissions of /etc/hosts look ok. They are:
-r--r--r-- 1 bin bin 707 Jul 8 10:25 /etc/hosts
3. In my main application I hardcoded a string variable with my host name to make sure the string is not corrupted. Then I passed this char array to gethostbyname(). There is no chance for corrupted vars etc. I printed out the nameof the variable with ">>>>" on either side of the name to make sure no chars before or after the var name.
4. I can run nsquery successfully too. I pass it the hostname and I get the IP address.
5. I changed the hostname to hostname.hp.com as an example in both /etc/hosts and the application. Still no luck.
If anyone can access this link or knows where the document that its referring to is kept, that will help tremendously. This was the link that was referred to in someone elses previous post regarding a similar problem.
The link is:
http://europe-support.external.hp.com/cki/bin/doc.pl/sid=664f46e90e024acf9b/screen=ckiDisplayDocument?docId=200000057171900
So I am still not sure how to fix this problem.
Thanks again everyone for your time and efforts
PA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 04:58 PM
тАО07-08-2003 04:58 PM
Re: gethostbyname frustrating error.
I would create a very small program that accepts a hostname and call gethostbyname to eliminate any additional code from masking the underlying problem. Make sure that /etc/hosts is readable for everyone (644 owned by root). The man page gives several conditions for a NULL pointer including invalid len param.
Bill Hassell, sysadmin
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 05:34 PM
тАО07-08-2003 05:34 PM
Re: gethostbyname frustrating error.
Cheers!
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-08-2003 06:28 PM
тАО07-08-2003 06:28 PM
Re: gethostbyname frustrating error.
I've worked it out.
This is the solution:
The main application uses a C libarary called NSL (this library comes with HP-UX) however the small test program I wrote does not use it.
We have two HP servers - same HP-UX but one with newer libraries (including the NSL libraries) than the other.
If I compile my main application on one of the servers using its NSL it gethostbyname() does not work. If I compile the same application on the other server (with newer NSL files) gethostbyname() works.
As my small app didn't use the NSL library then it worked everytime.
Whats strange is that the gethostbyname() function does not appear to need the NSL libraries yet the NSL libraries affect this system call. Wierd !!!
The trick here is to update the NSL C libraries that came with HP-UX on the older server as that is our development server.
Any ideas on how to do that would be
appreciated.
Thanks again
PA
- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Report Inappropriate Content
тАО07-10-2003 09:51 AM
тАО07-10-2003 09:51 AM
Re: gethostbyname frustrating error.
At 11.x libnsl.sl and libnsl.a were moved from libc. So now they are updated as part of the 11.x ONC Cumulative patch e.g. PHNE_28103 for 11.11. The name service switch at 11.x behaves differently than 10.20, and is used by gethostbyXXXX. Also be aware that the libnss_compat.1 libnss_files.1 libnss_nisplus.1libnss_dns.1 libnss_nis.1 also come into play and are occasionally updated via patch e.g 11.11PHNE_24129 for libnss_dns.
If you are using archive libs instead of dynamic libs, then compiling in an old libnsl.a
is the risk you assume with archive libs.
Hope that helps,
-> Brian Hackley