views:

543

answers:

2

I am in a situation where I am extremely bandwidth limited and must devote most of the bandwidth to transferring one type of measurement data. Sometimes I will be sending out lots of this measurement data and other times I will just be waiting for events to occur (all of this is over a TCP socket).

I would like to be able to stream out the full data capture file (different than the measurements) in the background at a speed that is inversely proportional to the amount of measurements that I am sending back.

I am looking for a way to monitor how many bytes are being sent out the network interface in much the same was as the system monitor on Ubuntu. The source code for the system monitor relies on gnome libraries and since my program is on an embedded device, I would like to reduce the number of external libraries that I use. Does anybody know of a way to do this in C/C++ without many additional libraries on a standard Linux distribution?

+1  A: 

One of the simplest ways is to parse the file: /proc/net/dev

Mine contains:

Inter-|   Receive                                                |  Transmit
 face |bytes    packets errs drop fifo frame compressed multicast|bytes    packets errs drop fifo colls carrier compressed
    lo:   44865    1431    0    0    0     0          0         0    44865    1431    0    0    0     0       0          0
  eth0:150117850  313734    0    0    0     0          0         0 34347178  271210    0    0    0     0       0          0
  pan0:       0       0    0    0    0     0          0         0        0       0    0    0    0     0       0          0

You could then write a parser that uses nothing other than the C/C++ libraries.

Matt H
+1  A: 

Use NetLink sockets of RTNetLink interface socket, they will get you the required in struct net_device_stats format

harishvk27