How to send packets from the network adapter:
ArticleSource: http://blog.21ic.org/user1/1066/archives/2007/40803.html
An IP packet can be considered as a packet.
Linux NIC DriverProgramAdd a 14-byte MAC header to the IP packet to form the Mac packet.
The Mac package contains the MAC address information of the sender and receiver. Since it is the MAC header information created by the driver, you can enter the address information at will, and the host disguise is implemented in this way.
The driver copies the Mac package to the cache in the NIC chip. Some Nic chips take over the processing. The NIC chip encapsulates Mac packets into physical frames and adds the header synchronization information and CRC verification. Then, it is thrown to the network cable to complete the sending of an IP packet. All NICs attached to the current network cable can see the physical frame.
How the NIC receives data packets:
A network cable can be regarded as a highway, and a physical frame is a car or network card. Maybe it's a gas station.
From this perspective, there is no absolute relationship between cars and gas stations. All cars can enter the gas station.
Normal situation:
The physical frame on the network is first obtained by the NIC chip. The NIC chip checks the CRC of the physical frame to ensure integrity. Secondly, the NIC chip removes the physical frame header to obtain the MAC package.
The NIC chip checks the target MAC address information in the Mac package, and is the same as the MAC address of the Nic? Inconsistent. Abandon.
The NIC chip copies Mac frames to the internal buffer of the NIC, triggering an interruption.
The driver copies the Mac package to the system through interruption to build the sk_buff. Tell the upper layer.
Remove the MAC header from the upper layer to obtain the required IP packet.
During the process, the NIC chip performs Mac matching filtering on physical frames. This can reduce the system load. Imagine what it would be like if the NIC Chip provided to the driver without any judgment on all Mac frames? When the data on the bus is busy, the CPU will waste most of the time to determine whether the Mac package is needed or not, and the efficiency is low.
Abnormal mode (mixed listening ):
The physical frame on the network is first obtained by the NIC chip. The NIC chip checks the CRC of the physical frame to ensure integrity. Secondly, the NIC chip removes the physical frame header to obtain the MAC package.The NIC chip does not filter Mac packets when it finds that it is configured in mixed listening mode.. The NIC chip copies Mac frames to the buffer inside the NIC, triggering an interruption. The driver copies the Mac package to the system through interruption, builds sk_buff, and tells the upper layer. Remove the MAC header from the upper layer to obtain the required IP packet. Obviously, the IP package here is not necessarily sent to you.
Driver problems:
Whether the NIC can receive other Mac packets depends on the RCR (receive control register) configuration in the NIC chip.The driver is a bridge that determines whether the NIC can work in mixed listening mode.. The mixed listening mode increases the CPU load and does not comply with the standard application!
All vehicles must pass through the gas station (some do not support fuel), and the number of tasks of the gas station staff can be imagined.
Of course, there are also exceptions. Some programs can directly access the NIC chip RCR to set the mixed listening mode without driving.
There is no absolute reason for the so-called things going through Hong Kong.