2010-05-15 5 views

Répondre

4

Chaque pilote réseau dispose d'une implémentation "ethtool" pour de telles fonctionnalités. Mais vous avez probablement besoin d'une fonction générique qui peut vous donner la vitesse d'une structure netdev générique. Vous pouvez jeter un oeil à net/core/net-sysfs.c et voir comment il implémente l'interface/sys/class/net. Par exemple:

static ssize_t show_speed(struct device *dev, 
      struct device_attribute *attr, char *buf) 
{ 
    struct net_device *netdev = to_net_dev(dev); 
    int ret = -EINVAL; 

    if (!rtnl_trylock()) 
     return restart_syscall(); 

    if (netif_running(netdev) && 
     netdev->ethtool_ops && 
     netdev->ethtool_ops->get_settings) { 
     struct ethtool_cmd cmd = { ETHTOOL_GSET }; 

     if (!netdev->ethtool_ops->get_settings(netdev, &cmd)) 
      ret = sprintf(buf, fmt_dec, ethtool_cmd_speed(&cmd)); 
    } 
    rtnl_unlock(); 
    return ret; 
} 
Questions connexes