I'm trying to fetch the stats of a NIC device in Rust, which is basically the equivalent of running ethtool -S eth0
.
I have been looking at the netlink interface for ethtool documentation and the existing libraries: neli and ethtool.
However, neither of them provide an out-of-box solution. This was my attempt as using the neli
library: ethtool.rs. However, I keep getting device not found
or operation not supported
error. While for the ethtool
library, I need to add the functionality in the library itself which I am currently trying to do.
Any help would be really appreciated as to what is the most straightforward way to do so without obviously running the system commands and reading the stdout.
I ended up using ioctl
to do the above instead of going through the hassle of creating the right netlink nested attributes.
Here's the code snippet for the same: ethtool.rs.
Much more straightforward, however obviously I'd be missing on some of the advantages of using netlink. But maybe that'd be a task for some other day.