in reply to udp send not reporting host unreachable errors

To summarize it, when udp socket makes a send system call it returns true, irrespective of the status of the receiving host/port.
...
1. Shouldn't send() be reporting 'Destination host unreachable'?

No, since UDP is connectionless. The packet is just sent, and the protocol doesn't provide that info. You could send an ICMP packet first to make sure the receiving side is reachable.

  • Comment on Re: udp send not reporting host unreachable errors

Replies are listed 'Best First'.
Re^2: udp send not reporting host unreachable errors
by JavaFan (Canon) on May 05, 2009 at 10:47 UTC
    You could send an ICMP packet first to make sure the receiving side is reachable.
    Well, you can, but you cannot be sure of anything regarding its answer. ICMP is a different protocol than UDP. Many routers/firewalls will block ICMP echos (or drop them on the ground) giving you false negatives about reachability. Or worse, a firewall may actually answer ICMP requests on behalf of its hosts on the inside - suggesting the host is up while it isn't. Or UDP traffic may be blocked while ICMP traffic isn't.

    Sending an ICMP packet may give you some insight, but you cannot be 100% sure.

    As for the OP: it seems to me that you want services from the network which TCP gives you, but UDP doesn't. Perhaps the OP should use TCP.

Re^2: udp send not reporting host unreachable errors
by saurabh.hirani (Beadle) on May 05, 2009 at 10:52 UTC

    I agree that UDP is connection less. But RFC 1122, which mandates the behaviour of Linux for UDP protocol states that whenever ICMP error messages are received, they should be reported to the user application.

    I do get "Connection refused" errors for sending data to a non existent UDP socket on a reachable host. Why shouldn't I get an error for a non existent port on an unreachable host?

    And as per the content of my post, if SO_BSDCOMPAT option is on, then you get errors if and only if the destination host is up but there is some problem in connecting to the socket.

    The UDP man page also states that SO_BSDCOMPAT option has been removed after Linux 2.2. I have Linux 2.6. So why is my application behaving as if SO_BSDCOMPAT option is set?

      I agree that UDP is connection less. But RFC 1122, which mandates the behaviour of Linux for UDP protocol states that whenever ICMP error messages are received, they should be reported to the user application.
      How do you propose this is done? Making the actual send() wait for a possible ICMP package is not practical, as you do not know whether there will come one, and you will not get a success message if the package was accepted. But if you don't wait forever, the program may have terminated before any message arrives.
        How do you propose this is done? Making the actual send() wait for a possible ICMP package is not practical, as you do not know whether there will come one, and you will not get a success message if the package was accepted.
        It is not practical. I am not going to use it. My pursuit is not to know whether the code snippet I wrote is practical, it is - why isn't the application behaving as I think it should? My point is: I should be getting 'Destination Unreachable' errors like I got for 'Connection Refused'.