Back to index

lshw  02.16
Functions
network.h File Reference
#include "hw.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

bool scan_network (hwNode &n)

Function Documentation

bool scan_network ( hwNode n)

Definition at line 298 of file network.cc.

{
  vector < string > interfaces;
  char buffer[2 * IFNAMSIZ + 1];

  if (!load_interfaces(interfaces))
    return false;

  int fd = socket(PF_INET, SOCK_DGRAM, 0);

  if (fd >= 0)
  {
    struct ifreq ifr;
    struct ethtool_drvinfo drvinfo;
    struct ethtool_cmd ecmd;
    struct ethtool_value edata;

    for (unsigned int i = 0; i < interfaces.size(); i++)
    {
      hwNode interface("network",
        hw::network);

      interface.setLogicalName(interfaces[i]);
      interface.claim();
      interface.addHint("icon", string("network"));

      string businfo = sysfs_getbusinfo(sysfs::entry::byClass("net", interface.getLogicalName()));
      interface.setBusInfo(businfo);

//scan_mii(fd, interface);
      scan_ip(interface);

      memset(&ifr, 0, sizeof(ifr));
      strcpy(ifr.ifr_name, interfaces[i].c_str());
      if (ioctl(fd, SIOCGIFFLAGS, &ifr) == 0)
      {
#ifdef IFF_PORTSEL
        if (ifr.ifr_flags & IFF_PORTSEL)
        {
          if (ifr.ifr_flags & IFF_AUTOMEDIA)
            interface.setConfig("automedia", "yes");
        }
#endif

        if (ifr.ifr_flags & IFF_UP)
          interface.enable();
        else
          interface.disable();
        if (ifr.ifr_flags & IFF_BROADCAST)
          interface.setConfig("broadcast", "yes");
        if (ifr.ifr_flags & IFF_DEBUG)
          interface.setConfig("debug", "yes");
        if (ifr.ifr_flags & IFF_LOOPBACK)
          interface.setConfig("loopback", "yes");
        if (ifr.ifr_flags & IFF_POINTOPOINT)
          interface.setConfig("point-to-point", "yes");
        if (ifr.ifr_flags & IFF_PROMISC)
          interface.setConfig("promiscuous", "yes");
        if (ifr.ifr_flags & IFF_SLAVE)
          interface.setConfig("slave", "yes");
        if (ifr.ifr_flags & IFF_MASTER)
          interface.setConfig("master", "yes");
        if (ifr.ifr_flags & IFF_MULTICAST)
          interface.setConfig("multicast", "yes");
      }

      memset(&ifr, 0, sizeof(ifr));
      strcpy(ifr.ifr_name, interfaces[i].c_str());
// get MAC address
      if (ioctl(fd, SIOCGIFHWADDR, &ifr) == 0)
      {
        string hwaddr = getmac((unsigned char *) ifr.ifr_hwaddr.sa_data);
        interface.addCapability(hwname(ifr.ifr_hwaddr.sa_family));
        if (ifr.ifr_hwaddr.sa_family >= 256)
          interface.addCapability("logical", _("Logical interface"));
        else
          interface.addCapability("physical", _("Physical interface"));
        interface.setDescription(string(hwname(ifr.ifr_hwaddr.sa_family)) +
          " interface");
        interface.setSerial(hwaddr);

        if (isVirtual(interface.getSerial()))
          interface.addCapability("logical", _("Logical interface"));
      }

// check for wireless extensions
      memset(buffer, 0, sizeof(buffer));
      strncpy(buffer, interfaces[i].c_str(), sizeof(buffer));
      if (ioctl(fd, SIOCGIWNAME, &buffer) == 0)
      {
        interface.addCapability("wireless", _("Wireless-LAN"));
        interface.setConfig("wireless", hw::strip(buffer + IFNAMSIZ));
        interface.setDescription(_("Wireless interface"));
        interface.addHint("icon", string("wifi"));
        interface.addHint("bus.icon", string("radio"));
      }

      edata.cmd = ETHTOOL_GLINK;
      memset(&ifr, 0, sizeof(ifr));
      strcpy(ifr.ifr_name, interfaces[i].c_str());
      ifr.ifr_data = (caddr_t) &edata;
      if (ioctl(fd, SIOCETHTOOL, &ifr) == 0)
      {
        interface.setConfig("link", edata.data ? "yes":"no");
      }

      ecmd.cmd = ETHTOOL_GSET;
      memset(&ifr, 0, sizeof(ifr));
      strcpy(ifr.ifr_name, interfaces[i].c_str());
      ifr.ifr_data = (caddr_t) &ecmd;
      if (ioctl(fd, SIOCETHTOOL, &ifr) == 0)
      {
        if(ecmd.supported & SUPPORTED_TP)
          interface.addCapability("tp", _("twisted pair"));
        if(ecmd.supported & SUPPORTED_AUI)
          interface.addCapability("aui", _("AUI"));
        if(ecmd.supported & SUPPORTED_BNC)
          interface.addCapability("bnc", _("BNC"));
        if(ecmd.supported & SUPPORTED_MII)
          interface.addCapability("mii", _("Media Independant Interface"));
        if(ecmd.supported & SUPPORTED_FIBRE)
          interface.addCapability("fibre",_( "optical fibre"));
        if(ecmd.supported & SUPPORTED_10baseT_Half)
        {
          interface.addCapability("10bt", _("10Mbit/s"));
          interface.setCapacity(10000000L);
        }
        if(ecmd.supported & SUPPORTED_10baseT_Full)
        {
          interface.addCapability("10bt-fd", _("10Mbit/s (full duplex)"));
          interface.setCapacity(10000000L);
        }
        if(ecmd.supported & SUPPORTED_100baseT_Half)
        {
          interface.addCapability("100bt", _("100Mbit/s"));
          interface.setCapacity(100000000L);
        }
        if(ecmd.supported & SUPPORTED_100baseT_Full)
        {
          interface.addCapability("100bt-fd", _("100Mbit/s (full duplex)"));
          interface.setCapacity(100000000L);
        }
        if(ecmd.supported & SUPPORTED_1000baseT_Half)
        {
          interface.addCapability("1000bt", "1Gbit/s");
          interface.setCapacity(1000000000L);
        }
        if(ecmd.supported & SUPPORTED_1000baseT_Full)
        {
          interface.addCapability("1000bt-fd", _("1Gbit/s (full duplex)"));
          interface.setCapacity(1000000000L);
        }
        if(ecmd.supported & SUPPORTED_Autoneg)
          interface.addCapability("autonegotiation", _("Auto-negotiation"));

        switch(ecmd.speed)
        {
          case SPEED_10:
            interface.setConfig("speed", "10Mbit/s");
            interface.setSize(10000000L);
            break;
          case SPEED_100:
            interface.setConfig("speed", "100Mbit/s");
            interface.setSize(100000000L);
            break;
          case SPEED_1000:
            interface.setConfig("speed", "1Gbit/s");
            interface.setSize(1000000000L);
            break;
        }
        switch(ecmd.duplex)
        {
          case DUPLEX_HALF:
            interface.setConfig("duplex", "half");
            break;
          case DUPLEX_FULL:
            interface.setConfig("duplex", "full");
            break;
        }
        switch(ecmd.port)
        {
          case PORT_TP:
            interface.setConfig("port", "twisted pair");
            break;
          case PORT_AUI:
            interface.setConfig("port", "AUI");
            break;
          case PORT_BNC:
            interface.setConfig("port", "BNC");
            break;
          case PORT_MII:
            interface.setConfig("port", "MII");
            break;
          case PORT_FIBRE:
            interface.setConfig("port", "fibre");
            break;
        }
        interface.setConfig("autonegotiation", (ecmd.autoneg == AUTONEG_DISABLE) ?  "off" : "on");
      }

      drvinfo.cmd = ETHTOOL_GDRVINFO;
      memset(&ifr, 0, sizeof(ifr));
      strcpy(ifr.ifr_name, interfaces[i].c_str());
      ifr.ifr_data = (caddr_t) & drvinfo;
      if (ioctl(fd, SIOCETHTOOL, &ifr) == 0)
      {
        interface.setConfig("driver", drvinfo.driver);
        interface.setConfig("driverversion", drvinfo.version);
        interface.setConfig("firmware", drvinfo.fw_version);
        if (interface.getBusInfo() == "")
          interface.setBusInfo(guessBusInfo(drvinfo.bus_info));
      }

      if(sysfs::entry::byClass("net", interface.getLogicalName()).hassubdir("bridge"))
        interface.addCapability("logical", _("Logical interface"));

      if (hwNode * existing = n.findChildByBusInfo(interface.getBusInfo()))
      {
        existing->merge(interface);
        if(interface.getDescription()!="")
          existing->setDescription(interface.getDescription());
      }
      else
      {
        existing = n.findChildByLogicalName(interface.getLogicalName());
        if (existing)
        {
          existing->merge(interface);
        }
        else
        {
// we don't care about loopback and "logical" interfaces
          if (!interface.isCapable("loopback") &&
            !interface.isCapable("logical"))
            n.addChild(interface);
        }
      }
    }

    close(fd);
    return true;
  }
  else
    return false;
}

Here is the call graph for this function:

Here is the caller graph for this function: