Dear fellow monks,

I have a question regarding the Net::Domain-Module:
The sub _hostdomain() tries to look up the hostdomain by searching for the strings "domain" or "search" in /etc/resolv.conf, if the domainname is not already defined or returned by
return $domain = $NetConfig{'inet_domain'} if defined $NetConfig{'inet +_domain'};
The comment says, that trying to look up the domainname in /etc/resolv.conf is done to
... eliminate(s) calls to gethostbyname, and therefore DNS lookups. ...
Why not just ask "gethostbyname" (or, as the man-page [0] recommends: a non-obsolete variant) and leave it to the user to configure their name resolution the best possible way?

But back to the module:
If I get it correctly the module prefers the first entry of the last line starting with "domain" or "search".
Say we have a resolv.conf looking like this:
[...] domain example.org search internal.example.org example.org [...]
the module would say, that the hostdomain is "internal.example.org" though the real hostdomain was e.g. "example.org".

The resolv.conf (5) manpage [1] states:
...
search
The search list is normally determined from the local domain name; by default, it contains only the local domain name. This may be changed by listing the desired domain search path following the search keyword with spaces or tabs separating the names.
...
So if I see that correctly, relying on an entry in the "search" block is a bit risky, isn't it?

Thank you for reading all this and I'd be very happy if someone could give me a hint, why the module behaves this way (or corrects me if I got anything wrong ;-))?

[0]: http://www.kernel.org/doc/man-pages/online/pages/man3/gethostbyaddr.3.html
[1]: http://www.kernel.org/doc/man-pages/online/pages/man5/resolv.conf.5.html

In reply to Getting the FQDN using Net::Domain by nickolsen

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.