This is the first article I wrote on the 9CBS blog, so I will start with my favorite TCP / IP!
How do I understand TCP / IP? From my personal understanding, it should be like this:
1: Address: software address, such as IP address; hardware address, such as Mac. The role of the address in TCP / IP is like: Xiao Wang wants to go to Xiao Li to eat, Xiao Wang wants to know Xiao Li's home address to eat rice? The optimum of TCP / IP is "physical" address, the hardware address provides the minimum communication basis; the optical hardware address is not enough, the function is limited. Therefore, there is a software address corresponding to the hardware address (not one corresponding): IP address. With hardware and software, the communication function is relatively large. At the bottom of TCP / IP, the link layer and IP layer function are mainly expanded around how to process the relationship between addresses.
2: Routing: Routing is actually more addressed. Route sublink hierarchy (hardware address), and IP level (software address). For example: When an internal network host A is to send a message to the external network C, you must first look for the IP routing of the external network C, query this routing table (IP level), know what needs to send the newspaper After the IP of the router B of the inner network, according to the hardware address of the router B, the link-level route is used, if Qing this machine A (link stage) routing table does not check B hardware address, Just send an ARP broadcast message to this LAN, the router B receives ARP broadcast, will reply to a ARP reply message with own IP, MAC address data, and the B will take B after receiving the reply message. IP, Mac is stored in the routing table of this unit. Then, according to this route, data to B, forwarded from B to the external network.
3: Memory: Nuclear grade, application level. TCP / IP is a communication service to the application layer. One: In general, an application constructs its own data in the customer process, then copy the data to the kernel memory through a memory processing function, so that the data packet is handed over to the kernel process TCP / IP processing, TCP / IP "from top to bottom" from the transport layer, the IP layer, the link layer, and processed layer-by-layer to the hardware. 2: The above is a general situation. If you don't want to take a general route, you can add an HOOK at the TCP / IP link layer, copy the data from the application layer to the kernel, but directly walk the link layer function to send packets. Sniffer uses this principle.