I am looking for a way to detect "port unreachable" errors for outgoing UDP packets in Erlang, so I can eagerly report transport layer errors to the application. I.e, I want to capture ICMP type 3 packets to report to the higher layers that packet have not reached the destination.
Currently I know about two approaches:
- Use undocumented
gen_udp:connect/3
. However, it seems like this requires opening a new socket for every new destination pair address:port. The advantage is that this does not require any privileges. - Use gen_icmp which requires either setuid helper or capabilities to open raw sockets.
Are there any other variants I am missing?