I successfully ported the Asio Pinger example https://think-async.com/Asio/asio-1.20.0/src/examples/cpp03/icmp/ping.cpp to work without Boost at all.
The example works perfectly, but running the app as root on macOS.
As suggested here and here, I understand that asio::ip::icmp
is built on top of raw sockets and macOS doesn't allow raw sockets to non-root users. This force me to run the app as sudo, that's not ideal. Otherwise, it fails with "Operation not permitted".
In the ping.c
example, they set the socket type as SOCK_DGRAM
for non-root users. I tried to manually change the flag directly in the ip\icmp.hpp
header but of course it does not work: the socket initializes correctly without sudo, but the app crashes sending the packet with socket_.send_to(request_buffer.data(), destination_);
.
Anyone knows how to run the Pinger example without involving root/sudo?
Thanks