Solved

gethostbyname

Posted on 1997-06-17
3
435 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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…
I had an issue with InstallShield not being able to use Computer Browser service on Windows Server 2012. Here is the solution I found.
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
This video gives you a great overview about bandwidth monitoring with SNMP and WMI with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're looking for how to monitor bandwidth using netflow or packet s…

752 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