This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Net::Ping from version 2.55 to 2.61
authorSteve Hay <steve.m.hay@googlemail.com>
Tue, 24 Oct 2017 07:34:23 +0000 (08:34 +0100)
committerSteve Hay <steve.m.hay@googlemail.com>
Wed, 25 Oct 2017 07:15:33 +0000 (08:15 +0100)
This retains blead customizations 0fc44d0a18 and 7bfdd8260c. Other
customizations have been incorporated into the CPAN release.

Porting/Maintainers.pl
dist/Net-Ping/Changes
dist/Net-Ping/lib/Net/Ping.pm
dist/Net-Ping/t/010_pingecho.t
dist/Net-Ping/t/200_ping_tcp.t
dist/Net-Ping/t/400_ping_syn.t
dist/Net-Ping/t/410_syn_host.t
t/porting/customized.dat

index 289c89a..a9c5684 100755 (executable)
@@ -825,7 +825,7 @@ use File::Glob qw(:case);
     },
 
     'Net::Ping' => {
-        'DISTRIBUTION' => 'RURBAN/Net-Ping-2.55.tar.gz',
+        'DISTRIBUTION' => 'RURBAN/Net-Ping-2.61.tar.gz',
         'FILES'        => q[dist/Net-Ping],
         'EXCLUDED'     => [
             qw(README.md.PL),
@@ -836,9 +836,7 @@ use File::Glob qw(:case);
         'CUSTOMIZED'   => [
             qw( t/000_load.t
                 t/001_new.t
-                t/010_pingecho.t
-                t/500_ping_icmp.t
-                t/510_ping_udp.t),
+                t/500_ping_icmp.t),
         ],
 
     },
index c4c785e..2da51e7 100644 (file)
@@ -1,5 +1,35 @@
 CHANGES
 -------
+2.61  Sat Jun 17 13:12:58 CEST 2017 (rurban)
+       Bugfixes
+        - Fix ping_udp for a started udp echo server (PR#5 by Stephan Loyd)
+
+2.60  Mon Jun 12 20:14:13 CEST 2017 (rurban)
+       Bugfixes
+        - Fix t/400_ping_syn.t phases
+        - Try to handle Windows Socket::getnameinfo errors
+        - Improve some tests on missing network connections
+
+2.59  Tue Apr 18 08:46:48 2017 +0200 (rurban)
+       Bugfixes
+        - skip udp ping tests on more platforms: hpux, irix, aix.
+          also pingecho on os390.
+          (from perl5 core)
+       Features
+        - added a make release target
+
+2.58  Wed Feb  1 19:34:03 CET 2017 (rurban)
+       Features
+        - return the port num as 5th return value with ack (jfraire)
+
+2.57  Wed Feb  1 19:34:03 CET 2017 (rurban)
+       Bugfixes
+        - Resigned with new gpg key
+
+2.56  Wed Jan 18 16:00:00  2017 -0700 (bbb)
+       Bugfixes
+        - Stabilize tests
+
 2.55  Thu Oct 20 09:16:06  2016 +0200 (rurban)
 
        Bugfixes
index 13cbe81..ebd186b 100644 (file)
@@ -11,7 +11,7 @@ use Fcntl qw( F_GETFL F_SETFL O_NONBLOCK );
 use Socket qw( SOCK_DGRAM SOCK_STREAM SOCK_RAW AF_INET PF_INET IPPROTO_TCP
               SOL_SOCKET SO_ERROR SO_BROADCAST
                IPPROTO_IP IP_TOS IP_TTL
-               inet_ntoa inet_aton getnameinfo NI_NUMERICHOST sockaddr_in );
+               inet_ntoa inet_aton getnameinfo sockaddr_in );
 use POSIX qw( ENOTCONN ECONNREFUSED ECONNRESET EINPROGRESS EWOULDBLOCK EAGAIN
              WNOHANG );
 use FileHandle;
