I've a router and two local machines A and B with respective ip 192.168.1.2 and 192.168.1.3 are connected with this router. When A makes a http request to some server and corresponding response is received by router, then how is this response propagated to A (not to B)? Is each request associated with a specific port so that router knows it's for A not for B? In that case ports couldn't be shared on A and B?
|
feedback
|
migrated from stackoverflow.com Jan 16 '10 at 8:40
This question came from our site for professional and enthusiast programmers.
|
In this case the Address Resolution protocol (ARP) and the Network Address Translation (NAT) are utilized. | |||
|
feedback
|
Yes, ports are part of the game. But your question is a duplicate. Check out this question: to see how NAT prevents address collisions. Example:
200.50.50.28 is router's global (internet) IP. Every port number is unique in the NAT table. And of course the router does all the dirty job of modifying the source and destination addresses transparently. | |||
|
feedback
|
|
The HTTP protocol operates on top of the TCP protocol, which operates on top of the IP protocol. TCP is a connection-oriented protocol, which means that a connection must be created before the client and server can communicate. A TCP connection consists of [source IP, source port, destination IP, destination port]. This means that when a message is sent to the server, the server already has the IP address and port to which it should reply. Any reply is sent in IP datagrams directed to that address and port. When any datagram is received by a router, it is routed to the next hop along the path back to where the datagram belongs. In your simple case, the next hop is right onto the LAN. When it gets to the LAN, the ARP protocol is used to find the MAC address to send to, assuming that address is not already in the router's address cache. In either case, given the MAC address, the router sends the datagram directly to that address on the LAN. | |||
|
feedback
|
|
This is not done by ports ofcourse. On a LAN, this is done by MAC addressed. Basically, each machine has a unique MAC address. Thus, when a user wants A to get an HTTP response from some server (IP given), these processes would be followed:
| |||
|
feedback
|