日期:2014-05-16  浏览次数:20763 次

linux下网络编程 pingflood 数据包设为2000为什么就不发送了呢
发送代码:
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