ethernet: print faster speeds in Gbit/s
As a special case, for 2500 Mbit/s, we display “2.5 Gbit/s”. For other speeds over 1000 Mbit/s, we print “10 Gbit/s”, “25 Gbit/s” or “100 Gbit/s”.
This commit is contained in:
parent
c1e9069aa1
commit
d5e1d58ae0
@ -46,6 +46,13 @@ static int print_eth_speed(char *outwalk, const char *interface) {
|
||||
(void)strcpy(ifr.ifr_name, interface);
|
||||
if (ioctl(general_socket, SIOCETHTOOL, &ifr) == 0) {
|
||||
ethspeed = (ecmd.speed == USHRT_MAX ? 0 : ethtool_cmd_speed(&ecmd));
|
||||
if (ethspeed == 2500) {
|
||||
// 2.5 Gbit/s is the only case where floating point formatting is most
|
||||
// common.
|
||||
return sprintf(outwalk, "%.1f Gbit/s", (double)ethspeed / 1000);
|
||||
} else if (ethspeed > 1000) {
|
||||
return sprintf(outwalk, "%d Gbit/s", ethspeed / 1000);
|
||||
}
|
||||
return sprintf(outwalk, "%d Mbit/s", ethspeed);
|
||||
} else
|
||||
return sprintf(outwalk, "?");
|
||||
|
Loading…
Reference in New Issue
Block a user