It is not the first time ICMP errors pop up on UDP sockets, previous time that was with send() returning ECONNREFUSED. I tried to search for some more generic way to detect ICMP related errors without hunting specific error codes which vary across socket operations. I only found IP_RECVERR socket option which allows to get detailed and full error stack with recvmsg(), with the returned info allowing to explicitly attribute the error to ICMP. But unfortunately it is Linux specific and probably doing this Linux specific doesn't worth it in this case.