@ISA = qw(Exporter);
@EXPORT = qw(pingecho);
-$VERSION = "2.42";
+$VERSION = "2.43";
# Constants
$self->{"seq"} = 0; # For counting packets
if ($self->{"proto"} eq "udp") # Open a socket
{
- $self->{"proto_num"} = (getprotobyname('udp'))[2] ||
+ $self->{"proto_num"} = eval { (getprotobyname('udp'))[2] } ||
croak("Can't udp protocol by name");
$self->{"port_num"} = (getservbyname('echo', 'udp'))[2] ||
croak("Can't get udp echo port by name");
elsif ($self->{"proto"} eq "icmp")
{
croak("icmp ping requires root privilege") if ($> and $^O ne 'VMS' and $^O ne 'cygwin');
- $self->{"proto_num"} = (getprotobyname('icmp'))[2] ||
+ $self->{"proto_num"} = eval { (getprotobyname('icmp'))[2] } ||
croak("Can't get icmp protocol by name");
$self->{"pid"} = $$ & 0xffff; # Save lower 16 bits of pid
$self->{"fh"} = FileHandle->new();
}
elsif ($self->{"proto"} eq "tcp" || $self->{"proto"} eq "stream")
{
- $self->{"proto_num"} = (getprotobyname('tcp'))[2] ||
+ $self->{"proto_num"} = eval { (getprotobyname('tcp'))[2] } ||
croak("Can't get tcp protocol by name");
$self->{"port_num"} = (getservbyname('echo', 'tcp'))[2] ||
croak("Can't get tcp echo port by name");
}
elsif ($self->{"proto"} eq "syn")
{
- $self->{"proto_num"} = (getprotobyname('tcp'))[2] ||
+ $self->{"proto_num"} = eval { (getprotobyname('tcp'))[2] } ||
croak("Can't get tcp protocol by name");
$self->{"port_num"} = (getservbyname('echo', 'tcp'))[2] ||
croak("Can't get tcp echo port by name");
# Root access is required to actually perform icmp testing.
use strict;
+use Config;
BEGIN {
unless (eval "require Socket") {
print "1..0 \# Skip: no Socket\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
use Test::More tests => 2;
# I do not know of any servers that support udp echo anymore.
use strict;
+use Config;
BEGIN {
unless (eval "require Socket") {
print "1..0 \# Skip: no echo port\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
use Test::More tests => 2;
# Test to make sure object can be instantiated for tcp protocol.
use strict;
+use Config;
BEGIN {
unless (eval "require Socket") {
print "1..0 \# Skip: no echo port\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
use Test::More tests => 2;
# Test to make sure object can be instantiated for stream protocol.
use strict;
+use Config;
BEGIN {
unless (eval "require Socket") {
print "1..0 \# Skip: no echo port\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
use Test::More tests => 2;
# Test to make sure object can be instantiated for syn protocol.
use strict;
+use Config;
BEGIN {
unless (eval "require Socket") {
print "1..0 \# Skip: no echo port\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
# Testing service_check method using tcp and syn protocols.
+use Config;
+
BEGIN {
unless (eval "require IO::Socket") {
print "1..0 \# Skip: no IO::Socket\n";
print "1..0 \# Skip: no echo port\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
use strict;
# Root access is required.
use strict;
+use Config;
BEGIN {
unless (eval "require Socket") {
print "1..0 \# Skip: no Socket\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
use Test::More tests => 2;
# Test to perform udp protocol testing.
use strict;
+use Config;
sub isWindowsVista {
return unless $^O eq 'MSWin32' or $^O eq "cygwin";
SKIP: {
skip "No udp echo port", 1 unless getservbyname('echo', 'udp');
skip "udp ping blocked by Window's default settings", 1 if isWindowsVista();
+ skip "No getprotobyname", 1 unless $Config{d_getpbyname};
my $p = new Net::Ping "udp";
is($p->ping("127.0.0.1"), 1);
}
# Test to perform icmp protocol testing.
# Root access is required.
+use Config;
+
BEGIN {
unless (eval "require Socket") {
print "1..0 \# Skip: no Socket\n";
exit;
}
+ unless ($Config{d_getpbyname}) {
+ print "1..0 \# Skip: no getprotobyname\n";
+ exit;
+ }
}
use Test::More qw(no_plan);