Logo Search packages:      
Sourcecode: pwlib version File versions  Download package

BOOL PIPSocket::GetInterfaceTable ( InterfaceTable &  table  )  [static, inherited]

Get a list of all interfaces

Returns:
TRUE if the interface table is returned, FALSE if an error occurs.
Parameters:
table  interface table

Definition at line 2120 of file ethsock.cxx.

References PString::IsEmpty(), and PString::MakeMinimumSize().

{
  PWin32SnmpLibrary & snmp = snmp.Current();

  PWaitAndSignal m(GetSNMPMutex());

  table.RemoveAll();

  /*
  if (!snmp.IsLoaded()) {
    // Error loading the SNMP library, fail safe to using whatever the
    // address of the local host is.
    Address ipAddr;
    if (!GetHostAddress(ipAddr))
      return FALSE;
    Address netMask(255,255,255,255);
    table.Append(new InterfaceEntry("FailSafe Interface", ipAddr, netMask, PString::Empty()));
    table.Append(new InterfaceEntry("localhost", PIPSocket::Address(), netMask, PString::Empty()));
    return TRUE;
  }
  */

  PWin32AsnOid baseOid = "1.3.6.1.2.1.4.20.1";
  PWin32AsnOid oid = baseOid;
  PWin32AsnAny value;
  while (snmp.GetNextOid(oid, value)) {
    if (!(baseOid *= oid))
      break;
    if (value.asnType != ASN_IPADDRESS)
      break;

    Address ipAddr;
    value.GetIpAddress(ipAddr);

    oid[9] = 3;
    Address netMask;
    if (!snmp.GetOid(oid, netMask))
      break;

    oid[9] = 2;
    AsnInteger ifIndex = -1;
    if (!snmp.GetOid(oid, ifIndex))
      break;

    PString macAddr;
    PEthSocket::Address ifPhysAddress("");
    PWin32AsnOid ifOid = "1.3.6.1.2.1.2.2.1.6.0";
    ifOid[10] = ifIndex;
    UINT len;
    if (snmp.GetOid(ifOid, &ifPhysAddress, sizeof(ifPhysAddress), &len) && len > 0)
      macAddr = ifPhysAddress;
  
    PString name = snmp.GetInterfaceName(ipAddr);
    if (name.IsEmpty()) {
      PWin32AsnOid nameOid = "1.3.6.1.2.1.2.2.1.2.0";
      nameOid[10] = ifIndex;
      if (!snmp.GetOid(nameOid, name))
        break;
      name.MakeMinimumSize();
    }

#ifdef _WIN32_WCE // Getting rid of ghost ips
    if ( !name.IsEmpty() )
#endif
      table.Append(new InterfaceEntry(name, ipAddr, netMask, macAddr));

    oid[9] = 1;
  }

  return TRUE;
}


Generated by  Doxygen 1.6.0   Back to index