@@ -21,7 +21,7 @@ use Time::HiRes;
 @ISA = qw(Exporter);
 @EXPORT = qw(pingecho);
 @EXPORT_OK = qw(wakeonlan);
-$VERSION = "2.55";
+$VERSION = "2.61";
 
 # Globals
 
@@ -37,11 +37,11 @@ $syn_forking = 0;
 
 # Constants
 
-my $AF_INET6  = eval { Socket::AF_INET6() };
+my $AF_INET6  = eval { Socket::AF_INET6() } || 30;
 my $AF_UNSPEC = eval { Socket::AF_UNSPEC() };
-my $AI_NUMERICHOST = eval { Socket::AI_NUMERICHOST() };
-my $NI_NUMERICHOST = eval { Socket::NI_NUMERICHOST() };
-my $IPPROTO_IPV6   = eval { Socket::IPPROTO_IPV6() };
+my $AI_NUMERICHOST = eval { Socket::AI_NUMERICHOST() } || 4;
+my $NI_NUMERICHOST = eval { Socket::NI_NUMERICHOST() } || 2;
+my $IPPROTO_IPV6   = eval { Socket::IPPROTO_IPV6() }   || 41;
 #my $IPV6_HOPLIMIT  = eval { Socket::IPV6_HOPLIMIT() };  # ping6 -h 0-255
 my $qr_family = qr/^(?:(?:(:?ip)?v?(?:4|6))|${\AF_INET}|$AF_INET6)$/;
 my $qr_family4 = qr/^(?:(?:(:?ip)?v?4)|${\AF_INET})$/;
@@ -618,8 +618,11 @@ sub ping_external {
     ? ('ip' => $ip->{addr_in})
     : ('host' => $ip->{host});
 
-  eval { require Net::Ping::External; }
-    or croak('Protocol "external" not supported on your system: Net::Ping::External not found');
+  eval {
+    local @INC = @INC;
+    pop @INC if $INC[-1] eq '.';
+    require Net::Ping::External;
+  } or croak('Protocol "external" not supported on your system: Net::Ping::External not found');
   return Net::Ping::External::ping(@addr, timeout => $timeout,
                                    family => $family);
 }
