Linux and macOS support a way for non-root applications to use ICMP ping. In both cases, a INET (and INET6??) socket can be created with the IPPROTO_ICMP protocol and the kernel ensures it can only be used for ping. Discussed here:
https://mail.openjdk.java.net/pipermail/net-dev/2020-November/014931.html
- links to
-
Review openjdk/jdk/1502