updated threads docs
[p5sagit/p5-mst-13.2.git] / lib / Net / Ping.pm
index 874f1c5..f689047 100644 (file)
@@ -1,6 +1,6 @@
 package Net::Ping;
 
-# $Id: Ping.pm,v 1.27 2002/04/02 02:01:21 rob Exp $
+# $Id: Ping.pm,v 1.33 2002/05/03 21:54:59 rob Exp $
 
 require 5.002;
 require Exporter;
@@ -12,20 +12,26 @@ use FileHandle;
 use Socket qw( SOCK_DGRAM SOCK_STREAM SOCK_RAW PF_INET
                inet_aton inet_ntoa sockaddr_in );
 use Carp;
-use Errno qw(ECONNREFUSED);
+use POSIX qw(ECONNREFUSED);
 
 @ISA = qw(Exporter);
 @EXPORT = qw(pingecho);
-$VERSION = "2.14";
+$VERSION = "2.17";
 
 # Constants
 
 $def_timeout = 5;           # Default timeout to wait for a reply
-$def_proto = "udp";         # Default protocol to use for pinging
+$def_proto = "tcp";         # Default protocol to use for pinging
 $max_datasize = 1024;       # Maximum data bytes in a packet
 # The data we exchange with the server for the stream protocol
 $pingstring = "pingschwingping!\n";
 
+if ($^O =~ /Win32/i) {
+  # Hack to avoid this Win32 spewage:
+  # Your vendor has not defined POSIX macro ECONNREFUSED
+  *ECONNREFUSED = sub {10061;}; # "Unknown Error" Special Win32 Response?
+};
+
 # Description:  The pingecho() subroutine is provided for backward
 # compatibility with the original Net::Ping.  It accepts a host
 # name/IP and an optional timeout in seconds.  Create a tcp ping
@@ -367,8 +373,7 @@ sub ping_tcp
 
   $@ = ""; $! = 0;
   $ret = $self -> tcp_connect( $ip, $timeout);
-  $ret = 1 if $! == ECONNREFUSED  # Connection refused
-    || $@ =~ /Unknown Error/i;    # Special Win32 response?
+  $ret = 1 if $! == ECONNREFUSED;  # Connection refused
   $self->{"fh"}->close();
   return $ret;
 }
@@ -598,7 +603,6 @@ sub ping_udp
       $ret,               # The return value
       $msg,               # Message to be echoed
       $finish_time,       # Time ping should be finished
-      $ping_time,         # Time ping took to complete
       $done,              # Set to 1 when we are done pinging
       $rbits,             # Read bits, filehandles for reading
       $nfound,            # Number of ready filehandles found
@@ -617,7 +621,6 @@ sub ping_udp
   vec($rbits, $self->{"fh"}->fileno(), 1) = 1;
   $ret = 0;                   # Default to unreachable
   $done = 0;
-  $ping_time = $timeout;
   $finish_time = &time() + $timeout;       # Ping needs to be done by then
   while (!$done && $timeout > 0)
   {
@@ -648,8 +651,7 @@ sub ping_udp
       $done = 1;
     }
   }
-  $ping_time -= $timeout;
-  return wantarray ? ($ret, $ping_time) : $ret;
+  return $ret;
 }
 
 # Description:  Close the connection unless we are using the tcp
@@ -670,7 +672,7 @@ __END__
 
 Net::Ping - check a remote host for reachability
 
-$Id: Ping.pm,v 1.27 2002/04/02 02:01:21 rob Exp $
+$Id: Ping.pm,v 1.33 2002/05/03 21:54:59 rob Exp $
 
 =head1 SYNOPSIS