Getting stats for icmp stack

I wrote a simple program which sends high amount of icmp packets to local network. But it seems that some of the packets (nearly about %20) getting lost on the target site. Is it possible to get icmp stack info from kernel itself?

You can get statistics about protocol stacks icmp, udp, tcp, ip from the file /proc/net/snmp

Every new packet which sent or received increments related counters here. You can learn a lot of information for icmp stack like received message count, received errors, received checksum errors etc.

You may get a hint about your icmp packet loss from /proc/net/snmp

But there is another file which is probably main reason for your packet loss: /proc/sys/net/ipv4/icmp_ratelimit

Value in this file controls maximum rate at which the kernel generates icmp messages of the types specified by icmp_ratemask. The value is the number of jiffies the kernel has to wait between sending two such messages. Therefore zero means no limit. It is used with icmp_ratemask value which gives you an option to select rate limit calculation on which icmp types. So, it is good to disable rate limiting and test your program again like below:

echo 0 > /proc/sys/net/ipv4/icmp_ratelimit