Skip to content

Commit 8198bf1

Browse files
dist/Net-Ping - Update (selectively) to 2.75
1 parent c65514c commit 8198bf1

File tree

8 files changed

+44
-17
lines changed

8 files changed

+44
-17
lines changed

Porting/Maintainers.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -866,7 +866,7 @@ package Maintainers;
866866
},
867867

868868
'Net::Ping' => {
869-
'DISTRIBUTION' => 'RURBAN/Net-Ping-2.75.tar.gz',
869+
'DISTRIBUTION' => 'RURBAN/Net-Ping-2.76.tar.gz',
870870
'FILES' => q[dist/Net-Ping],
871871
'EXCLUDED' => [
872872
qr{^\.[awc]},

dist/Net-Ping/Changes

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
CHANGES
22
-------
3+
2.76 2025-09-08 08:39:55 rurban
4+
Features
5+
- use SOCK_DRGAM for ICMP under linux, which requires no root.
6+
(Owen DeLong GH #33)
7+
Minor
8+
- Improve make release
39
2.75 2022-09-01 12:44:03 rurban
410
Minor
511
- Modernized the synopsis (PR #31)

dist/Net-Ping/lib/Net/Ping.pm

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ use Time::HiRes;
2222
@ISA = qw(Exporter);
2323
@EXPORT = qw(pingecho);
2424
@EXPORT_OK = qw(wakeonlan);
25-
$VERSION = "2.76";
25+
$VERSION = "2.77";
2626

2727
# Globals
2828

@@ -227,13 +227,18 @@ sub new
227227
}
228228
elsif ($self->{proto} eq "icmp")
229229
{
230-
croak("icmp ping requires root privilege") if !_isroot();
230+
croak("icmp ping requires root privilege") if !_isroot() and $^O ne "linux";
231231
$self->{proto_num} = eval { (getprotobyname('icmp'))[2] } ||
232232
croak("Can't get icmp protocol by name");
233233
$self->{pid} = $$ & 0xffff; # Save lower 16 bits of pid
234234
$self->{fh} = FileHandle->new();
235-
socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) ||
236-
croak("icmp socket error - $!");
235+
if ($^O eq "linux" and !_isroot()) {
236+
socket($self->{fh}, PF_INET, SOCK_DGRAM, $self->{proto_num}) ||
237+
croak("icmp socket error - $!");
238+
} else {
239+
socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) ||
240+
croak("icmp socket error - $!");
241+
}
237242
$self->_setopts();
238243
if ($self->{'ttl'}) {
239244
setsockopt($self->{fh}, IPPROTO_IP, IP_TTL, pack("I*", $self->{'ttl'}))
@@ -250,8 +255,13 @@ sub new
250255
croak("Can't get ipv6-icmp protocol by name"); # 58
251256
$self->{pid} = $$ & 0xffff; # Save lower 16 bits of pid
252257
$self->{fh} = FileHandle->new();
253-
socket($self->{fh}, $AF_INET6, SOCK_RAW, $self->{proto_num}) ||
254-
croak("icmp socket error - $!");
258+
if ($^O eq 'linux' and !_isroot()) {
259+
socket($self->{fh}, $AF_INET6, SOCK_DGRAM, $self->{proto_num}) ||
260+
croak("icmp socket error - $!");
261+
} else {
262+
socket($self->{fh}, $AF_INET6, SOCK_RAW, $self->{proto_num}) ||
263+
croak("icmp socket error - $!");
264+
}
255265
$self->_setopts();
256266
if ($self->{'gateway'}) {
257267
my $g = $self->{gateway};
@@ -715,8 +725,13 @@ sub ping_icmp
715725
$timeout = $self->{timeout} if !defined $timeout and $self->{timeout};
716726
$timestamp_msg = $self->{message_type} && $self->{message_type} eq 'timestamp' ? 1 : 0;
717727

718-
socket($self->{fh}, $ip->{family}, SOCK_RAW, $self->{proto_num}) ||
719-
croak("icmp socket error - $!");
728+
if ($^O eq 'linux' and !_isroot()) {
729+
socket($self->{fh}, $ip->{family}, SOCK_DGRAM, $self->{proto_num}) ||
730+
croak("icmp socket error - $!");
731+
} else {
732+
socket($self->{fh}, $ip->{family}, SOCK_RAW, $self->{proto_num}) ||
733+
croak("icmp socket error - $!");
734+
}
720735

721736
if (defined $self->{local_addr} &&
722737
!CORE::bind($self->{fh}, _pack_sockaddr_in(0, $self->{local_addr}))) {
@@ -2366,11 +2381,13 @@ enabled.
23662381
X<ping_icmp>
23672382
23682383
The L</ping> method used with the icmp protocol.
2384+
Under Linux under a non-root account this uses now SOCK_DGRAM.
23692385
23702386
=item $p->ping_icmpv6([$host, $timeout, $family])
23712387
X<ping_icmpv6>
23722388
23732389
The L</ping> method used with the icmpv6 protocol.
2390+
Under Linux under a non-root account this uses now SOCK_DGRAM.
23742391
23752392
=item $p->ping_stream([$host, $timeout, $family])
23762393
X<ping_stream>

dist/Net-Ping/t/000_load.t

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,5 @@ BEGIN {
1212
use_ok( 'Net::Ping' ) || print "No Net::Ping!\n";
1313
}
1414

15-
note( "Testing Net::Ping $Net::Ping::VERSION, Perl $], $^X" );
15+
diag( "Testing Net::Ping $Net::Ping::VERSION, Perl $] on $^O, $^X" );
1616

dist/Net-Ping/t/010_pingecho.t

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use warnings;
22
use strict;
33
use Config;
44

5+
56
BEGIN {
67
unless (my $port = getservbyname('echo', 'tcp')) {
78
print "1..0 \# Skip: no echo port\n";
@@ -19,6 +20,7 @@ BEGIN {use_ok('Net::Ping')};
1920
TODO: {
2021
local $TODO = "Not working on os390 smoker; may be a permissions problem"
2122
if $^O eq 'os390';
23+
$TODO = "Not working on freebsd" if $^O eq 'freebsd';
2224
my $result = pingecho("127.0.0.1");
2325
is($result, 1, "pingecho 127.0.0.1 works");
2426
}

dist/Net-Ping/t/450_service.t

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ is($p->ping("127.0.0.1"), 1, 'first port is reachable');
7878
$p->{port_num} = $port2;
7979

8080
{
81-
local $TODO = "Believed not to work on $^O" if $^O =~ /^(?:MSWin32|os390|cygwin)$/;
81+
local $TODO = "Believed not to work on $^O" if $^O =~ /^(?:hpux|MSWin32|os390|cygwin|freebsd)$/;
8282
is($p->ping("127.0.0.1"), 1, 'second port is reachable');
8383
}
8484

@@ -133,7 +133,7 @@ SKIP: {
133133

134134
{
135135
local $TODO = "Believed not to work on $^O"
136-
if $^O =~ /^(?:MSWin32|os390|cygwin)$/;
136+
if $^O =~ /^(?:hpux|MSWin32|os390|cygwin|freebsd)$/;
137137
is($p->ack(), '127.0.0.1', 'IP should be reachable');
138138
}
139139
}

dist/Net-Ping/t/500_ping_icmp.t

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,14 @@ BEGIN {
1919
}
2020

2121
my $is_devel = $ENV{PERL_CORE} || -d ".git" ? 1 : 0;
22+
$ENV{TEST_PING_HOST} = "127.0.0.1" if $ENV{NO_NETWORK_TESTING};
2223
# Note this rawsocket test code is considered anti-social in p5p and was removed in
2324
# their variant.
24-
# See http://nntp.perl.org/group/perl.perl5.porters/240707
25+
# See https://www.nntp.perl.org/group/perl.perl5.porters/2016/11/msg240707.html
2526
# Problem is that ping_icmp needs root perms, and previous bugs were
2627
# never caught. So I rather execute it via sudo in the core test suite
2728
# and on devel CPAN dirs, than not at all and risk further bitrot of this API.
28-
if ( 0 && !Net::Ping::_isroot()) { # disable in blead via 7bfdd8260c
29+
if (!Net::Ping::_isroot()) {
2930
my $file = __FILE__;
3031
my $lib = $ENV{PERL_CORE} ? '-I../../lib' : '-Mblib';
3132
if ($is_devel and $Config{ccflags} =~ /fsanitize=address/ and $^O eq 'linux') {
@@ -54,7 +55,7 @@ if ( 0 && !Net::Ping::_isroot()) { # disable in blead via 7bfdd8260c
5455

5556
SKIP: {
5657
skip "icmp ping requires root privileges.", 2
57-
if !Net::Ping::_isroot() or $^O eq 'MSWin32';
58+
if ($^O ne 'Linux' and !Net::Ping::_isroot()) or $^O eq 'MSWin32';
5859
my $p = new Net::Ping "icmp";
5960
is($p->message_type(), 'echo', "default icmp message type is 'echo'");
6061
# message_type fails on wrong message type

dist/Net-Ping/t/501_ping_icmpv6.t

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,8 @@ BEGIN {
1919
}
2020

2121
my $is_devel = $ENV{PERL_CORE} || -d ".git" ? 1 : 0;
22-
if (0 && !Net::Ping::_isroot()) {
22+
$ENV{TEST_PING6_HOST} = "::1" if $ENV{NO_NETWORK_TESTING};
23+
if (!Net::Ping::_isroot()) {
2324
my $file = __FILE__;
2425
my $lib = $ENV{PERL_CORE} ? '-I../../lib' : '-Mblib';
2526
# -n prevents from asking for a password. rather fail then
@@ -59,7 +60,7 @@ SKIP: {
5960
my $rightip = "2001:4860:4860::8888"; # pingable ip of google's dnsserver
6061
# for a firewalled ipv6 network try an optional local ipv6 host
6162
$rightip = $ENV{TEST_PING6_HOST} if $ENV{TEST_PING6_HOST};
62-
my $wrongip = "2001:4860:4860::1234"; # non existing ip
63+
my $wrongip = "2001:db8::"; # non existing ip
6364
# diag "Pinging existing IPv6 ";
6465
my $result = $p->ping($rightip);
6566
if ($result == 1) {

0 commit comments

Comments
 (0)