When I try to print the maximal throughput of my network interface, I receive an error:

    $ cat /sys/class/net/<interface>/speed
    cat: /sys/class/net/<interface>/speed: Invalid argument

response. According to my investigation, this attribute is only valid for interfaces that implement ethtool `get_link_ksettings` method ([source][1]). 

My goal is to calculate network utilization for each interface by fetching the sent and received number of bytes each second (parsing the `/proc/net/dev` pseudo-file) and then using throughput to calculate percentage of utilization. I am doing this in C, so max throughput is obtained via `ioctl()` function that is unable to succeed for interfaces with unknown speed.

Is there a way how I can obtain the speed attribute in some other way? The simplest solution a was able to come up with is to say that the default speed of a interface is standard 10Mbps and if the utilization is over 100%, I can step the max speed up to the next standard speed of 1000Mbps and so on for 1Gbps, 2.5Gbps and 10Gbps. This could somehow work, but it may get broken with bundled interfaces utilizing non-standard speeds, e.g., two 1Gbps card bundled into one 2Gbps. Bundled interfaces are not a big concern for me, but having general solution would be awesome.


  [1]: https://www.kernel.org/doc/Documentation/ABI/testing/sysfs-class-net