How does the server know how to respond to a UDP packet? [closed]

NE is a site for to ask and provide answers about professionally managed networks in a business environment. Your question falls outside the areas our community decided are on topic. Please visit the help center for more details. If you disagree with this closure, please ask on Network Engineering Meta.

Closed 6 years ago .

As far as I know, UDP ports and OS sockets are mapped only by the (local port, local address) pair. In other words, the receiver side's OS does not keep a state of (remote port, remote address) pair (although this information has been attached to the UDP header of the packet. My question is, when you respond to this packet (let's say a DNS response), how does the server know who to respond? Does some entity keep the (remote port, remote address) pair that has been obtained from the packet and somehow use it?

asked Aug 20, 2018 at 1:55 603 1 1 gold badge 7 7 silver badges 13 13 bronze badges

Unfortunately, questions about applications, programming, and host OSes are off-topic here. You could try to ask about programming on Stack Overflow.

Commented Aug 20, 2018 at 14:42

2 Answers 2

First of all: Sockets have nothing to do with network protocols but with network programming:

Indeed a if a DNS server software called the recv() function the information about the IP address of the sending computer would be lost.

The software would not be able to send a response.

Therefore the software calls the recvfrom() function instead of recv() :

This function will return additional information about the UDP packet received; in the case of IPv4: The "source address" and the "source port" (in the case of IPv6 even more).

Using this information the software can send a response.