Welcome to the MacNN Forums.

If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

You are here: MacNN Forums > Software - Troubleshooting and Discussion > Developer Center > gethostbyname() returns NULL

gethostbyname() returns NULL
Thread Tools
Fresh-Faced Recruit
Join Date: May 2001
Status: Offline
Reply With Quote
Jun 17, 2001, 03:28 PM
 
I am doing some Unix server development at the University on Solaris. We are interested in porting to Linux and OS X.

I can get the software to compile on LinuxPPC and, after adding a few header includes, on OS X. Since my Mac is on a cable modem at home, my hostname is localhost in both Linux and OS X. For Linux, I used 'hostname' and 'alias HOST=...' to change my hostname to what my cable company shows my machine as to get the server software to run.

I tried doing the same on OS X. I used 'hostname' and 'setenv HOST ...' while using sudo tcsh. I used uname to confirm my changes. I also used 'kill -HUP xxx' to restart lookupd per Apple's TIL since it caches host info.

When I try the server software, however, gethostbyname() returns NULL. herror says that the error is 'Unknown Host'.

Does anyone have any suggestions?

Scott
     
Senior User
Join Date: Sep 2000
Location: Boston, MA
Status: Offline
Reply With Quote
Jun 17, 2001, 03:41 PM
 
edit /etc/hostconfig and reboot.
     
Fresh-Faced Recruit
Join Date: May 2001
Status: Offline
Reply With Quote
Jun 17, 2001, 07:10 PM
 
Thanks for the suggestion. I edited the file and changed

hostname=-AUTOMATIC-

to

hostname="my-cable-modem-name"

I then rebooted. Both 'echo $HOST' and 'uname -a' returned the new info. But gethostbyname still returns NULL and herror shows 'Unknown Host'.

Should I be doing something else?

Scott
     
Dedicated MacNNer
Join Date: Apr 2001
Location: San Francisco, USA
Status: Offline
Reply With Quote
Jun 18, 2001, 12:12 AM
 
Originally posted by my 2 cents:
<STRONG>I then rebooted. Both 'echo $HOST' and 'uname -a' returned the new info. But gethostbyname still returns NULL and herror shows 'Unknown Host'.

Should I be doing something else?</STRONG>
I'm not sure how you are using gethostbyname(), but perhaps you could run a similar test using nslookup. If nslookup fails with 'unknown host', then you have a configuration problem. Make sure your search domains are specified in the Network Preferences. Your changes will be reflected in /etc/resolv.conf. If nslookup works and your code does not, check your code for possible bugs.

To continue your example, if your full hostname is 'my-cable-modem-name.my-cable-provider.com', then make sure 'my-cable-provider.com' is listed in the search domains. You can use the following link to find your full hostname:

http://www.dyndns.org/cgi-bin/check_ip.cgi

Edit: fixed a typo.

[ 06-18-2001: Message edited by: honeydew ]
     
Fresh-Faced Recruit
Join Date: May 2001
Status: Offline
Reply With Quote
Jun 18, 2001, 08:58 PM
 
Originally posted by honeydew:
<STRONG>

I'm not sure how you are using gethostbyname(), but perhaps you could run a similar test using nslookup. If nslookup fails with 'unknown host', then you have a configuration problem. Make sure your search domains are specified in the Network Preferences. Your changes will be reflected in /etc/resolv.conf. If nslookup works and your code does not, check your code for possible bugs.

To continue your example, if your full hostname is 'my-cable-modem-name.my-cable-provider.com', then make sure 'my-cable-provider.com' is listed in the search domains. You can use the following link to find your full hostname:
</STRONG>
Thanks for the tips. My cable provider was listed in resolv.conf. I rolled the dice and fired up NetInfo Manager. I duplicated my -DHCP- setting, but substituted my cable "hostname" and ip number. I then ran the software and it worked.

Since I left the original -DHCP- option and the new item, I wonder if I will run into any dhcp problems in the future.

Scott
     
   
Thread Tools
Forum Links
Forum Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts
BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Top
Privacy Policy
All times are GMT -5. The time now is 09:52 PM.
All contents of these forums © 1995-2011 MacNN. All rights reserved.
Branding + Design: www.gesamtbild.com
vBulletin v.3.8.7 © 2000-2011, Jelsoft Enterprises Ltd., Content Relevant URLs by vBSEO 3.3.2