I'm using BSD sockets to build an advanced traceroute program that doesn't need root privileges (like tracepath). Using UDP and a bound socket, I call:
recvmsg(socket, header, MSG_ERRQUEUE)
I receive info about the supposed ICMP notification that a previously sent packet has triggered. Do you know if it's possible to access the ICMP payload (which should be the previously-sent packet)?
I read from recvmsg man page:
[..] The payload of the original packet that caused the error
is passed as normal data via msg_iovec. [..]
But I can't find anything useful there, it just seems random data (I used wireshark to cross-check data).
You can use this sample code to check which ICMP Error you got and handle it (The sample contain some comments and links):