und3f / anyevent-ping

Asynchronous ping with AnyEvent
2 stars 4 forks source link

Unable to create icmp socket : Operation not permitted (non-root) #6

Closed defc0n closed 9 years ago

defc0n commented 9 years ago

I'm on OS X Yosemite and trying to execute the following code:

#!/usr/bin/env perl

use strict;
use warnings;

use AnyEvent;
use AnyEvent::Ping;

use Data::Dumper;

my $cv = AnyEvent->condvar;

my $pinger = AnyEvent::Ping->new;

$pinger->ping( '127.0.0.1', 1, sub {

    my ( $result ) = @_;

    warn Dumper $result;

    $cv->send } );

$cv->recv;
$pinger->end;

When I attempt to run as normal user:

$ perl ping.pl
Unable to create icmp socket : Operation not permitted at ping.pl line 13.

When I run as root:

$ sudo perl ping.pl
$VAR1 = [
          [
            'OK',
            '0.000152826309204102'
          ]
        ];

Is there some socket options being set which require root privileges in the OS X kernel but do not in other kernels or something?

defc0n commented 9 years ago

FWIW, I can of course issue a regular ping command from the command line just fine:

$ ping 127.0.0.1
PING 127.0.0.1 (127.0.0.1): 56 data bytes
64 bytes from 127.0.0.1: icmp_seq=0 ttl=64 time=0.044 ms
und3f commented 9 years ago

The reason /bin/ping works from regular users is SUID permission. It will not work if you make a copy: $ cp /bin/ping ~/ping; ~/ping google.com ping: icmp open socket: Operation not permitted

defc0n commented 9 years ago

interesting, surprised i never knew or heard of this, thanks!