Jason Yang
Jason Yang

Reputation: 584

Why is UDP socket identified by destination IP address and destination port?

According to "Computer networking: a top-down approach", Kurose et al., a UDP socket is fully identified by destination IP and destination port.

Why do we need destination IP here? I thought UDP only need the destination port for the demultiplexing.

Upvotes: 3

Views: 7673

Answers (2)

Erick Robertson
Erick Robertson

Reputation: 33068

I think that you are confusing UDP with Mulitcast.

Multicast is a broadcast protocol that doesn't need a destination IP address. It only needs a port number because it is delivered to all IP's on the given port.

UDP, by contrast, is only delivered to one IP. This is why it needs that destination IP address.

Upvotes: 1

Barmar
Barmar

Reputation: 780843

The machine may have multiple IPs, and different sockets may be bound to the same port on different IPs. It needs to use the destination IP to know which of these sockets the incoming datagram should be sent to.

In fact, it's quite common to use a different socket for each IP. When sending the reply, we want to ensure that the source IP matches the request's destination IP, so that the client can tell that the response came from the same server it sent to. By using different sockets for each IP, and sending the reply out the same socket that the request came in on, this consistency is maintained. Some socket implementations have an extension to allow setting the source IP at the time the reply is being sent, so they can use a single socket for all IPs, but this is not part of the standard sockets API.

Upvotes: 3

Related Questions