Re: Getting the domain name
- From: Michael B Allen <mba2000@xxxxxxxxxx>
- Date: Fri, 23 Mar 2007 17:25:21 -0400
On Fri, 23 Mar 2007 15:49:35 -0500, James Antill wrote:
On Fri, 23 Mar 2007 14:06:20 -0400, Michael B Allen wrote:
Can anyone recommend a portable way of getting the domain name of the
local machine? I find it amazing that there's no builtin method for
doing this (gethostname does not necessarily contain the domain).
What you might want[1] is gethostname() -> getnameinfo(), and then
chop the first node off. But that assumes the above will give you a
domain name (and/or that you have one), which isn't guaranteed.
Hi James,
Do you mean getaddrinfo and look at ai_canonname? The getnameinfo function
takes an address.
And at any rate if gethostname doesn't provide a domain name that's not
going to work anyway. Thus this post.
[1] This is what dnsdomainname in net-tools does, for instance.
Actually on the system in question even hostname -f doesn't quite give me
what I want. It produces 'name.domain.com.' with a '.' at the end. Clearly
it's just reading it from /etc/hosts which has that '.'.
I want something that favors doing a PTR lookup in DNS on the IP of the
default interface.
Actually what I want is something that tries whatever it has to until
it comes up with a name that has more than one label and ends on .com,
..net, .local etc.
This is one of those things that you'd think someone would have
solved long ago. Lot's of software use domain names as a namespace
(e.g. Kerberos).
Mike
.
- Follow-Ups:
- Re: Getting the domain name
- From: Gordon Burditt
- Re: Getting the domain name
- References:
- Getting the domain name
- From: Michael B Allen
- Re: Getting the domain name
- From: James Antill
- Getting the domain name
- Prev by Date: Re: Getting the domain name
- Next by Date: poll() revents variable
- Previous by thread: Re: Getting the domain name
- Next by thread: Re: Getting the domain name
- Index(es):
Relevant Pages
|