* tcpip.sys
*/
-#include <roscfg.h>
#include <stdio.h>
#include "iphlpapi_private.h"
#endif
BOOL isIpEntity( HANDLE tcpFile, TDIEntityID *ent ) {
- DWORD entityType, returnedLen;
- NTSTATUS status;
- TCP_REQUEST_QUERY_INFORMATION_EX req;
-
- req.ID.toi_class = INFO_CLASS_GENERIC;
- req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.ID.toi_id = ENTITY_TYPE_ID;
- req.ID.toi_entity = *ent;
-
- status =
- DeviceIoControl
- ( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- &entityType,
- sizeof(entityType),
- &returnedLen,
- NULL );
-
- TRACE("Ent: %04x:d -> %04x\n",
- ent->tei_entity, ent->tei_instance, entityType );
-
- return NT_SUCCESS(status) && entityType == CL_NL_IP;
+ return (ent->tei_entity == CL_NL_ENTITY ||
+ ent->tei_entity == CO_NL_ENTITY);
}
NTSTATUS getNthIpEntity( HANDLE tcpFile, DWORD index, TDIEntityID *ent ) {
}
if( numRoutes == index && i < numEntities ) {
- TRACE("Index %d is entity #%d - %04x:%08x\n", index, i,
+ 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 );
entry->ipsi_numaddr,
entry->ipsi_numroutes,
status);
-
- return status;
+
+ return status;
}
NTSTATUS tdiGetRoutesForIpEntity
status = tdiGetSetOfThings( tcpFile,
INFO_CLASS_PROTOCOL,
INFO_TYPE_PROVIDER,
- IP_MIB_ROUTETABLE_ENTRY_ID,
- ent->tei_entity,
- 0,
+ IP_MIB_ARPTABLE_ENTRY_ID,
+ CL_NL_ENTITY,
+ ent->tei_instance,
0,
sizeof(IPRouteEntry),
(PVOID *)routes,
numRoutes);
- return status;
+ return status;
}
NTSTATUS tdiGetIpAddrsForIpEntity
TRACE("TdiGetIpAddrsForIpEntity(tcpFile %x,entityId %x)\n",
(DWORD)tcpFile, ent->tei_instance);
- status = tdiGetSetOfThings( tcpFile,
- INFO_CLASS_PROTOCOL,
+ status = tdiGetSetOfThings( tcpFile,
+ INFO_CLASS_PROTOCOL,
INFO_TYPE_PROVIDER,
IP_MIB_ADDRTABLE_ENTRY_ID,
- ent->tei_entity,
- 0,
+ CL_NL_ENTITY,
+ ent->tei_instance,
0,
sizeof(IPAddrEntry),
(PVOID *)addrs,
numAddrs );
- return status;
+ return status;
}
DWORD getInterfaceStatsByName(const char *name, PMIB_IFROW entry)
if( !NT_SUCCESS(status) ) {
TRACE("failure: %08x\n", (int)status );
+ closeTcpFile( tcpFile );
return 0;
}
status = tdiGetMibForIpEntity( tcpFile, &entitySet[i], &isnmp );
if( !NT_SUCCESS(status) ) {
tdiFreeThingSet( entitySet );
+ closeTcpFile( tcpFile );
return status;
}
numRoutes += isnmp.ipsi_numroutes;
{
RouteTable *out_route_table;
DWORD numRoutes = getNumRoutes(), routesAdded = 0;
- IPSNMPInfo snmpInfo;
TDIEntityID ent;
HANDLE tcpFile;
NTSTATUS status = openTcpFile( &tcpFile );
TRACE("GETTING ROUTE TABLE\n");
- out_route_table = HeapAlloc( GetProcessHeap(), 0,
- sizeof(RouteTable) +
+ out_route_table = HeapAlloc( GetProcessHeap(), 0,
+ sizeof(RouteTable) +
(sizeof(RouteEntry) * (numRoutes - 1)) );
-
+ if (!out_route_table) {
+ closeTcpFile(tcpFile);
+ return NULL;
+ }
+
out_route_table->numRoutes = numRoutes;
- for( i = 0; routesAdded < numRoutes; i++ ) {
+ for( i = 0; routesAdded < out_route_table->numRoutes; i++ ) {
int j;
IPRouteEntry *route_set;
getNthIpEntity( tcpFile, i, &ent );
- tdiGetMibForIpEntity( tcpFile, &ent, &snmpInfo );
-
- TRACE( "%d routes in instance %d\n", snmpInfo.ipsi_numroutes, i );
tdiGetRoutesForIpEntity( tcpFile, &ent, &route_set, &numRoutes );
-
+
if( !route_set ) {
closeTcpFile( tcpFile );
HeapFree( GetProcessHeap(), 0, out_route_table );
return 0;
}
- TRACE("Route set returned\n");
+ TRACE( "%d routes in instance %d\n", numRoutes, i );
#if 0
- HexDump( route_set,
- sizeof( IPRouteEntry ) *
+ HexDump( route_set,
+ sizeof( IPRouteEntry ) *
snmpInfo.ipsi_numroutes );
#endif
- for( j = 0; j < snmpInfo.ipsi_numroutes; j++ ) {
+ for( j = 0; j < numRoutes; j++ ) {
int routeNum = j + routesAdded;
- out_route_table->routes[routeNum].dest =
+ out_route_table->routes[routeNum].dest =
route_set[j].ire_dest;
out_route_table->routes[routeNum].mask =
route_set[j].ire_mask;
if( route_set ) tdiFreeThingSet( route_set );
- routesAdded += snmpInfo.ipsi_numroutes;
+ routesAdded += numRoutes;
}
+ closeTcpFile( tcpFile );
+
TRACE("Return: %08x, %08x\n", status, out_route_table);
return out_route_table;
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
for( i = 0; i < numEntities; i++ ) {
- if( isInterface( &entitySet[i] ) &&
- hasArp( tcpFile, &entitySet[i] ) ) {
+ if( isInterface( &entitySet[i] ) &&
+ hasArp( tcpFile, &entitySet[i] ) &&
+ !isLoopback( tcpFile, &entitySet[i] ) ) {
status = tdiGetSetOfThings( tcpFile,
INFO_CLASS_PROTOCOL,
&returnSize );
if( status == STATUS_SUCCESS ) totalNumber += returnSize;
- if( IpArpTable ) tdiFreeThingSet( IpArpTable );
+ if( IpArpTable ) {
+ tdiFreeThingSet( IpArpTable );
+ IpArpTable = NULL;
+ }
}
}
DWORD numEntities, returnSize;
TDIEntityID *entitySet;
HANDLE tcpFile;
- int i, row = 0, totalNumber;
+ int i, totalNumber, TmpIdx, CurrIdx = 0;
NTSTATUS status;
PMIB_IPNETTABLE IpArpTable = NULL;
PMIB_IPNETROW AdapterArpTable = NULL;
}
IpArpTable = HeapAlloc
- ( GetProcessHeap(), 0,
+ ( 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( isIpEntity( tcpFile, &entitySet[i] ) &&
- hasArp( tcpFile, &entitySet[i] ) ) {
+ if( isInterface( &entitySet[i] ) &&
+ hasArp( tcpFile, &entitySet[i] ) &&
+ !isLoopback( tcpFile, &entitySet[i] ) ) {
status = tdiGetSetOfThings( tcpFile,
INFO_CLASS_PROTOCOL,
&returnSize );
if( status == STATUS_SUCCESS ) {
- for( row = 0; row < returnSize; row++ )
- IpArpTable->table[row] = AdapterArpTable[row];
+ for( TmpIdx = 0; TmpIdx < returnSize; TmpIdx++, CurrIdx++ )
+ IpArpTable->table[CurrIdx] = AdapterArpTable[TmpIdx];
}
if( AdapterArpTable ) tdiFreeThingSet( AdapterArpTable );
}
}
+ closeTcpFile( tcpFile );
+
tdiFreeThingSet( entitySet );
- IpArpTable->dwNumEntries = row;
+ IpArpTable->dwNumEntries = CurrIdx;
return IpArpTable;
}