Easy way to find hostname/domainname

Mark Towfiq towfiq at interlan.Interlan.COM
Thu Oct 4 00:38:01 AEST 1990


In article <1990Sep28.162012.14325 at saukh.rd.jvd.su>
nms at saukh.rd.jvd.su (Nickolay Saukh) writes:

   I need advice/software to figure out the hostname & domain name for C
   programs and shell scripts. In C for hostname it seems to be quite easy:

   [how to get hostname deleted]

   But how to find domain name? Look at some file with magic name? What the
   name should be (with portabily issues in mind)?

In C, I would do a gethostbyname() to get the FQDN, and then take
everything after the first "." to be the domain.

   The same problem for shell scripts. I know about 'hostname' command in
   BSD world, 'uuname -l' for SV world (and 'uname' also).

So you want the FQDN in a shell script?  I do not know of a portable
way to do this.  You could look for /etc/resolv.conf, or you could
look for a program like "host", or "nslookup", and maybe AWK its
output?



More information about the Comp.unix.programmer mailing list