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:
- Protocol. (TCP, UDP)
- Source IP address.
- Source port.
- Target IP address.
- 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.)