about summary refs log tree commit
diff options
context:
space:
mode:
authorGraham Barr <gbarr@pobox.com>2001-10-26 15:33:47 +0000
committerGraham Barr <gbarr@pobox.com>2001-10-26 15:33:47 +0000
commit65ef320c6a7af0fe1ea4576b2b4e8ee21e5af8a3 (patch)
treef2cc5a5d2315c70f53103682be643c2185a6d555
parentf473f405ee0d6abe93386f9f4f855981dfe73955 (diff)
downloadperl-libnet-65ef320c6a7af0fe1ea4576b2b4e8ee21e5af8a3.tar.gz
More fixes from the core for undefs
-rw-r--r--Net/Domain.pm20
1 files changed, 10 insertions, 10 deletions
diff --git a/Net/Domain.pm b/Net/Domain.pm
index a1c6490..62b9d96 100644
--- a/Net/Domain.pm
+++ b/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