diff options
author | Graham Barr <gbarr@pobox.com> | 2001-10-26 13:32:47 +0000 |
---|---|---|
committer | Graham Barr <gbarr@pobox.com> | 2001-10-26 13:32:47 +0000 |
commit | 43a88cffd14d50c5c0cbd97e49ce3d1038ccc518 (patch) | |
tree | f64941284375762207d6191b5de544110ab49fb1 /lib/Net/Domain.pm | |
parent | 13d11c6e852aaac8eff257adcc793baa531c16b1 (diff) | |
download | perl-43a88cffd14d50c5c0cbd97e49ce3d1038ccc518.tar.gz |
More fixes that were made to the core and not in the libnet src
p4raw-id: //depot/perl@12683
Diffstat (limited to 'lib/Net/Domain.pm')
-rw-r--r-- | lib/Net/Domain.pm | 20 |
1 files changed, 10 insertions, 10 deletions
diff --git a/lib/Net/Domain.pm b/lib/Net/Domain.pm index a1c64909ab..62b9d96116 100644 --- a/lib/Net/Domain.pm +++ b/lib/Net/Domain.pm @@ -16,7 +16,7 @@ use Net::Config; @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); @@ -36,8 +36,8 @@ sub _hostname { 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 =~ /^([^\.]+)\.(.*)$/; } @@ -102,7 +102,7 @@ sub _hostname { }; } - # remove garbage + # remove garbage $host =~ s/[\0\r\n]+//go; $host =~ s/(\A\.+|\.+\Z)//go; $host =~ s/\.\.+/\./go; @@ -147,7 +147,7 @@ sub _hostdomain { @hosts = ($host,"localhost"); - unless($host =~ /\./) { + unless (defined($host) && $host =~ /\./) { my $dom = undef; eval { my $tmp = "\0" x 256; ## preload scalar @@ -179,19 +179,19 @@ sub _hostdomain { # 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; } } @@ -231,7 +231,7 @@ sub domainname { 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 @@ -331,6 +331,6 @@ it under the same terms as Perl itself. =for html <hr> -I<$Id: //depot/libnet/Net/Domain.pm#17 $> +I<$Id: //depot/libnet/Net/Domain.pm#18 $> =cut |