NTSTATUS getNthIpEntity( HANDLE tcpFile, DWORD index, TDIEntityID *ent ) { DWORD numEntities = 0; DWORD numRoutes = 0; TDIEntityID *entitySet = 0; NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); int i; if( !NT_SUCCESS(status) ) return status; for( i = 0; i < numEntities; i++ ) { if( isIpEntity( tcpFile, &entitySet[i] ) ) { TRACE("Entity %d is an IP Entity\n", i); if( numRoutes == index ) break; else numRoutes++; } } if( numRoutes == index && i < numEntities ) { TRACE("Index %d is entity #%d - %04x:%08x\n", index, i, entitySet[i].tei_entity, entitySet[i].tei_instance ); memcpy( ent, &entitySet[i], sizeof(*ent) ); tdiFreeThingSet( entitySet ); return STATUS_SUCCESS; } else { tdiFreeThingSet( entitySet ); return STATUS_UNSUCCESSFUL; } }
DWORD getNumArpEntries(void) { DWORD numEntities; TDIEntityID *entitySet = NULL; HANDLE tcpFile; int i, totalNumber = 0; NTSTATUS status; PMIB_IPNETROW IpArpTable = NULL; DWORD returnSize; TRACE("called.\n"); status = openTcpFile( &tcpFile ); if( !NT_SUCCESS(status) ) { TRACE("failure: %08x\n", (int)status ); return 0; } status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); for( i = 0; i < numEntities; i++ ) { if( isInterface( &entitySet[i] ) && hasArp( tcpFile, &entitySet[i] ) ) { status = tdiGetSetOfThings( tcpFile, INFO_CLASS_PROTOCOL, INFO_TYPE_PROVIDER, IP_MIB_ARPTABLE_ENTRY_ID, AT_ENTITY, entitySet[i].tei_instance, 0, sizeof(MIB_IPNETROW), (PVOID *)&IpArpTable, &returnSize ); if( status == STATUS_SUCCESS ) totalNumber += returnSize; if( IpArpTable ) { tdiFreeThingSet( IpArpTable ); IpArpTable = NULL; } } } closeTcpFile( tcpFile ); if( IpArpTable ) tdiFreeThingSet( IpArpTable ); if( entitySet ) tdiFreeThingSet( entitySet ); return totalNumber; }
DWORD getNumRoutes(void) { DWORD numEntities, numRoutes = 0; TDIEntityID *entitySet; HANDLE tcpFile; int i; NTSTATUS status; TRACE("called.\n"); status = openTcpFile( &tcpFile ); if( !NT_SUCCESS(status) ) { TRACE("failure: %08x\n", (int)status ); return 0; } status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); if( !NT_SUCCESS(status) ) { TRACE("failure: %08x\n", (int)status ); closeTcpFile( tcpFile ); return 0; } for( i = 0; i < numEntities; i++ ) { if( isIpEntity( tcpFile, &entitySet[i] ) ) { IPSNMPInfo isnmp; memset( &isnmp, 0, sizeof( isnmp ) ); status = tdiGetMibForIpEntity( tcpFile, &entitySet[i], &isnmp ); if( !NT_SUCCESS(status) ) { tdiFreeThingSet( entitySet ); closeTcpFile( tcpFile ); return status; } numRoutes += isnmp.ipsi_numroutes; } } TRACE("numRoutes: %d\n", (int)numRoutes); closeTcpFile( tcpFile ); return numRoutes; }
static DWORD getNumInterfacesInt(BOOL onlyNonLoopback) { DWORD numEntities, numInterfaces = 0; TDIEntityID *entitySet; HANDLE tcpFile; NTSTATUS status; int i; status = openTcpFile( &tcpFile, FILE_READ_DATA ); if( !NT_SUCCESS(status) ) { WARN("getNumInterfaces: failed %08x\n", status ); return 0; } status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); if( !NT_SUCCESS(status) ) { WARN("getNumInterfaces: failed %08x\n", status ); closeTcpFile( tcpFile ); return 0; } for( i = 0; i < numEntities; i++ ) { if( isInterface( &entitySet[i] ) && (!onlyNonLoopback || (onlyNonLoopback && !isLoopback( tcpFile, &entitySet[i] ))) ) numInterfaces++; } TRACE("getNumInterfaces: success: %d %d %08x\n", onlyNonLoopback, numInterfaces, status ); closeTcpFile( tcpFile ); tdiFreeThingSet( entitySet ); return numInterfaces; }
PMIB_IPNETTABLE getArpTable(void) { DWORD numEntities, returnSize; TDIEntityID *entitySet; HANDLE tcpFile; int i, totalNumber, TmpIdx, CurrIdx = 0; NTSTATUS status; PMIB_IPNETTABLE IpArpTable = NULL; PMIB_IPNETROW AdapterArpTable = NULL; TRACE("called.\n"); totalNumber = getNumArpEntries(); status = openTcpFile( &tcpFile ); if( !NT_SUCCESS(status) ) { TRACE("failure: %08x\n", (int)status ); return 0; } IpArpTable = HeapAlloc ( GetProcessHeap(), 0, sizeof(DWORD) + (sizeof(MIB_IPNETROW) * totalNumber) ); if (!IpArpTable) { closeTcpFile(tcpFile); return NULL; } status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities ); for( i = 0; i < numEntities; i++ ) { if( isInterface( &entitySet[i] ) && hasArp( tcpFile, &entitySet[i] ) ) { status = tdiGetSetOfThings( tcpFile, INFO_CLASS_PROTOCOL, INFO_TYPE_PROVIDER, IP_MIB_ARPTABLE_ENTRY_ID, AT_ENTITY, entitySet[i].tei_instance, 0, sizeof(MIB_IPNETROW), (PVOID *)&AdapterArpTable, &returnSize ); if( status == STATUS_SUCCESS ) { for( TmpIdx = 0; TmpIdx < returnSize; TmpIdx++, CurrIdx++ ) IpArpTable->table[CurrIdx] = AdapterArpTable[TmpIdx]; tdiFreeThingSet( AdapterArpTable ); } } } closeTcpFile( tcpFile ); tdiFreeThingSet( entitySet ); IpArpTable->dwNumEntries = CurrIdx; return IpArpTable; }
static NTSTATUS getInterfaceInfoSet( HANDLE tcpFile, IFInfo **infoSet, PDWORD numInterfaces ) { DWORD numEntities; TDIEntityID *entIDSet = 0; NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entIDSet, &numEntities ); IFInfo *infoSetInt = 0; int curInterf = 0, i; if (!NT_SUCCESS(status)) { ERR("getInterfaceInfoSet: tdiGetEntityIDSet() failed: 0x%lx\n", status); return status; } infoSetInt = HeapAlloc( GetProcessHeap(), 0, sizeof(IFInfo) * numEntities ); if( infoSetInt ) { for( i = 0; i < numEntities; i++ ) { if( isInterface( &entIDSet[i] ) ) { infoSetInt[curInterf].entity_id = entIDSet[i]; status = tdiGetMibForIfEntity ( tcpFile, &entIDSet[i], &infoSetInt[curInterf].if_info ); TRACE("tdiGetMibForIfEntity: %08x\n", status); if( NT_SUCCESS(status) ) { DWORD numAddrs; IPAddrEntry *addrs; TDIEntityID ip_ent; int j; status = getNthIpEntity( tcpFile, curInterf, &ip_ent ); if( NT_SUCCESS(status) ) status = tdiGetIpAddrsForIpEntity ( tcpFile, &ip_ent, &addrs, &numAddrs ); for( j = 0; j < numAddrs && NT_SUCCESS(status); j++ ) { TRACE("ADDR %d: index %d (target %d)\n", j, addrs[j].iae_index, infoSetInt[curInterf].if_info.ent.if_index); if( addrs[j].iae_index == infoSetInt[curInterf].if_info.ent.if_index ) { memcpy( &infoSetInt[curInterf].ip_addr, &addrs[j], sizeof( addrs[j] ) ); curInterf++; break; } } } } } tdiFreeThingSet(entIDSet); if (NT_SUCCESS(status)) { *infoSet = infoSetInt; *numInterfaces = curInterf; } else { HeapFree(GetProcessHeap(), 0, infoSetInt); } return status; } else { return STATUS_INSUFFICIENT_RESOURCES; } }