Getting raw sockets requires root privilege, and tcp/udp doesn’t have it,
so I need to know how to get a udp socket and fetch icmp data.
The programming language is C and the OS is BSD-like.
(In other words I want to write a ping without root privilege)
UDP is an OSI layer four protocoll, so is ICMP. Thereby, you can’t implement ICMP on an UDP socket since its layer four protocoll is already fixed to UDP. You can consider writing an implementation that requires the privilege to open a raw socket. Then you either give the application or your account the right capability or flip the executables SUID bit to make it run as root.