develooper Front page | perl.perl5.porters | Postings from December 2000

[ID 20001214.002] Net::Ping patch

Thread Next
From:
Jonathan Stowe
Date:
December 14, 2000 01:34
Subject:
[ID 20001214.002] Net::Ping patch
Message ID:
Pine.LNX.4.10.10012140805480.19767-200000@orpheus.gellyfish.com
--- Ping.pm~	Thu Dec 14 07:12:10 2000
+++ Ping.pm	Thu Dec 14 07:56:22 2000
@@ -369,14 +369,20 @@
         elsif ($nfound)         # A packet is waiting
         {
             $from_msg = "";
-            $from_saddr = recv($self->{"fh"}, $from_msg, 1500, $flags);
-            ($from_port, $from_ip) = sockaddr_in($from_saddr);
-            if (($from_ip eq $ip) &&        # Does the packet check out?
-                ($from_port == $self->{"port_num"}) &&
-                ($from_msg eq $msg))
+            if( $from_saddr = recv($self->{"fh"}, $from_msg, 1500, $flags) )
             {
-                $ret = 1;       # It's a winner
-                $done = 1;
+               ($from_port, $from_ip) = sockaddr_in($from_saddr);
+               if (($from_ip eq $ip) &&        # Does the packet check out?
+                   ($from_port == $self->{"port_num"}) &&
+                   ($from_msg eq $msg))
+               {
+                   $ret = 1;       # It's a winner
+                   $done = 1;
+               }
+            }
+            else # probably no UDP echo service running.  But persist.
+            {
+               $done = 0;
             }
         }
         else                    # Oops, timed out
@@ -454,6 +460,11 @@
 received from the remote host and the received packet contains the
 same data as the packet that was sent, the remote host is considered
 reachable.  This protocol does not require any special privileges.
+
+It should be borne in mind that, for both tcp and udp ping, a host
+will be reported as unreachable if if not is not running the
+appropriate echo service.  For Unix-like systems see L<inetd(8)> for
+more information.
 
 If the "icmp" protocol is specified, the ping() method sends an icmp
 echo message to the remote host, which is what the UNIX ping program

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About