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
- Get the number of packets right now.
- Wait n seconds.
- 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
精彩评论