So, I'm writing a kernel module that needs stats about local network interfaces and I came up with the following code … everything works fine except for the part where I try to read wireless device stats … apparently the wireless_handler
struct is not filled because the CONFIG_WIRELESS_EXT
is not set … my question? Where does ifconfig
get its' wireless stats from?
struct net_device *dev;
struct net_device_stats *stats;
struct iw_statistics *wi_stats;
dev = first_net_device(&init_net);
while (dev)
{
if (strncmp(dev->name , "wlan",4)==0 && (dev->flags & IFF_UP) == 1)
{
#ifndef CONFIG_WIRELESS_EXT
wi_stats = dev -> wireless_handlers -> get_wireless_stats(dev);
#endif
}
else if (strncmp(dev->name , "eth",3)==0 || strncmp(dev->name , "lo",2)==0)
{
stats = dev->netdev_ops->ndo_get_stats(dev);
printk(KERN_INFO "recive packets: [%li]\ntransmitted packets: [%li]\nrecive errors: [%li]\ntransmission errors: [%li]\nnumber of collisions: [%li]",
stats->rx_packets , stats->tx_packets ,stats->rx_errors , stats->tx_errors, stats->collisions);
}
dev = next_net_device(dev);
}//end while
Best Answer
Using
strace
, you can seeiwconfig
doing something like this:And a dozen or so other
ioctl
s follow. Chase down thoseioctl
s in the kernel and you'll find where the data is.