linux ping的三个数字(56,84,64)

参考:
ping 深入剖析:https://www.cnblogs.com/aozhejin/p/15917312.html 

windows默认是32字节,linux是56字节说的都是数据包大小
注意:
1. 数据包和数据报的区别
2.56.64.84三个数字
3.8字节icmp数据报头
4.20字节ip数据报头
5.报头+内容不能大于65535,所以最大值为65507(linux:65507, windows:65500)

来测试网络的状况,这时,就要指定ping包的大小了。数据包总长度84个字节

 1. 指定数据包大小为1500Byte:ping -s 1500 ip

 2. 指定次数为4次,数据包大小为32767Byte:ping -c 4 -s 32767 ip

 3. 指定ping包大小为1500Byte:ping -l 1500 ip

 4. 指定次数为6次,ping包大小为1500:ping -n 6 -l 1500 ip

  -s 指定每次ping发送的数据字节数
  -s 指定一个数据包发送给指定ip ,单位字节(byte), 最大发送65536(32位int最大值).
由于1024B = 1KB , 65536B = 65Byte. 所以最大只能附加65byte的包,默认64b(1byte=8bit)
提示超出包大小
[root@h6 ~]# ping -s 665000 10.129.51.11  
ping: packet size too large: 665000
ping.c中处理的代码为
 if (datalen > 0xFFFF - 8 - optlen - 20) {
   //十六进制0xFFFF转成十进制为65535
   //实际数据大小为 65535-8-20= 65507字节

  if (uid || datalen > sizeof(outpack)-8) {
  fprintf(stderr, "Error: packet size %d is too large. Maximum is %d\n", datalen, 0xFFFF-8-20-optlen);
  exit(2);
 }
 /* Allow small oversize to root yet. It will cause EMSGSIZE. */
 fprintf(stderr, "WARNING: packet size %d is too large. Maximum is %d\n", datalen, 0xFFFF-8-20-optlen);
 //imcp报头+ip报头+内容数据不能大于65535,实际的数据字节为最大值为65507(实际数据包大小为 65535-8-20= 65507字节)
 //linux:65507, windows:65500

 

windows

  C:\Users\qic>ping www.baidu.com

  正在 Ping www.baidu.com [110.242.68.3] 具有 32 字节的数据: 
  来自 110.242.68.3 的回复: 字节=32 时间=13ms TTL=52
  来自 110.242.68.3 的回复: 字节=32 时间=38ms TTL=52 
  来自 110.242.68.3 的回复: 字节=32 时间=10ms TTL=52

  110.242.68.3 的 Ping 统计信息:
  数据包: 已发送 = 3,已接收 = 3,丢失 = 0 (0% 丢失),
  往返行程的估计时间(以毫秒为单位):
  最短 = 10ms,最长 = 38ms,平均 = 20ms

  //windows,数据包大小是32字节/次

 linux 

[root@ht6 ~]#  ping -c 4 -w 10  10.129.51.11
PING 10.129.55.111 (10.129.51.11) 56(84) bytes of data.
64 bytes from 10.129.51.11: icmp_seq=1 ttl=64 time=0.196 ms
64 bytes from 10.129.51.11: icmp_seq=2 ttl=64 time=0.126 ms
64 bytes from 10.129.51.11: icmp_seq=3 ttl=64 time=0.166 ms
64 bytes from 10.129.51.11: icmp_seq=4 ttl=64 time=0.140 ms
--- 10.129.51.11 ping statistics ---
4 packets transmitted, 4 received, 0% packet loss, time 3000ms
rtt min/avg/max/mdev = 0.126/0.157/0.196/0.026 ms
//icmp_seq如果丢失则显示错误
//这里有三个数据 56,84,64这三个数据分别是
1.ping包的linux默认数据包大小为64字节(icmp头部8字节+56字节的默认数据包)
2.84字节是数据包总大小(实际的)--构成为(20字节ip数据报+8字节icmp数据报)+56数据包
3.56字节即数据大小
posted @ 2022-03-24 15:30  jinzi  阅读(1729)  评论(0编辑  收藏  举报