Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Plans to use DGRAM sockets for ICMP ? #21

Open
snmgian opened this issue Sep 29, 2018 · 5 comments
Open

Plans to use DGRAM sockets for ICMP ? #21

snmgian opened this issue Sep 29, 2018 · 5 comments

Comments

@snmgian
Copy link

snmgian commented Sep 29, 2018

Hi,

I'm running net-ping gem on macOS High Sierra, and at least Net::Ping::TCP and Net::Ping::External are working ok (the ones I tested).

I tried Net::Ping::ICMP. I see it requires cap2 gem, so it fails with:

Caused by:
LoadError: cannot load such file -- cap2

cap2 is used to check whether there's net_raw enabled or not, because Net::Ping::ICMP uses raw socket.

Why does it use raw sockets? Is there any plan to use DGRAM sockets? Apple's ping utility uses DGRAM when the user is not root.

@chernesk
Copy link
Collaborator

I'll check into that. Sorry about the late response. I'll plan to have a response on this within the next week.

@chernesk
Copy link
Collaborator

I'm not sure, but I never did get to look at this. Life took over and I got too busy. That sounds like a good idea. I'll try to take a look in the next week, but gladly accept pull requests.

@djberg96
Copy link

I did find this:

https://apple.stackexchange.com/questions/312857/how-does-macos-allow-standard-users-to-ping

Based on this, it may just be a matter of:

if Process.euid == 0
  socket_type = Socket::SOCK_RAW
else
  socket_type = Socket::SOCK_DGRAM
end

# and later...

socket = Socket.new(Socket::PF_INET, socket_type, Socket::IPPROTO_ICMP)

Which may obviate the need for cap2 (?)

@djberg96
Copy link

Hm, I still get a permissions issue on Linux, I'll have to test this at home on the mac.

@djberg96
Copy link

Yep, looks like that only works on Macs.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants