3
votes

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?

2

2 Answers

2
votes

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 )
-2
votes

The ICMP errors are basically useless. If you receive an error, that doesn't assure that the other end didn't receive the packet. If you don't receive an error, that doesn't ensure that the other end did receive the packet. So there is almost no reason to ever bother doing this.

If you tell us more about why you think you need to do this, we can tell you what you should do instead.