where does iwconfig get data on bitrate in linux

1.7k views Asked by At

I am writing a C program to calculate current bandwidth usage on a data link. I also need the bandwidth of the link.

For wireless links, iwconfig prints the wireless link characteristics which are stored in /proc/net/wireless. However how about data rate of the wireless link? Is it also stored somewhere in the (another)file?

Also for ethernet links, Are there similar files where all the link details are stored?

2

There are 2 answers

0
ldx On BEST ANSWER

You should use libnl to query interface information. Don't rely on files under /proc or scrape the output of iw or iwconfig, since their output format might change any time.

If you are curious about the details, check out the source code of iw. It's easy to understand (I used it myself to understand how to query nl80211 for interface info).

0
lorem On

So, I solved my problem by reading the tx_bytes and rx_bytes in the statistics directory of each interface. My function is called every 10 seconds. so, I save the current value of tx/rx_bytes in memory and when my function is called the next time, i use the current value and previous value to calculate the data rate.