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?
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
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.