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?
closed as off-topic by Ron Maupin♦ Aug 20 '18 at 14:42
This question appears to be off-topic. The users who voted to close gave this specific reason:
- "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." – Ron Maupin
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.
A UDP socket is defined by the (source address, source port, destination address, destination port) tuple. That way, the destination host knows where a request has originated from and where to send the reponse (where applicable).