4

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:

  1. 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.
  2. Use gen_icmp which requires either setuid helper or capabilities to open raw sockets.

Are there any other variants I am missing?

Ivan Dubrov
  • 4,778
  • 2
  • 29
  • 41
  • If you want to test UDP why do you think ICMP would help you? Afaik ICMP only provides a more basic ping of the whole machine, not a specific port. – ZeissS Sep 26 '11 at 20:10
  • 2
    @ZeissS: Because unreachable ports (and many other conditions) are reported via ICMP. – Ivan Dubrov Sep 27 '11 at 08:53
  • 2
    Basically, when you send UDP packet to the port without listening socket, you (may or may not -- depends on network configuration, remote host configuration, etc) receive ICMP type 3, code 3 packet with information about destination address and port. – Ivan Dubrov Sep 27 '11 at 09:07

1 Answers1

1

procket might be what you're looking for, but I've never used it myself. It's a binding to the low-level socket API, therefore it allows you to use all the protocols the underlying API supports. I'm just quoting its README, so please take it with a pinch of salt.

erszcz
  • 1,630
  • 10
  • 16