IP(Network Layer) the downstream data is transmitted to the link layer. For our commonly used devices, the most important device at this level is the network card. The complete title is the ethernet card, because the NIC has multiple formats, and we often see the Ethernet NIC.
The Ethernet header is as follows:
The data structure is as follows:
Struct ethhdr {
Unsigned char h_dest [eth_alen];/*TargetMacAddress*/
Unsigned char h_source [eth_alen];/*SourceMacAddress*/
Unsigned short h_proto ;/*Data Protocol types in frames*/
};
MembersH_protoAvailable data
# Define eth_p_loop 0x0060/* Ethernet loopback packet */
# Define eth_p_echo 0x0200/* Ethernet ECHO packet */
# Define eth_p_pup 0x0400/* Xerox pup packet */
# Define eth_p_ip 0x0800/* Internet Protocol packet */
# Define eth_p_arp 0x0806/* Address Resolution Packet */
# Define eth_p_rarp 0x8035/* reverse ADDR res packet */
# Define eth_p_x25 0x0805/* CCITT X.25 */
# Define eth_p_atalk 0x809b/* appletalk DDP */
# Define eth_p_ipx 0x8137/* IPX over Dix */
# Define eth_p_802_3 0x0001/* dummy type for 802.3 frames */
# Define eth_p_ax25 0x0002/* dummy protocol id for ax.25 */
# Define eth_p_all 0x0003/* every packet (Be careful !!!) */
# Define eth_p_802_2 0x0004/* 802.2 frames */
# Define eth_p_snap 0x0005/* internal only */
The header type here involves802.3The difference between frames and Ethernet frames is the difference between the length and type fields.
When the network adapter sends dataIPAddressARPDestination after conversionMacThe destination address, which is sent as a unique destination address. However, the destination address is not necessarily the final address we specify, but may be the next route in the entire network.MacAddress. Only the entire network is finished and the destination address is reached.MacThe address is what we specify.IPCorrespondingMacAddress. During the transmission of the entire network, the router will frequently useArp/RARPProtocol to find the next stopMacAddress until the data is transmitted to the destination address, or the data is discarded.