@ISA = qw(Exporter);
@EXPORT_OK = qw(hostname hostdomain hostfqdn domainname);
-$VERSION = "2.16"; # $Id: //depot/libnet/Net/Domain.pm#17 $
+$VERSION = "2.16"; # $Id: //depot/libnet/Net/Domain.pm#18 $
my($host,$domain,$fqdn) = (undef,undef,undef);
my $a = shift(@addr);
$host = gethostbyaddr($a,Socket::AF_INET());
last if defined $host;
- }
- if (index($host,'.') > 0) {
+ }
+ if (defined($host) && index($host,'.') > 0) {
$fqdn = $host;
($host,$domain) = $fqdn =~ /^([^\.]+)\.(.*)$/;
}
};
}
- # remove garbage
+ # remove garbage
$host =~ s/[\0\r\n]+//go;
$host =~ s/(\A\.+|\.+\Z)//go;
$host =~ s/\.\.+/\./go;
@hosts = ($host,"localhost");
- unless($host =~ /\./) {
+ unless (defined($host) && $host =~ /\./) {
my $dom = undef;
eval {
my $tmp = "\0" x 256; ## preload scalar
# Attempt to locate FQDN
- foreach (@hosts) {
+ foreach (grep {defined $_} @hosts) {
my @info = gethostbyname($_);
next unless @info;
# look at real name & aliases
my $site;
- foreach $site ($info[0], split(/ /,$info[1])) {
+ foreach $site ($info[0], split(/ /,$info[1])) {
if(rindex($site,".") > 0) {
# Extract domain from FQDN
- ($domain = $site) =~ s/\A[^\.]+\.//;
+ ($domain = $site) =~ s/\A[^\.]+\.//;
return $domain;
}
}
return $fqdn = $host if defined $host and $host =~ /^\d+(\.\d+){3}$/;
my @host = defined $host ? split(/\./, $host) : ('localhost');
- my @domain = defined $domain ? split(/\./, $domain) : ('');
+ my @domain = defined $domain ? split(/\./, $domain) : ();
my @fqdn = ();
# Determine from @host & @domain the FQDN
=for html <hr>
-I<$Id: //depot/libnet/Net/Domain.pm#17 $>
+I<$Id: //depot/libnet/Net/Domain.pm#18 $>
=cut