good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
udp send not reporting host unreachable errorsby saurabh.hirani (Beadle) |
on May 05, 2009 at 09:57 UTC ( [id://761889]=perlquestion: print w/replies, xml ) | Need Help?? |
saurabh.hirani has asked for the wisdom of the Perl Monks concerning the following question: Hi guys, Yesterday I had put up a post about a query I had for UDP sockets - send call on udp socket. To summarize it, when udp socket makes a send system call it returns true, irrespective of the status of the receiving host/port. And as per the UDP protocol, any reported asynchronous errors are are passed to the user. So if I do a send, which returns true and then I do a recv or send, the first send's errors are reported during the later operations. The code that I used was:With no server running on 127.0.0.1:3333 the output I got was,
which happens because of asynchronous errors received on network. I concluded, that if my send call fails, the error will be obtained at any point in time, but I will get the error. I was wrong. Because if I change the PeerAddr to a unreachable host, the output I get is
The output I was expecting was
Because I should have got the error of host unreachable like I got for connection refused. I looked up to the udp and socket man pages on my system and found the following snippet in the udp man page: All fatal errors will be passed to the user as an error return even when the socket is not connected. This includes asynchronous errors received from the network. You may get an error for an earlier packet that was sent on the same socket. This behaviour differs from many other BSD socket implementations which don’t pass any errors unless the socket is connected. Linux behaviour mandated by RFC 1122. Snippet from socket man page SOCKET OPTIONS section for option SO_BSDCOMPAT: If enabled ICMP errors received for a UDP socket will not be passed to the user program. In later kernel versions, support for this option has been phased out: Linux 2.4 silently ignores it, and Linux 2.6 generates a kernel warning (printk()) if a program uses this option. Which means that I will get UDP send errors only if my destination host is up. I tried using the getsockopt() method from Socket module to check if SO_BSDCOMPAT option is set. But the Socket.pm module file does not have this option in its list of queriable options. Perl is installed directly from the rpm and has not been compiled. My system parameters are
My questions:
thanks and regards, Saurabh
Back to
Seekers of Perl Wisdom
|
|