Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Linux C++: Accessing network statistics

I am developing a network statistic program in C++ for Linux.

I would like to access some statistical information about the current network connection.

E.g.:

  • packet loss,
  • bytes transferred (upload and download),
  • current network load (upload and download),

Any idea how to access this kind of information?


so, i have been trying to accomplish my objective using de /proc, we can find alot of information, but there is some missing information i need. I am thinking in developing a simple C++ promiscuous application, using LibPcap, that captures the network traffic i need and starts taking the metrics i want.

The Con is that i think this is going to be CPU intensive, at least more then needed ... Any thoughts about this ?

like image 537
maluk Avatar asked Sep 03 '12 14:09

maluk


1 Answers

All this information are spread into /proc/net files (updated by kernel). The most important file is /proc/net/netstat. Into to /proc/net/dev there are device statistics. You could open and parse.

like image 175
André A. G. Scotá Avatar answered Sep 27 '22 22:09

André A. G. Scotá