【问题标题】:what is the use of buffer size in socket?套接字中缓冲区大小的用途是什么?
【发布时间】:2016-04-30 08:27:49
【问题描述】:

我正在了解 ping 命令的实现。对此我有一个疑问。怀疑是

我知道套接字缓冲区用于在套接字中一次传输多少字节。 但是 ping 命令如何管理套接字缓冲区大小。

$ ping -S 300 -s 400 google.com
PING google.com (216.58.197.46) 400(428) bytes of data.
72 bytes from maa03s20-in-f14.1e100.net (216.58.197.46): icmp_req=1 ttl=56 (truncated)
72 bytes from maa03s20-in-f14.1e100.net (216.58.197.46): icmp_req=2 ttl=56 (truncated)
72 bytes from maa03s20-in-f14.1e100.net (216.58.197.46): icmp_req=3 ttl=56 (truncated)
^C
--- google.com ping statistics ---
3 packets transmitted, 3 received, 0% packet loss, time 2003ms
rtt min/avg/max/mdev = 40.231/41.500/42.408/0.924 ms

在上面的 ping 命令中,套接字缓冲区大小为 300,单个数据包大小为 400。套接字缓冲区大小仅为 300。但是 ping 在该套接字中一次传输 400 个字节。怎么可能。 同时接收到的数据包大小只有72,为什么只有72。

谁能解释一下。

【问题讨论】:

    标签: linux sockets


    【解决方案1】:

    ping 请求仅使用/需要 72 字节的数据。这在 300 缓冲区大小(限制)和 400 字节数据包大小之内。 ICMP 数据包可能包含 64 个数据字节和 8 个标头字节,从而产生一个 72 字节的数据包。

    由于 ICMP 数据包只需要 72 字节,因此不会添加不必要的数据来满足 400 字节的数据包大小。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-31
      • 2020-04-04
      • 2015-05-01
      相关资源
      最近更新 更多