@ISA = qw(Exporter);
@EXPORT_OK = qw(hostname hostdomain hostfqdn domainname);
-$VERSION = "2.14"; # $Id: //depot/libnet/Net/Domain.pm#15 $
+$VERSION = "2.19_01"; # $Id: //depot/libnet/Net/Domain.pm#21 $
my($host,$domain,$fqdn) = (undef,undef,undef);
# those on dialup systems.
local *RES;
+ local($_);
if(open(RES,"/etc/resolv.conf")) {
while(<RES>) {
my $host = _hostname();
my(@hosts);
- local($_);
@hosts = ($host,"localhost");
: undef;
};
+ if ( $^O eq 'VMS' ) {
+ $dom ||= $ENV{'TCPIP$INET_DOMAIN'}
+ || $ENV{'UCX$INET_DOMAIN'};
+ }
+
chop($dom = `domainname 2>/dev/null`)
- unless(defined $dom || $^O eq 'MSWin32');
+ unless(defined $dom || $^O =~ /^(?:cygwin|MSWin32)/);
if(defined $dom) {
my @h = ();
+ $dom =~ s/^\.+//;
while(length($dom)) {
push(@h, "$host.$dom");
- $dom =~ s/^[^.]+.//;
+ $dom =~ s/^[^.]+.+// or last;
}
unshift(@hosts,@h);
}
# eleminate DNS lookups
return $fqdn = $host . "." . $domain
- if($host !~ /\./ && $domain =~ /\./);
+ if(defined $host and defined $domain
+ and $host !~ /\./ and $domain =~ /\./);
# For hosts that have no name, just an IP address
- return $fqdn = $host if $host =~ /^\d+(\.\d+){3}$/;
+ return $fqdn = $host if defined $host and $host =~ /^\d+(\.\d+){3}$/;
- my @host = split(/\./, $host);
- my @domain = split(/\./, $domain);
+ my @host = defined $host ? split(/\./, $host) : ('localhost');
+ my @domain = defined $domain ? split(/\./, $domain) : ();
my @fqdn = ();
# Determine from @host & @domain the FQDN
=head1 SYNOPSIS
- use Net::Domain qw(hostname hostfqdn hostdomain);
+ use Net::Domain qw(hostname hostfqdn hostdomain domainname);
=head1 DESCRIPTION
Identify and return the FQDN of the current host.
+=item domainname ()
+
+An alias for hostfqdn ().
+
=item hostname ()
Returns the smallest part of the FQDN which can be used to identify the host.
=for html <hr>
-I<$Id: //depot/libnet/Net/Domain.pm#15 $>
+I<$Id: //depot/libnet/Net/Domain.pm#21 $>
=cut