My doubt is why an icmp destination port unreachable error message generated for udp. Why we can't simply discard the udp packet if the destination port is not reachable by saying udp is connection-less


From ICMP RFC 792:

  If, in the destination host, the IP module cannot deliver the
  datagram  because the indicated protocol module or process port is
  not active, the destination host may send a destination
  unreachable message to the source host.

Because the keyword is MAY, it is not required for the receiving host to send a destination port unreachable if there is no process listening at that tcp or udp port, but it is allowed per the standard.

As a UDP application developer, it is helpful to know that the destination port is unreachable, so the ICMP error message is helpful and appreciated.

Sometimes, the answer is, “we do it because the standard says to do it”.

  • Take into account that UDP applications needs to have a mechanism to know if the destination port is accepting data or not. If this ICMP packet is not sent then your application will need to have a timeout (180 seconds for example) mechanism in order to inform the application that there is no response. – camp0 Oct 11 '19 at 9:58
  • 3
    This assumes the application gets a response. Syslog, for example, is a blind transmit. (in fact, it used to be a common practice to disconnect the TX pair from your "secure" syslog collector) – Ricky Oct 11 '19 at 15:57
  • @camp0, there is nothing that dictates a UDP application needs to have such a mechanism. There are any number of one way only applications that have existed over the years, as well as data being dumped to raw sockets for various purposes. – YLearn Oct 14 '19 at 14:02
  • @RickyBeam Ha, Fascinating! – Eddie Oct 15 '19 at 0:57

There are few things more infuriating then when you try to do something and it doesn't work with no indication is to why it didn't work, so you have no clue how to fix it or who to yell at to get it fixed.

That is why we build error messages into protocols, even connectionless ones.


Why ICMP Destination Port Unreachable error messeage is generated for unreliable UDP packets?

My question would be why not? Per the RFCs, this is action is allowed. I would even go further and suggest that this should be recommended. You can silently discard TCP segments, but should not with UDP.

My doubt is why an icmp destination port unreachable error message generated for udp. Why we can't simply discard the udp packet if the destination port is not reachable by saying udp is connection-less

It is the fact that UDP is connectionless that it should be sending this response. TCP cold simply discard segments in this situation because it is connection oriented. Let me give you an example of why sending an ICMP Destination Port Unreachable response is a good idea in this situation.

Say computer (C) has 3 TB of data to send, and believes it should send it to server (S). If this were a connection oriented TCP transfer, if the port is not available, the TCP handshake will simply fail.

Now if C was going to use UDP to send this data to S, it wouldn't need the handshake as it is connectionless. There will also be no missing acknowledgements to slow down/halt the flow of data (and eventually time out the connection). C simply starts sending data and will keep sending data. Barring server S doing something (like sending an ICMP Destination Port Unreachable) or the application on C stopping this transfer for some reason, it will continue to send 3 TB of data to S. S must still receive (and then discard) all this data.

The ICMP Destination Port Unreachable prevents the majority of this data from ever being sent. It doesn't need to be processed/sent by C, it doesn't need to transit the network(s) between C and S, and it doesn't need to be received and processed in any form by S.


The ICMP message is a network-layer function and it is sent for the dropped IP packet encapsulating the UDP datagram - it simply doesn't care about the payload.

The only exception is that no ICMP message is generated for a dropped ICMP message (to prevent ping-pong message loops):

To avoid the infinite regress of messages about messages etc., no ICMP messages are sent about ICMP messages.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.