Solved

gethostbyname

Posted on 1997-06-17
3
430 Views
Last Modified: 2013-12-23
How to get in C full name of local host, when gethostbyname returns only short one? In aliases too.
I don't want ask DNS in my program. Is field "domain" in /etc/resolv.conf right place to find domain of local host ?
I'm passing name returned by gethostname to gethostbyname.
I want my program to work on any host.
0
Comment
Question by:andzei
3 Comments
 
LVL 1

Expert Comment

by:strobert
ID: 1582153
what are you passing into gethostbyname? "localhost"?
0
 

Author Comment

by:andzei
ID: 1582154
Edited text of question
0
 
LVL 2

Accepted Solution

by:
pxh earned 100 total points
ID: 1582155
Yes. The resolv.conf must contain the name of your local domain. So if you add it to your (short) hostname you will get the full address of your host. However, if a machine is not relying on DNS this file may not be present (see below). But then, there might also no domainname defined on that machine.

Don't try to read /etc/defaultdomain or the output from the command domainname. At least on Solaris machines they may return the NIS domain name, which might be absolutely different from the Internet domain.

Your wish that the application runs on any host is very ambitious. What about a host with networking not set up? Or not using DNS? You may have to specify what the application does and what networking services are essential for it.

Hope this helps,

Peter (pxh@mpe-garching.mpg.de)

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Don’t let your business fall victim to the coming apocalypse – use our Survival Guide for the Fax Apocalypse to identify the risks and signs of zombie fax activities at your business.
For many of us, the  holiday season kindles the natural urge to give back to our friends, family members and communities. While it's easy for friends to notice the impact of such deeds, understanding the contributions of businesses and enterprises i…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…
After creating this article (http://www.experts-exchange.com/articles/23699/Setup-Mikrotik-routers-with-OSPF.html), I decided to make a video (no audio) to show you how to configure the routers and run some trace routes and pings between the 7 sites…

932 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now