my office has few machine and one router and internet connection. when i open my browser and write url like yahoo.com then response come to me. so i dont have knowledge how router in my office deliver the response to right machine always. how router detect that which machine should get the response. when my request goes through the router then what kind of extra information goes out with through router. i doubt my machine mac id also goes out with the request and that is why when response come back then router read the mac id and deliver the response to right machine in Lan of my office. but i am not sure actually what happen behind the scene. i search Google but could found the answer way i want. so please some one tell me in detail how router in a office deliver the response against any request to right pc in a lan. thanks in advance.
migrated from stackoverflow.com Apr 10 '11 at 18:26
This question came from our site for professional and enthusiast programmers.
closed as off topic by EEAA, Ward, jscott, sysadmin1138♦ Apr 11 '11 at 1:46
Questions on Server Fault are expected to relate to professional server, networking, or related infrastructure administration within the scope defined by the community. Consider editing the question or leaving comments for improvement if you believe the question can be reworded to fit within the scope. Read more about reopening questions here.If this question can be reworded to fit the rules in the help center, please edit the question.
The answer is that each machine hooked up to the network has a unique IP address. Every time you make an HTTP request, there's a "Frame Format" which refers to the way outgoing packets are organized. One piece of information embedded in that frame is the Header, consisting of a destination address and a source address.
Your office router probably provides NAT functionality (Network Address Translation). There are different types of NATs - a good reference would be the wikipedia page for NATs. The basic idea is that the router maintains a mapping from your private ip_address:port to a public ip_address:port. An external webserver sees your public ip_address:port information (say, a.b.c.d:9000). A response from that web server is directed back to this public address. Now because you initiated the connection, the router has a mapping from the public address (a.b.c.d:9000) to your internal address (x.y.z.1:4000). A similar mapping would be maintained for other active connections (from your machine and other machines).
Now, if your router does not provide NAT, then each machine in your office probably has a public ip address, and the router just routes packets based on IP address information.
Now irrespective of the NAT functionality provided by your office router, ARP and RARP (protocols) are used to map from IP address to MAC address. The basic idea of how ARP works is as follows: If a machine needs to route a packet to a given IP address in the LAN and it does not know what MAC address corresponds to this destination IP address, then a broadcast is sent out requesting the machine that owns the IP to respond with its MAC address. Other nodes in the LAN ignore the request, but the owner responds with its MAC address. The requesting machine can then store this mapping it its cache to avoid subsequent APR requests/responses for this machine. The ARP/RARP mechanism will also be implemented by your office router. The MAC address is used in the ethernet header.