I have understood that UDP sockets are fully identified by destination IP and destination port. The IPs are in the IP datagram´s header yes, but when the datagram arrive at its destination, only the payload is sent to the upper-layer protocol. If two hosts send a UDP segment to a host with the same IP and port, how does the socket know which IP to send the response to, since the payload does not contain the source IP and the socket isn´t identified with source IP?


TCP packets need to be wrapped in IP the same way that UDP datagrams are. Both have port numbers but not addresses for delivery.

For UDP/IP or TCP/IP, you need a 5-tuple to identify a connection:

  1. Protocol. (TCP, UDP)
  2. Source IP address.
  3. Source port.
  4. Target IP address.
  5. Target port.

A poor analogy: think about sending several physical packages. UDP alone would be just writing someone's apartment number without any street address, which of course does not work. Adding IP would mean writing destination and return addresses and adding postage, so it can be sent. (TCP would mean a fancier postal rate that allows package tracking to ensure delivery, and numbers the packages so their order is known.)

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.