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?
You should use libnl to query interface information. Don't rely on files under /proc or scrape the output of
iw
oriwconfig
, 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).