@@ -1295,8 +1298,9 @@ sub ping_udp
         $done = 1;
       } else {
         ($from_port, $from_ip) = _unpack_sockaddr_in($from_saddr, $ip->{family});
+        my $addr_in = ref($ip) eq "HASH" ? $ip->{addr_in} : $ip;
         if (!$source_verify ||
-            (($from_ip eq $ip) &&        # Does the packet check out?
+            (($from_ip eq $addr_in) &&        # Does the packet check out?
              ($from_port == $self->{port_num}) &&
              ($from_msg eq $msg)))
         {
@@ -1379,7 +1383,7 @@ sub ping_syn
     }
   }
 
-  my $entry = [ $host, $ip, $fh, $start_time, $stop_time ];
+  my $entry = [ $host, $ip, $fh, $start_time, $stop_time, $self->{port_num} ];
   $self->{syn}->{$fh->fileno} = $entry;
   if ($self->{stop_time} < $stop_time) {
     $self->{stop_time} = $stop_time;
@@ -1558,7 +1562,7 @@ sub ack
           }
           # Everything passed okay, return the answer
           return wantarray ?
-            ($entry->[0], &time() - $entry->[3], $self->ntop($entry->[1]))
+            ($entry->[0], &time() - $entry->[3], $self->ntop($entry->[1]), $entry->[5])
             : $entry->[0];
         } else {
           warn "Corrupted SYN entry: unknown fd [$fd] ready!";
@@ -1712,10 +1716,8 @@ sub ntop {
     # Socket warns when undef is passed in, but it still works.
     my $port = getservbyname('echo', 'udp');
     my $sockaddr = _pack_sockaddr_in($port, $ip);
-    my ($error, $address) = getnameinfo($sockaddr, NI_NUMERICHOST);
-    if($error) {
-      croak $error;
-    }
+    my ($error, $address) = getnameinfo($sockaddr, $NI_NUMERICHOST);
+    croak $error if $error;
     return $address;
 }
 
@@ -1854,9 +1856,8 @@ sub _resolv {
         croak("getnameinfo($getaddr[0]->{addr}) failed - $err");
       }
     } else {
-      my $error = sprintf "getaddrinfo($h{host},,%s) failed - $err",
-                  ($family == AF_INET) ? "AF_INET" : "AF_INET6";
-      croak("$error");
+      croak(sprintf("getaddrinfo($h{host},,%s) failed - $err",
+                    $family == AF_INET ? "AF_INET" : "AF_INET6"));
     }
   # old way
   } else {
@@ -2242,8 +2243,8 @@ SYN queued using the ping() method.  If the timeout is
 reached before the TCP ACK is received, or if the remote
 host is not listening on the port attempted, then the TCP
 connection will not be established and ack() will return
-undef.  In list context, the host, the ack time, and the
-dotted ip string will be returned instead of just the host.
+undef.  In list context, the host, the ack time, the dotted ip 
+string, and the port number will be returned instead of just the host.
 If the optional $host argument is specified, the return
 value will be pertaining to that host only.
 This call simply does nothing if you are using any protocol
index 6516d16..90a934a 100644 (file)
@@ -12,7 +12,7 @@ use Test::More tests => 2;
 BEGIN {use_ok('Net::Ping')};
 
 TODO: {
-    local $TODO = "Not working on os390 smoker; may be a prermissions problem"
+    local $TODO = "Not working on os390 smoker; may be a permissions problem"
         if $^O eq 'os390';
     my $result = pingecho("127.0.0.1");
     is($result, 1, "pingecho works");
index 8ef4fb7..a26b2f1 100644 (file)
@@ -28,7 +28,7 @@ BEGIN {
 #
 # $ PERL_CORE=1 make test
 
-use Test::More tests => 13;
+use Test::More tests => 12;
 BEGIN {use_ok('Net::Ping');}
 
 my $p = new Net::Ping "tcp",9;
@@ -50,8 +50,13 @@ is($p->ping("172.29.249.249"), 0, "Can't reach 172.29.249.249");
 # Test a few remote servers
 # Hopefully they are up when the tests are run.
 
-foreach (qw(www.geocities.com www.wisc.edu
-           www.freeservers.com ftp.freeservers.com
-           yahoo.com www.yahoo.com www.about.com)) {
+if ($p->ping('google.com')) { # check for firewall
+  foreach (qw(google.com www.google.com www.wisc.edu
+              yahoo.com www.yahoo.com www.about.com)) {
     isnt($p->ping($_), 0, "Can ping $_");
+  }
+} else {
+ SKIP: {
+    skip "Cannot ping google.com: no TCP connection or firewall", 6;
+  }
 }
index e1cfcba..edad0fc 100644 (file)
@@ -4,7 +4,7 @@ BEGIN {
   if ($ENV{PERL_CORE}) {
     unless ($ENV{PERL_TEST_Net_Ping}) {
       print "1..0 # Skip: network dependent test\n";
-        exit;
+      exit;
     }
   }
   unless (eval "require Socket") {
@@ -33,25 +33,22 @@ BEGIN {
 # $ PERL_CORE=1 make test
 
 # Try a few remote servers
-my %webs;
-BEGIN {
-  %webs = (
+my %webs = (
   # Hopefully this is never a routeable host
   "172.29.249.249" => 0,
 
   # Hopefully all these web ports are open
-  "www.geocities.com." => 1,
   "www.freeservers.com." => 1,
   "yahoo.com." => 1,
   "www.yahoo.com." => 1,
   "www.about.com." => 1,
   "www.microsoft.com." => 1,
 );
-}
 
-use Test::More tests => 3 + 2 * keys %webs;
+use Test::More;
+plan tests => 3 + 2 * keys %webs;
 
-BEGIN {use_ok('Net::Ping')};
+use_ok('Net::Ping');
 
 my $can_alarm = eval {alarm 0; 1;};
 
@@ -73,6 +70,13 @@ isa_ok($p, 'Net::Ping', 'new() worked');
 # (Make sure getservbyname works in scalar context.)
 cmp_ok(($p->{port_num} = getservbyname("http", "tcp")), '>', 0, 'valid port');
 
+# check if network is up
+eval { $p->ping('www.google.com.'); };
+if ($@ =~ /getaddrinfo.*failed/) {
+  ok(1, "skip $@");
+  ok(1, "skip") for 0..12;
+  exit;
+}
 foreach my $host (keys %webs) {
   # ping() does dns resolution and
   # only sends the SYN at this point
@@ -80,13 +84,23 @@ foreach my $host (keys %webs) {
   is($p->ping($host), 1, "Can reach $host [" . ($p->{bad}->{$host} || "") . "]");
 }
 
+my $failed;
 Alarm(20);
 while (my $host = $p->ack()) {
-  is($webs{$host}, 1, "supposed to be up: http://$host/");
+  next if $host eq 'www.google.com.';
+  $failed += !is($webs{$host}, 1, "supposed to be up: http://$host/");
   delete $webs{$host};
 }
 
 Alarm(0);
 foreach my $host (keys %webs) {
-  is($webs{$host}, 0, "supposed to be down: http://$host/ [" . ($p->{bad}->{$host} || "") . "]");
+  $failed += !is($webs{$host}, 0,
+                "supposed to be down: http://$host/ [" . ($p->{bad}->{$host} || "") . "]");
+}
+
+if ($failed) {
+  diag ("NOTE: ",
+        "Network connectivity will be required for all tests to pass.\n",
+        "Firewalls may also cause some tests to fail, so test it ",
+        "on a clear network.");
 }
index 160c738..8e89e32 100644 (file)
@@ -41,7 +41,7 @@ BEGIN {
   "172.29.249.249" => 0,
 
   # Hopefully all these web ports are open
-  "www.geocities.com." => 1,
+  "www.google.com." => 1,
   "www.freeservers.com." => 1,
   "yahoo.com." => 1,
   "www.yahoo.com." => 1,
index f7e0bd7..5c0fe7c 100644 (file)
@@ -7,9 +7,7 @@ Math::Complex cpan/Math-Complex/t/Trig.t 2682526e23a161d54732c2a66393fe4a234d186
 Memoize cpan/Memoize/Memoize.pm 902092ff91cdec9c7b4bd06202eb179e1ce26ca2
 Net::Ping dist/Net-Ping/t/000_load.t deff5dc2ca54dae28cb19d3631427db127279ac2
 Net::Ping dist/Net-Ping/t/001_new.t 90c9d63509b3efc8941449fbd1ca8b807fa42040
-Net::Ping dist/Net-Ping/t/010_pingecho.t fd91db2daf78a994bd0210ab32cca2a46dff4f44
 Net::Ping dist/Net-Ping/t/500_ping_icmp.t a003daa5eaf215e58234786bb1fbfbebf669bf44
-Net::Ping dist/Net-Ping/t/510_ping_udp.t 6f01825a13a3ea294888bbd3af0aac95fb7f672f
 NEXT cpan/NEXT/lib/NEXT.pm 2c83d03ee361816e53ccb931137d314ab878d19f
 NEXT cpan/NEXT/t/next.t 66fd60eb0f75b6f3eea95d1dee745f9a7a348146
 Pod::Checker cpan/Pod-Checker/t/pod/contains_bad_pod.xr 73538fd80dfe6e19ad561fe034009b44460208f6