*BSD News Article 17914


Return to BSD News archive

Newsgroups: comp.unix.bsd
Path: sserve!newshost.anu.edu.au!munnari.oz.au!uunet!emba-news.uvm.edu!trantor.emba.uvm.edu!wollman
From: wollman@trantor.emba.uvm.edu (Garrett Wollman)
Subject: Re: domain name
Message-ID: <1993Jul3.190436.16183@uvm.edu>
Sender: news@uvm.edu
Organization: University of Vermont, EMBA Computer Facility
References: <1993Jul2.203312.2808@das.harvard.edu>
Date: Sat, 3 Jul 1993 19:04:36 GMT
Lines: 27

In article <1993Jul2.203312.2808@das.harvard.edu> jiu@kepler.uucp (Haibin Jiu) writes:
>Does anyone know of a sure way to obtain the correct domainname,
>hostname, or a combination of both?

Sure...

gethostname(buf, sizeof buf - 1);
hp = gethostbyname(buf);

Now inspect hp->h_name and hp->h_aliases until you find something that
looks fully-qualified.  If the system has been configured correctly,
then hp->h_name should be the ``official'' FQDN for this host.  If the
site has been configured incorrectly, then you might wish to make use
of an auxiliary program, linked with whatever library will ensure you
get the DNS resolver and not YP, which does a gethostbyaddr() on
hp->h_addr_list[0].

You should also have a configurable parameter for Suns with broken
libraries, for which gethostbyname(myname) can result in a core dump.

-GAWollman

-- 
Garrett A. Wollman   | Shashish is simple, it's discreet, it's brief. ... 
wollman@emba.uvm.edu | Shashish is the bonding of hearts in spite of distance.
uvm-gen!wollman      | It is a bond more powerful than absence.  We like people
UVM disagrees.       | who like Shashish.  - Claude McKenzie + Florent Vollant