开发者

Network Status in C

Right now I am able to retrieve开发者_StackOverflow the network status using the following code..

 popen("netstat -i | grep '^e[a-z][a-z]*0[ \t]' | head -n1","r")


sscanf(line,"%32s %d %*s %*s %d %d %d %d",
               name, &mtu,
               &in_packets, &in_errors,
               &out_packets, &out_errors);

I want to calculate packets per sec.. How can I do that? Thanks


How to calculate packets/second

  1. Get the number of packets right now.
  2. Wait n seconds.
  3. Get the new number of packets.

Now subtract the first number from the second number and divide by n and you have your packets/second over a given interval.


you can use tcpstat e.g.

tcpstat -i eth0 -o '%b\n'

Output

16516.80   #bps
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