Skip to content

Commit

Permalink
Release 2.76: use SOCK_DRGAM for ICMP under linux,
Browse files Browse the repository at this point in the history
which requires no root. Owen DeLong GH #33
  • Loading branch information
Reini Urban committed Dec 5, 2024
1 parent 0eef27a commit 00c4de5
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
4 changes: 4 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
CHANGES
-------
2.76 2024-12-05 13:12:08 rurban
Features
- use SOCK_DRGAM for ICMP under linux, which requires no root.
(Owen DeLong GH #33)
2.75 2022-09-01 12:44:03 rurban
Minor
- Modernized the synopsis (PR #31)
Expand Down
13 changes: 9 additions & 4 deletions lib/Net/Ping.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ use Time::HiRes;
@ISA = qw(Exporter);
@EXPORT = qw(pingecho);
@EXPORT_OK = qw(wakeonlan);
$VERSION = "2.75";
$VERSION = "2.76";

# Globals

Expand Down Expand Up @@ -227,13 +227,18 @@ sub new
}
elsif ($self->{proto} eq "icmp")
{
croak("icmp ping requires root privilege") if !_isroot();
croak("icmp ping requires root privilege") if !_isroot() && ($^O ne "linux");
$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();
socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) ||
croak("icmp socket error - $!");
if ($^O eq "linux") {
socket($self->{fh}, PF_INET, SOCK_DGRAM, $self->{proto_num}) ||
croak("icmp socket error - $!");
} else {
socket($self->{fh}, PF_INET, SOCK_RAW, $self->{proto_num}) ||
croak("icmp socket error - $!");
}
$self->_setopts();
if ($self->{'ttl'}) {
setsockopt($self->{fh}, IPPROTO_IP, IP_TTL, pack("I*", $self->{'ttl'}))
Expand Down

0 comments on commit 00c4de5

Please sign in to comment.