当前位置: 技术问答>linux和unix
linux下网络编程 pingflood 数据包设为2000为什么就不发送了呢
来源: 互联网 发布时间:2016-03-05
本文导语: 发送代码: buffer[65535], 如果package设为1742以下,可以发送数据包.大于1742 无数据包发送.好奇怪. 这是为什么呢? while(1) { sendto(sockfd,buffer,sizeof(struct ip)+sizeof(struct icmphdr)+package,0,(struct sockaddr*)&destA...
发送代码:
buffer[65535],
如果package设为1742以下,可以发送数据包.大于1742 无数据包发送.好奇怪.
这是为什么呢?
while(1)
{
sendto(sockfd,buffer,sizeof(struct ip)+sizeof(struct icmphdr)+package,0,(struct sockaddr*)&destAddr,sizeof(struct sockaddr_in));
}
buffer[65535],
如果package设为1742以下,可以发送数据包.大于1742 无数据包发送.好奇怪.
这是为什么呢?
while(1)
{
sendto(sockfd,buffer,sizeof(struct ip)+sizeof(struct icmphdr)+package,0,(struct sockaddr*)&destAddr,sizeof(struct sockaddr_in));
}
|
看来是有限制了, 似乎是以太网的MTU 1500的限制. ICMP时数据最大为1472. 是不是这个限制啊!
可楼主写的是1742是不是笔误呢?
C:>ping -l 1473 -f www.freebsd.org
Pinging www.freebsd.org [69.147.83.33] with 1473 bytes of data:
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.
Ping statistics for 69.147.83.33:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
C:>ping -l 1472 -f www.freebsd.org
Pinging www.freebsd.org [69.147.83.33] with 1472 bytes of data:
Reply from 69.147.83.33: bytes=1472 time=386ms TTL=45
Reply from 69.147.83.33: bytes=1472 time=385ms TTL=45
Reply from 69.147.83.33: bytes=1472 time=386ms TTL=45
Reply from 69.147.83.33: bytes=1472 time=387ms TTL=45
Ping statistics for 69.147.83.33:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 385ms, Maximum = 387ms, Average = 386ms
可楼主写的是1742是不是笔误呢?
C:>ping -l 1473 -f www.freebsd.org
Pinging www.freebsd.org [69.147.83.33] with 1473 bytes of data:
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.
Packet needs to be fragmented but DF set.
Ping statistics for 69.147.83.33:
Packets: Sent = 4, Received = 0, Lost = 4 (100% loss),
C:>ping -l 1472 -f www.freebsd.org
Pinging www.freebsd.org [69.147.83.33] with 1472 bytes of data:
Reply from 69.147.83.33: bytes=1472 time=386ms TTL=45
Reply from 69.147.83.33: bytes=1472 time=385ms TTL=45
Reply from 69.147.83.33: bytes=1472 time=386ms TTL=45
Reply from 69.147.83.33: bytes=1472 time=387ms TTL=45
Ping statistics for 69.147.83.33:
Packets: Sent = 4, Received = 4, Lost = 0 (0% loss),
Approximate round trip times in milli-seconds:
Minimum = 385ms, Maximum = 387ms, Average = 386ms