diff options
author | garrisoncarter <31416563+garrisoncarter@users.noreply.github.com> | 2022-07-11 00:57:14 -0700 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-11 09:57:14 +0200 |
commit | d4eea1f8fc138b39ea78b3bf555c2e0438f2404e (patch) | |
tree | 73345897298cdd69a1dd706a69adb264d1436430 /psutil | |
parent | 072e3bfcf2dfc45288dd00de816f2940e5d5f2bc (diff) | |
download | psutil-d4eea1f8fc138b39ea78b3bf555c2e0438f2404e.tar.gz |
[Linux] `net_if_stats()` returns an incorrect speed value for 100GbE network cards (#2096)
Diffstat (limited to 'psutil')
-rw-r--r-- | psutil/_psutil_linux.c | 11 |
1 files changed, 10 insertions, 1 deletions
diff --git a/psutil/_psutil_linux.c b/psutil/_psutil_linux.c index 70cf5d1b..c59050cb 100644 --- a/psutil/_psutil_linux.c +++ b/psutil/_psutil_linux.c @@ -417,6 +417,7 @@ psutil_net_if_duplex_speed(PyObject* self, PyObject* args) { int sock = 0; int ret; int duplex; + __u32 uint_speed; int speed; struct ifreq ifr; struct ethtool_cmd ethcmd; @@ -438,7 +439,15 @@ psutil_net_if_duplex_speed(PyObject* self, PyObject* args) { if (ret != -1) { duplex = ethcmd.duplex; - speed = ethcmd.speed; + // speed is returned from ethtool as a __u32 ranging from 0 to INT_MAX + // or SPEED_UNKNOWN (-1) + uint_speed = ethtool_cmd_speed(ðcmd); + if (uint_speed == (__u32)SPEED_UNKNOWN || uint_speed > INT_MAX) { + speed = 0; + } + else { + speed = (int)uint_speed; + } } else { if ((errno == EOPNOTSUPP) || (errno == EINVAL)) { |