I'm writing a simple UDP chat server in Python 2.7 on Linux 2.6.38.
How can ICMP error messages be read that a host(client) receives when it sends UDP segments to say, an unreachable server?
I tried
sockFd.setsockopt( socket.IPPROTO_IP, socket.IP_RECVERR, 1 )
But socket.IP_RECVERR isn't defined in socket module.
I tried using a timeout on sockFd.recvfrom and doing sendto a second time but that didn't help. Is there an API to read the ICMP errors received by the host?
The question is a bit old but I'll answer it since I've faced the same problem.
The constant IP_RECVERR is defined in the "IN" module, so the next statement should do the job:
import socket
import IN
sockFd.setsockopt( socket.IPPROTO_IP, IN.IP_RECVERR, 1 )
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With