I have the following code snippet to fetch linux network interface speed:
struct ethtool_cmd cmd;
uint32_t speed = 0;
cmd.cmd = ETHTOOL_GSET;
/* Some other codes */
speed = ethtool_cmd_speed(&cmd);
std::cout << std::to_string(speed));
It has been found that in some cases, when a linux interface is down the value of speed is returned as UINT32_MAX
. I have also seen that the speed is returned as '0' when interface is not available. So my concern is why does it return UINT32_MAX
? Some linux commands return '-1' when fails, but the return type of ethtool_cmd_speed
is unsigned int
. So is it equivalent to sending '-1' upon failure?
So my final concern is if the following condition is sufficient to check if the interface speed is successfully fetched
if (speed != UINT32_MAX)
Thanks in advance.
Aucun commentaire:
Enregistrer un commentaire