From: Graham Barr Date: Fri, 26 Oct 2001 13:32:47 +0000 (+0000) Subject: More fixes that were made to the core and not in the libnet src X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=43a88cffd14d50c5c0cbd97e49ce3d1038ccc518;p=p5sagit%2Fp5-mst-13.2.git More fixes that were made to the core and not in the libnet src p4raw-id: //depot/perl@12683 --- diff --git a/lib/Net/Domain.pm b/lib/Net/Domain.pm index a1c6490..62b9d96 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
-I<$Id: //depot/libnet/Net/Domain.pm#17 $> +I<$Id: //depot/libnet/Net/Domain.pm#18 $> =cut