summaryrefslogtreecommitdiff
path: root/lib/Net/Ping.pm
diff options
context:
space:
mode:
authorJarkko Hietaniemi <jhi@iki.fi>2002-06-10 02:12:09 +0000
committerJarkko Hietaniemi <jhi@iki.fi>2002-06-10 02:12:09 +0000
commit15d96390cdc9f50119594a52390acfbf47d4f693 (patch)
tree354fa1935b736b1c5afcf463bdd12cc194608c2f /lib/Net/Ping.pm
parentcba2fd88758e554cd86f91751596696bfd7d3f5f (diff)
downloadperl-15d96390cdc9f50119594a52390acfbf47d4f693.tar.gz
Upgrade to Net::Ping 2.19.
p4raw-id: //depot/perl@17155
Diffstat (limited to 'lib/Net/Ping.pm')
-rw-r--r--lib/Net/Ping.pm38
1 files changed, 31 insertions, 7 deletions
diff --git a/lib/Net/Ping.pm b/lib/Net/Ping.pm
index 04cddc14d7..babe2b0b53 100644
--- a/lib/Net/Ping.pm
+++ b/lib/Net/Ping.pm
@@ -1,13 +1,13 @@
package Net::Ping;
-# $Id: Ping.pm,v 1.34 2002/05/06 17:37:54 rob Exp $
+# $Id: Ping.pm,v 1.1 2002/06/04 00:41:52 rob Exp $
require 5.002;
require Exporter;
use strict;
use vars qw(@ISA @EXPORT $VERSION
- $def_timeout $def_proto $max_datasize $pingstring $hires);
+ $def_timeout $def_proto $max_datasize $pingstring $hires $udp_source_verify);
use FileHandle;
use Socket qw( SOCK_DGRAM SOCK_STREAM SOCK_RAW PF_INET
inet_aton inet_ntoa sockaddr_in );
@@ -16,7 +16,7 @@ use POSIX qw(ECONNREFUSED);
@ISA = qw(Exporter);
@EXPORT = qw(pingecho);
-$VERSION = "2.18";
+$VERSION = "2.19";
# Constants
@@ -25,6 +25,7 @@ $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";
+$udp_source_verify = 1; # Default is to verify source endpoint
if ($^O =~ /Win32/i) {
# Hack to avoid this Win32 spewage:
@@ -163,6 +164,17 @@ sub bind
}
+# Description: Allow UDP source endpoint comparision to be
+# skipped for those remote interfaces that do
+# not response from the same endpoint.
+
+sub source_verify
+{
+ my $self = shift;
+ $udp_source_verify = 1 unless defined
+ ($udp_source_verify = ((defined $self) && (ref $self)) ? shift() : $self);
+}
+
# Description: allows the module to use milliseconds as returned by
# the Time::HiRes module
@@ -638,9 +650,10 @@ sub ping_udp
$from_saddr = recv($self->{"fh"}, $from_msg, 1500, UDP_FLAGS)
or last; # For example an unreachable host will make recv() fail.
($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 (!$udp_source_verify ||
+ (($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;
@@ -672,7 +685,7 @@ __END__
Net::Ping - check a remote host for reachability
-$Id: Ping.pm,v 1.34 2002/05/06 17:37:54 rob Exp $
+$Id: Ping.pm,v 1.1 2002/06/04 00:41:52 rob Exp $
=head1 SYNOPSIS
@@ -778,11 +791,22 @@ default) number of data bytes is 1 if the protocol is "udp" and 0
otherwise. The maximum number of data bytes that can be specified is
1024.
+=item $p->source_verify( { 0 | 1 } );
+
+Allows source endpoint verification to be enabled or disabled.
+This is useful for those remote destinations with multiples
+interfaces where the response may not originate from the same
+endpoint that the original destination endpoint was sent to.
+
+This is enabled by default.
+
=item $p->hires( { 0 | 1 } );
Causes this module to use Time::HiRes module, allowing milliseconds
to be returned by subsequent calls to ping().
+This is disabled by default.
+
=item $p->bind($local_addr);
Sets the source address from which pings will be sent. This must be