@@ -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.
23662381X<ping_icmp>
23672382
23682383The 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])
23712387X<ping_icmpv6>
23722388
23732389The 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])
23762393X<ping_stream>
0 commit comments