文章目录
链路层负责相邻设备之间的数据帧传输,典型协议有:ETHH(以太网协议),ARP协议,MTU;
网络层是通过IP地址定位起点与终点;链路层是负责起点到终点之间的相邻设备间传输。相邻设备之间的识别是通过MAC地址完成的。
MAC地址:网卡的物理硬件地址–通常出厂时设定的,通常可以修改。
Uint8_t mac[6] —>为无符号的六个字节的数据。
MAC address & #xff1a; physical hardware address of the net card - usually set & #xff0c when out of the factory; usually modified.
Uint8_t Mac[6] — > is unsigned data of six bytes.
6字节对端源端MAC地址和6字节对端MAC地址: 长度是48位,是在网卡出厂时固化的
MAC地址:网卡的物理硬件地址,用于表示硬件设备。
2字节上层协议类型:帧协议类型字段有三种值,分别对应IP、ARP、RARP
4字节帧尾:帧末尾是CRC校验码
6 byte-to-end MAC address & 6 byte address & #xff1a; 48 by-line
MAC address & #xff1a; physical hardware address & #xff0c for webcards; for hardware equipment.
2 by-line upper-level protocol type xff1a; three values for frame agreement type, IP, ARP, RARP
4 by-line xff1a; at the end of the frame CRC calibration code
如何知道指定相邻设备的MAC地址?
ARP协议:是一个介于网络层与链路层之间的协议,通过IP地址获取相邻设备的MAC地址。–>过程:组织ARP请求(包含源端MAC,源端IP,指定相邻设备IP…等信息),广播ARP请求,相邻设备都能收到ARP请求,检测对端IP地址是否和自己匹配,匹配则组织ARP响应返回,否则直接丢弃。
ARP广播只会广播一层,局域网内。
通ARP协议获取到了IP地址和MAC地址映射关系后,缓存起来,然后可用ETH协议传输。
knows how to designate a neighbouring device & #xff1f; ARP & #xff1a; an agreement between network and chain layers & #xff0c; access to a neighbouring device & gt; process #xff1a; organization ARP request & #xff08; including source MAC, source IP #xff0c; designation of a neighbouring device & etc. xff09; xff0c; broadcasting ARP request xff0c; adjacent equipment can receive ARP request #xff0c; detection of matching of an end IP address xff0c; matching organization ARP response xff0c; otherwise ARP broadcast will only broadcast a first floor ~ xff0c; existing network
access to an ARP address & Mfffx;
注意到源MAC地址、目的MAC地址在以太网首部和ARP请求中各出现一次,对于链路层为以太网的情况是多余的,但如果链路层是其它类型的网络则有可能是必要的。
硬件类型指链路层网络类型,1为以太网;
协议类型指要转换的地址类型,0x0800为IP地址;
硬件地址长度对于以太网地址为6字节;
协议地址长度对于和IP地址为4字节;
op字段为1表示ARP请求,op字段为2表示ARP应答。
It was noted that the source MAC address, the destination MAC address, appeared each time in the first part of Tainet and in the ARP request, was redundant in the case of the chain layer, but it might be necessary if the chain layer was another type of network.
hardware type indicated the network type of the chain layer, 1 the ether network;
protocol type indicated the address type to be converted, 0x0800 the IP address;
hardware address length was 6 bytes for the web address;
protocol address length was 4 bytes for the IP address; and
op field indicated an ARP request for 1 and op field 2 indicated an ARP response.
ARP欺骗攻击(局域网内):伪造IP进行ARP响应 解决方法:防火墙MAC白名单。
ARP fraudulently attacked xff08; LAN xff09; : counterfeiting IP for ARP response solution xff1a; firewall MAC white list.
MTU:最大传输单元~组网方式不同,默认值也不同;以太网默认MTU=1500字节.
br/> MTUxff1a; Max unit ~ network mode xff0c; default values xff1b; default default MTU#61; 1500 by Bytes.
MTU对于编程的影响:
- 对于TCP:
Tcp:tcp三次握手时协商的MSS(最大数据段大小),就是根据MTU计算得到的。MSS=MTU-40.tcp在每次发送数据时取出不大于MSS的数据发送。
TCP在网络层不会产生数据分片,因为在传输层自动进行分段。 - 对于UDP:
udp不存在MSS,只要最大数据大小小于64k-40就能发送。但是一旦大于MTU就会在网络层进行数据分片,然而一旦分片就要在对端进行重组,重组过程在一个分片出现问题,整个报文都会被丢弃。分片越多,危险越大。
因此udp编程时,程序员要尽量考虑MTU对于udp传输的影响,在应用层进行分包管理,尽量减少分片概率。
注册有任何问题请添加 微信:MVIP619 拉你进入群
打开微信扫一扫
添加客服
进入交流群
发表评论