RtlInitUnicodeString( &fileName, TcpFileName );
InitializeObjectAttributes( &objectAttributes,
- &fileName,
- OBJ_CASE_INSENSITIVE,
- NULL,
- NULL );
+ &fileName,
+ OBJ_CASE_INSENSITIVE,
+ NULL,
+ NULL );
status = NtCreateFile( tcpFile,
- SYNCHRONIZE | GENERIC_EXECUTE,
- &objectAttributes,
- &ioStatusBlock,
- NULL,
- FILE_ATTRIBUTE_NORMAL,
- FILE_SHARE_READ | FILE_SHARE_WRITE,
- FILE_OPEN_IF,
- FILE_SYNCHRONOUS_IO_NONALERT,
- 0,
- 0 );
+ SYNCHRONIZE | GENERIC_EXECUTE,
+ &objectAttributes,
+ &ioStatusBlock,
+ NULL,
+ FILE_ATTRIBUTE_NORMAL,
+ FILE_SHARE_READ | FILE_SHARE_WRITE,
+ FILE_OPEN_IF,
+ FILE_SYNCHRONOUS_IO_NONALERT,
+ 0,
+ 0 );
/* String does not need to be freed: it points to the constant
* string we provided */
* IPInterfaceInfo
*/
NTSTATUS tdiGetSetOfThings( HANDLE tcpFile,
- DWORD toiClass,
- DWORD toiType,
- DWORD toiId,
- DWORD teiEntity,
- DWORD fixedPart,
- DWORD entrySize,
- PVOID *tdiEntitySet,
- PDWORD numEntries ) {
+ DWORD toiClass,
+ DWORD toiType,
+ DWORD toiId,
+ DWORD teiEntity,
+ DWORD fixedPart,
+ DWORD entrySize,
+ PVOID *tdiEntitySet,
+ PDWORD numEntries ) {
TCP_REQUEST_QUERY_INFORMATION_EX req = TCP_REQUEST_QUERY_INFORMATION_INIT;
PVOID entitySet = 0;
NTSTATUS status = STATUS_SUCCESS;
DWORD allocationSizeForEntityArray = entrySize * MAX_TDI_ENTITIES,
- arraySize = entrySize * MAX_TDI_ENTITIES;
+ arraySize = entrySize * MAX_TDI_ENTITIES;
DPRINT("TdiGetSetOfThings(tcpFile %x,toiClass %x,toiType %x,toiId %x,"
- "teiEntity %x,fixedPart %d,entrySize %d)\n",
- (int)tcpFile,
- (int)toiClass,
- (int)toiType,
- (int)toiId,
- (int)teiEntity,
- (int)fixedPart,
- (int)entrySize );
+ "teiEntity %x,fixedPart %d,entrySize %d)\n",
+ (int)tcpFile,
+ (int)toiClass,
+ (int)toiType,
+ (int)toiId,
+ (int)teiEntity,
+ (int)fixedPart,
+ (int)entrySize );
req.ID.toi_class = toiClass;
req.ID.toi_type = toiType;
* stabilizes.
*/
do {
- assert( !entitySet ); /* We must not have an entity set allocated */
- status = DeviceIoControl( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- 0,
- 0,
- &allocationSizeForEntityArray,
- NULL );
-
- if( !NT_SUCCESS(status) ) {
- DPRINT("TdiGetSetOfThings() => %08x\n", (int)status);
- return status;
- }
-
- arraySize = allocationSizeForEntityArray;
- entitySet = HeapAlloc( GetProcessHeap(), 0, arraySize );
-
- if( !entitySet ) {
- status = STATUS_INSUFFICIENT_RESOURCES;
- DPRINT("TdiGetSetOfThings() => %08x\n", (int)status);
- return status;
- }
-
- status = DeviceIoControl( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- entitySet,
- arraySize,
- &allocationSizeForEntityArray,
- NULL );
-
- /* This is why we have the loop -- we might have added an adapter */
- if( arraySize == allocationSizeForEntityArray )
- break;
-
- HeapFree( GetProcessHeap(), 0, entitySet );
- entitySet = 0;
-
- if( !NT_SUCCESS(status) ) {
- DPRINT("TdiGetSetOfThings() => %08x\n", (int)status);
- return status;
- }
-
- DPRINT("TdiGetSetOfThings(): Array changed size: %d -> %d.\n",
- arraySize, allocationSizeForEntityArray );
+ assert( !entitySet ); /* We must not have an entity set allocated */
+ status = DeviceIoControl( tcpFile,
+ IOCTL_TCP_QUERY_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ 0,
+ 0,
+ &allocationSizeForEntityArray,
+ NULL );
+
+ if( !NT_SUCCESS(status) ) {
+ DPRINT("TdiGetSetOfThings() => %08x\n", (int)status);
+ return status;
+ }
+
+ arraySize = allocationSizeForEntityArray;
+ entitySet = HeapAlloc( GetProcessHeap(), 0, arraySize );
+
+ if( !entitySet ) {
+ status = STATUS_INSUFFICIENT_RESOURCES;
+ DPRINT("TdiGetSetOfThings() => %08x\n", (int)status);
+ return status;
+ }
+
+ status = DeviceIoControl( tcpFile,
+ IOCTL_TCP_QUERY_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ entitySet,
+ arraySize,
+ &allocationSizeForEntityArray,
+ NULL );
+
+ /* This is why we have the loop -- we might have added an adapter */
+ if( arraySize == allocationSizeForEntityArray )
+ break;
+
+ HeapFree( GetProcessHeap(), 0, entitySet );
+ entitySet = 0;
+
+ if( !NT_SUCCESS(status) ) {
+ DPRINT("TdiGetSetOfThings() => %08x\n", (int)status);
+ return status;
+ }
+
+ DPRINT("TdiGetSetOfThings(): Array changed size: %d -> %d.\n",
+ arraySize, allocationSizeForEntityArray );
} while( TRUE ); /* We break if the array we received was the size we
- * expected. Therefore, we got here because it wasn't */
+ * expected. Therefore, we got here because it wasn't */
*numEntries = (arraySize - fixedPart) / entrySize;
*tdiEntitySet = entitySet;
DPRINT("TdiGetSetOfThings() => Success: %d things @ %08x\n",
- (int)*numEntries, (int)entitySet);
+ (int)*numEntries, (int)entitySet);
return STATUS_SUCCESS;
}
DWORD returnSize;
DPRINT("TdiGetMibForIfEntity(tcpFile %x,entityId %x)\n",
- (int)tcpFile, (int)ent->tei_instance);
+ (int)tcpFile, (int)ent->tei_instance);
req.ID.toi_class = INFO_CLASS_PROTOCOL;
req.ID.toi_type = INFO_TYPE_PROVIDER;
req.ID.toi_entity = *ent;
status = DeviceIoControl( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- entry,
- sizeof(*entry),
- &returnSize,
- NULL );
+ IOCTL_TCP_QUERY_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ entry,
+ sizeof(*entry),
+ &returnSize,
+ NULL );
if( !NT_SUCCESS(status) ) {
- TRACE("failure: %08x\n", status);
- return status;
+ TRACE("failure: %08x\n", status);
+ return status;
} else TRACE("Success.\n");
DPRINT("TdiGetMibForIfEntity() => {\n"
- " if_index ....................... %x\n"
- " if_type ........................ %x\n"
- " if_mtu ......................... %d\n"
- " if_speed ....................... %x\n"
- " if_physaddrlen ................. %d\n",
- entry->ent.if_index,
- entry->ent.if_type,
- entry->ent.if_mtu,
- entry->ent.if_speed,
- entry->ent.if_physaddrlen);
+ " if_index ....................... %x\n"
+ " if_type ........................ %x\n"
+ " if_mtu ......................... %d\n"
+ " if_speed ....................... %x\n"
+ " if_physaddrlen ................. %d\n",
+ entry->ent.if_index,
+ entry->ent.if_type,
+ entry->ent.if_mtu,
+ entry->ent.if_speed,
+ entry->ent.if_physaddrlen);
DPRINT(" if_physaddr .................... %02x:%02x:%02x:%02x:%02x:%02x\n",
- " if_descr ....................... %s\n",
- entry->ent.if_physaddr[0] & 0xff,
- entry->ent.if_physaddr[1] & 0xff,
- entry->ent.if_physaddr[2] & 0xff,
- entry->ent.if_physaddr[3] & 0xff,
- entry->ent.if_physaddr[4] & 0xff,
- entry->ent.if_physaddr[5] & 0xff,
- entry->ent.if_descr);
+ " if_descr ....................... %s\n",
+ entry->ent.if_physaddr[0] & 0xff,
+ entry->ent.if_physaddr[1] & 0xff,
+ entry->ent.if_physaddr[2] & 0xff,
+ entry->ent.if_physaddr[3] & 0xff,
+ entry->ent.if_physaddr[4] & 0xff,
+ entry->ent.if_physaddr[5] & 0xff,
+ entry->ent.if_descr);
DPRINT("} status %08x\n",status);
-
+
return status;
}
NTSTATUS tdiGetEntityIDSet( HANDLE tcpFile,
- TDIEntityID **entitySet,
- PDWORD numEntities ) {
+ TDIEntityID **entitySet,
+ PDWORD numEntities ) {
NTSTATUS status = tdiGetSetOfThings( tcpFile,
- INFO_CLASS_GENERIC,
- INFO_TYPE_PROVIDER,
- ENTITY_LIST_ID,
- GENERIC_ENTITY,
- 0,
- sizeof(TDIEntityID),
- (PVOID *)entitySet,
- numEntities );
+ INFO_CLASS_GENERIC,
+ INFO_TYPE_PROVIDER,
+ ENTITY_LIST_ID,
+ GENERIC_ENTITY,
+ 0,
+ sizeof(TDIEntityID),
+ (PVOID *)entitySet,
+ numEntities );
if( NT_SUCCESS(status) ) {
- int i;
-
- for( i = 0; i < *numEntities; i++ ) {
- DPRINT("%-4d: %04x:%08x\n",
- i,
- (*entitySet)[i].tei_entity,
- (*entitySet)[i].tei_instance );
- }
+ int i;
+
+ for( i = 0; i < *numEntities; i++ ) {
+ DPRINT("%-4d: %04x:%08x\n",
+ i,
+ (*entitySet)[i].tei_entity,
+ (*entitySet)[i].tei_instance );
+ }
}
return status;
static BOOL isInterface( TDIEntityID *if_maybe ) {
return
- if_maybe->tei_entity == IF_ENTITY;
+ if_maybe->tei_entity == IF_ENTITY;
}
static BOOL isLoopback( HANDLE tcpFile, TDIEntityID *loop_maybe ) {
IFEntrySafelySized entryInfo;
tdiGetMibForIfEntity( tcpFile,
- loop_maybe,
- &entryInfo );
+ loop_maybe,
+ &entryInfo );
return !entryInfo.ent.if_type ||
- entryInfo.ent.if_type == IFENT_SOFTWARE_LOOPBACK;
+ entryInfo.ent.if_type == IFENT_SOFTWARE_LOOPBACK;
}
NTSTATUS tdiGetEntityType( HANDLE tcpFile, TDIEntityID *ent, PULONG type ) {
DWORD returnSize;
DPRINT("TdiGetEntityType(tcpFile %x,entityId %x)\n",
- (DWORD)tcpFile, ent->tei_instance);
+ (DWORD)tcpFile, ent->tei_instance);
req.ID.toi_class = INFO_CLASS_GENERIC;
req.ID.toi_type = INFO_TYPE_PROVIDER;
req.ID.toi_entity.tei_instance = ent->tei_instance;
status = DeviceIoControl( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- type,
- sizeof(*type),
- &returnSize,
- NULL );
+ IOCTL_TCP_QUERY_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ type,
+ sizeof(*type),
+ &returnSize,
+ NULL );
DPRINT("TdiGetEntityType() => %08x %08x\n", *type, status);
}
static NTSTATUS getInterfaceInfoSet( HANDLE tcpFile,
- IFInfo **infoSet,
- PDWORD numInterfaces ) {
+ IFInfo **infoSet,
+ PDWORD numInterfaces ) {
DWORD numEntities;
TDIEntityID *entIDSet = 0;
NTSTATUS status = tdiGetEntityIDSet( tcpFile, &entIDSet, &numEntities );
int curInterf = 0, i;
if( NT_SUCCESS(status) )
- infoSetInt = HeapAlloc( GetProcessHeap(), 0,
- sizeof(IFInfo) * numEntities );
+ infoSetInt = HeapAlloc( GetProcessHeap(), 0,
+ sizeof(IFInfo) * numEntities );
if( infoSetInt ) {
- for( i = 0; i < numEntities; i++ ) {
- if( isInterface( &entIDSet[i] ) ) {
- status = tdiGetMibForIfEntity
- ( tcpFile,
- &entIDSet[i],
- &infoSetInt[curInterf].if_info );
- if( NT_SUCCESS(status) ) {
- DWORD numAddrs;
- IPAddrEntry *addrs;
- TDIEntityID ip_ent;
- int j,k;
-
- interfaceInfoComplete = FALSE;
- for( j = 0; NT_SUCCESS(status); j++ ) {
- status = getNthIpEntity( tcpFile, j, &ip_ent );
- if( NT_SUCCESS(status) )
- status = tdiGetIpAddrsForIpEntity
- ( tcpFile, &ip_ent, &addrs, &numAddrs );
- for( k = 0; k < numAddrs && NT_SUCCESS(status); k++ ) {
- if( addrs[k].iae_index ==
- infoSetInt[curInterf].if_info.ent.if_index ) {
- memcpy( &infoSetInt[curInterf].ip_addr,
- &addrs[k],
- sizeof( addrs[k] ) );
- interfaceInfoComplete = TRUE;
- break;
- }
- }
- if( interfaceInfoComplete ) break;
- }
- }
- if( NT_SUCCESS(status) ) curInterf++;
- }
- }
+ for( i = 0; i < numEntities; i++ ) {
+ if( isInterface( &entIDSet[i] ) ) {
+ status = tdiGetMibForIfEntity
+ ( tcpFile,
+ &entIDSet[i],
+ &infoSetInt[curInterf].if_info );
+ if( NT_SUCCESS(status) ) {
+ DWORD numAddrs;
+ IPAddrEntry *addrs;
+ TDIEntityID ip_ent;
+ int j,k;
+
+ interfaceInfoComplete = FALSE;
+ for( j = 0; NT_SUCCESS(status); j++ ) {
+ status = getNthIpEntity( tcpFile, j, &ip_ent );
+ if( NT_SUCCESS(status) )
+ status = tdiGetIpAddrsForIpEntity
+ ( tcpFile, &ip_ent, &addrs, &numAddrs );
+ for( k = 0; k < numAddrs && NT_SUCCESS(status); k++ ) {
+ if( addrs[k].iae_index ==
+ infoSetInt[curInterf].if_info.ent.if_index ) {
+ memcpy( &infoSetInt[curInterf].ip_addr,
+ &addrs[k],
+ sizeof( addrs[k] ) );
+ interfaceInfoComplete = TRUE;
+ break;
+ }
+ }
+ if( interfaceInfoComplete ) break;
+ }
+ }
+ if( NT_SUCCESS(status) ) curInterf++;
+ }
+ }
}
*infoSet = infoSetInt;
status = openTcpFile( &tcpFile );
if( !NT_SUCCESS(status) ) {
- DPRINT("getNumInterfaces: failed %08x\n", status );
- return 0;
+ DPRINT("getNumInterfaces: failed %08x\n", status );
+ return 0;
}
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
if( !NT_SUCCESS(status) ) {
- DPRINT("getNumInterfaces: failed %08x\n", status );
- return 0;
+ DPRINT("getNumInterfaces: failed %08x\n", status );
+ return 0;
}
closeTcpFile( tcpFile );
for( i = 0; i < numEntities; i++ ) {
- if( isInterface( &entitySet[i] ) &&
- (!onlyLoopback || isLoopback( tcpFile, &entitySet[i] )) )
- numInterfaces++;
+ if( isInterface( &entitySet[i] ) &&
+ (!onlyLoopback || isLoopback( tcpFile, &entitySet[i] )) )
+ numInterfaces++;
}
DPRINT("getNumInterfaces: success: %d %d %08x\n",
- onlyLoopback, numInterfaces, status );
+ onlyLoopback, numInterfaces, status );
tdiFreeThingSet( entitySet );
int i;
if( !NT_SUCCESS(status) )
- return status;
+ return status;
for( i = 0; i < numEntities; i++ ) {
- if( isInterface( &entitySet[i] ) ) {
- if( numInterfaces == index ) break;
- else numInterfaces++;
- }
+ if( isInterface( &entitySet[i] ) ) {
+ if( numInterfaces == index ) break;
+ else numInterfaces++;
+ }
}
DPRINT("Index %d is entity #%d - %04x:%08x\n", index, i,
- entitySet[i].tei_entity, entitySet[i].tei_instance );
+ entitySet[i].tei_entity, entitySet[i].tei_instance );
if( numInterfaces == index && i < numEntities ) {
- memcpy( ent, &entitySet[i], sizeof(*ent) );
- tdiFreeThingSet( entitySet );
- return STATUS_SUCCESS;
+ memcpy( ent, &entitySet[i], sizeof(*ent) );
+ tdiFreeThingSet( entitySet );
+ return STATUS_SUCCESS;
} else {
- tdiFreeThingSet( entitySet );
- return STATUS_UNSUCCESSFUL;
+ tdiFreeThingSet( entitySet );
+ return STATUS_UNSUCCESSFUL;
}
}
int i;
if( NT_SUCCESS(status) )
- for( i = 0; i < numInterfaces; i++ ) {
- if( ifInfo[i].if_info.ent.if_index == index ) {
- memcpy( info, &ifInfo[i], sizeof(*info) );
- break;
- }
- }
+ for( i = 0; i < numInterfaces; i++ ) {
+ if( ifInfo[i].if_info.ent.if_index == index ) {
+ memcpy( info, &ifInfo[i], sizeof(*info) );
+ break;
+ }
+ }
if( NT_SUCCESS(status) )
- return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
+ return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
else
- return status;
+ return status;
}
NTSTATUS getInterfaceInfoByName( HANDLE tcpFile, char *name, IFInfo *info ) {
NTSTATUS status = getInterfaceInfoSet( tcpFile, &ifInfo, &numInterfaces );
if( NT_SUCCESS(status) )
- for( i = 0; i < numInterfaces; i++ ) {
- if( !strcmp(ifInfo[i].if_info.ent.if_descr, name) ) {
- memcpy( info, &ifInfo[i], sizeof(*info) );
- break;
- }
- }
+ for( i = 0; i < numInterfaces; i++ ) {
+ if( !strcmp(ifInfo[i].if_info.ent.if_descr, name) ) {
+ memcpy( info, &ifInfo[i], sizeof(*info) );
+ break;
+ }
+ }
if( NT_SUCCESS(status) )
- return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
+ return i < numInterfaces ? STATUS_SUCCESS : STATUS_UNSUCCESSFUL;
else
- return status;
+ return status;
}
/* Note that the result of this operation must be freed later */
NTSTATUS status = openTcpFile( &tcpFile );
if( NT_SUCCESS(status) ) {
- status = getInterfaceInfoByIndex( tcpFile, index, &ifInfo );
-
- if( NT_SUCCESS(status) ) {
- adapter_name = ifInfo.if_info.ent.if_descr;
-
- interfaceName = HeapAlloc( GetProcessHeap(), 0,
- strlen(adapter_name) + 1 );
- strcpy( interfaceName, adapter_name );
-
- closeTcpFile( tcpFile );
- }
+ status = getInterfaceInfoByIndex( tcpFile, index, &ifInfo );
+
+ if( NT_SUCCESS(status) ) {
+ adapter_name = ifInfo.if_info.ent.if_descr;
+
+ interfaceName = HeapAlloc( GetProcessHeap(), 0,
+ strlen(adapter_name) + 1 );
+ strcpy( interfaceName, adapter_name );
+
+ closeTcpFile( tcpFile );
+ }
}
return interfaceName;
NTSTATUS status = openTcpFile( &tcpFile );
if( NT_SUCCESS(status) ) {
- status = getInterfaceInfoByName( tcpFile, (char *)name, &ifInfo );
-
- if( NT_SUCCESS(status) ) {
- *index = ifInfo.if_info.ent.if_index;
- closeTcpFile( tcpFile );
- }
+ status = getInterfaceInfoByName( tcpFile, (char *)name, &ifInfo );
+
+ if( NT_SUCCESS(status) ) {
+ *index = ifInfo.if_info.ent.if_index;
+ closeTcpFile( tcpFile );
+ }
}
return status;
status = getInterfaceInfoSet( tcpFile, &ifInfo, &numInterfaces );
if( NT_SUCCESS(status) ) {
- ret = (InterfaceIndexTable *)
- calloc(1,
- sizeof(InterfaceIndexTable) +
- (numInterfaces - 1) * sizeof(DWORD));
-
- if (ret) {
- ret->numAllocated = numInterfaces;
-
- for( i = 0; i < numInterfaces; i++ ) {
- if( !nonLoopbackOnly ||
- !isLoopback( tcpFile, &ifInfo[i].entity_id ) ) {
- ret->indexes[curInterface++] =
- ifInfo[i].if_info.ent.if_index;
- }
- }
-
- ret->numIndexes = curInterface;
- }
-
- tdiFreeThingSet( ifInfo );
+ ret = (InterfaceIndexTable *)
+ calloc(1,
+ sizeof(InterfaceIndexTable) +
+ (numInterfaces - 1) * sizeof(DWORD));
+
+ if (ret) {
+ ret->numAllocated = numInterfaces;
+
+ for( i = 0; i < numInterfaces; i++ ) {
+ if( !nonLoopbackOnly ||
+ !isLoopback( tcpFile, &ifInfo[i].entity_id ) ) {
+ ret->indexes[curInterface++] =
+ ifInfo[i].if_info.ent.if_index;
+ }
+ }
+
+ ret->numIndexes = curInterface;
+ }
+
+ tdiFreeThingSet( ifInfo );
}
closeTcpFile( tcpFile );
}
-
+
return ret;
}
}
NTSTATUS getIPAddrEntryForIf(HANDLE tcpFile,
- char *name,
- DWORD index,
- IFInfo *ifInfo) {
+ char *name,
+ DWORD index,
+ IFInfo *ifInfo) {
NTSTATUS status =
- name ?
- getInterfaceInfoByName( tcpFile, name, ifInfo ) :
- getInterfaceInfoByIndex( tcpFile, index, ifInfo );
+ name ?
+ getInterfaceInfoByName( tcpFile, name, ifInfo ) :
+ getInterfaceInfoByIndex( tcpFile, index, ifInfo );
return status;
}
status = openTcpFile( &tcpFile );
if( NT_SUCCESS(status) ) {
- status = getIPAddrEntryForIf( tcpFile, name, index, &ifInfo );
- if( NT_SUCCESS(status) ) {
- switch( addrType ) {
- case IPAAddr: addrOut = ifInfo.ip_addr.iae_addr; break;
- case IPABcast: addrOut = ifInfo.ip_addr.iae_bcastaddr; break;
- case IPAMask: addrOut = ifInfo.ip_addr.iae_mask; break;
- case IFMtu: addrOut = ifInfo.if_info.ent.if_mtu; break;
- case IFStatus: addrOut = ifInfo.if_info.ent.if_operstatus; break;
- }
- }
- closeTcpFile( &tcpFile );
+ status = getIPAddrEntryForIf( tcpFile, name, index, &ifInfo );
+ if( NT_SUCCESS(status) ) {
+ switch( addrType ) {
+ case IPAAddr: addrOut = ifInfo.ip_addr.iae_addr; break;
+ case IPABcast: addrOut = ifInfo.ip_addr.iae_bcastaddr; break;
+ case IPAMask: addrOut = ifInfo.ip_addr.iae_mask; break;
+ case IFMtu: addrOut = ifInfo.if_info.ent.if_mtu; break;
+ case IFStatus: addrOut = ifInfo.if_info.ent.if_operstatus; break;
+ }
+ }
+ closeTcpFile( &tcpFile );
}
return addrOut;
-}
+}
DWORD getInterfaceIPAddrByIndex(DWORD index) {
return getAddrByIndexOrName( 0, index, IPAAddr );
}
void getInterfacePhysicalFromInfo( IFInfo *info,
- PDWORD len, PBYTE addr, PDWORD type ) {
+ PDWORD len, PBYTE addr, PDWORD type ) {
*len = info->if_info.ent.if_physaddrlen;
memcpy( addr, info->if_info.ent.if_physaddr, *len );
*type = info->if_info.ent.if_type;
}
DWORD getInterfacePhysicalByName(const char *name, PDWORD len, PBYTE addr,
- PDWORD type)
+ PDWORD type)
{
HANDLE tcpFile;
IFInfo info;
NTSTATUS status = openTcpFile( &tcpFile );
if( NT_SUCCESS(status) ) {
- status = getInterfaceInfoByName( tcpFile, (char *)name, &info );
- if( NT_SUCCESS(status) )
- getInterfacePhysicalFromInfo( &info, len, addr, type );
- closeTcpFile( tcpFile );
+ status = getInterfaceInfoByName( tcpFile, (char *)name, &info );
+ if( NT_SUCCESS(status) )
+ getInterfacePhysicalFromInfo( &info, len, addr, type );
+ closeTcpFile( tcpFile );
}
return status;
NTSTATUS status = openTcpFile( &tcpFile );
if( NT_SUCCESS(status) ) {
- status = getInterfaceInfoByIndex( tcpFile, index, &info );
- if( NT_SUCCESS(status) )
- getInterfacePhysicalFromInfo( &info, len, addr, type );
- closeTcpFile( tcpFile );
+ status = getInterfaceInfoByIndex( tcpFile, index, &info );
+ if( NT_SUCCESS(status) )
+ getInterfacePhysicalFromInfo( &info, len, addr, type );
+ closeTcpFile( tcpFile );
}
return status;
DPRINT("Called.\n");
if( NT_SUCCESS(status) ) {
- status = getInterfaceInfoByName( tcpFile, (char *)name, &info );
-
- if( NT_SUCCESS(status) ) {
- memcpy( &entry->wszName[MAX_INTERFACE_NAME_LEN],
- &info.if_info,
- sizeof(info.if_info) );
- }
-
- closeTcpFile( tcpFile );
+ status = getInterfaceInfoByName( tcpFile, (char *)name, &info );
+
+ if( NT_SUCCESS(status) ) {
+ memcpy( &entry->wszName[MAX_INTERFACE_NAME_LEN],
+ &info.if_info,
+ sizeof(info.if_info) );
+ }
+
+ closeTcpFile( tcpFile );
}
return status;
DPRINT("Called.\n");
if( NT_SUCCESS(status) ) {
- status = getInterfaceInfoByIndex( tcpFile, index, &info );
-
- if( NT_SUCCESS(status) ) {
- memcpy( &entry->wszName[MAX_INTERFACE_NAME_LEN],
- &info.if_info,
- sizeof(info.if_info) );
- }
-
- closeTcpFile( tcpFile );
+ status = getInterfaceInfoByIndex( tcpFile, index, &info );
+
+ if( NT_SUCCESS(status) ) {
+ memcpy( &entry->wszName[MAX_INTERFACE_NAME_LEN],
+ &info.if_info,
+ sizeof(info.if_info) );
+ }
+
+ closeTcpFile( tcpFile );
}
return status;
HANDLE tcpFile = INVALID_HANDLE_VALUE;
NTSTATUS status = openTcpFile( &tcpFile );
TCP_REQUEST_SET_INFORMATION_EX_SAFELY_SIZED req =
- TCP_REQUEST_SET_INFORMATION_INIT;
+ TCP_REQUEST_SET_INFORMATION_INIT;
IPRouteEntry *rte;
TDIEntityID id;
DWORD returnSize = 0;
DPRINT("Called.\n");
if( NT_SUCCESS(status) )
- status = getNthIpEntity( tcpFile, 0, &id );
+ status = getNthIpEntity( tcpFile, 0, &id );
if( NT_SUCCESS(status) ) {
- req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
- req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
- req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
- req.Req.ID.toi_entity = id;
- req.Req.BufferSize = sizeof(*rte);
- rte =
- (IPRouteEntry *)&req.Req.Buffer[0];
-
- rte->ire_dest = pRoute->dwForwardDest;
- rte->ire_index = pRoute->dwForwardIfIndex;
- rte->ire_metric = pRoute->dwForwardMetric1;
- rte->ire_gw = pRoute->dwForwardNextHopAS;
- rte->ire_mask = pRoute->dwForwardMask;
-
- status = DeviceIoControl( tcpFile,
- IOCTL_TCP_SET_INFORMATION_EX,
- &req,
- sizeof(req),
- NULL,
- 0,
- &returnSize,
- NULL );
+ req.Req.ID.toi_class = INFO_CLASS_PROTOCOL;
+ req.Req.ID.toi_type = INFO_TYPE_PROVIDER;
+ req.Req.ID.toi_id = IP_MIB_ROUTETABLE_ENTRY_ID;
+ req.Req.ID.toi_entity = id;
+ req.Req.BufferSize = sizeof(*rte);
+ rte =
+ (IPRouteEntry *)&req.Req.Buffer[0];
+
+ rte->ire_dest = pRoute->dwForwardDest;
+ rte->ire_index = pRoute->dwForwardIfIndex;
+ rte->ire_metric = pRoute->dwForwardMetric1;
+ rte->ire_gw = pRoute->dwForwardNextHopAS;
+ rte->ire_mask = pRoute->dwForwardMask;
+
+ status = DeviceIoControl( tcpFile,
+ IOCTL_TCP_SET_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ NULL,
+ 0,
+ &returnSize,
+ NULL );
}
if( tcpFile != INVALID_HANDLE_VALUE )
- closeTcpFile( tcpFile );
+ closeTcpFile( tcpFile );
return status;
}
req.ID.toi_entity = *ent;
status =
- DeviceIoControl
- ( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- &entityType,
- sizeof(entityType),
- &returnedLen,
- NULL );
+ DeviceIoControl
+ ( tcpFile,
+ IOCTL_TCP_QUERY_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ &entityType,
+ sizeof(entityType),
+ &returnedLen,
+ NULL );
DPRINT("Ent: %04x:d -> %04x\n",
- ent->tei_entity, ent->tei_instance, entityType );
+ ent->tei_entity, ent->tei_instance, entityType );
return NT_SUCCESS(status) && entityType == CL_NL_IP;
}
int i;
if( !NT_SUCCESS(status) )
- return status;
+ return status;
for( i = 0; i < numEntities; i++ ) {
- if( isIpEntity( tcpFile, &entitySet[i] ) ) {
- DPRINT("Entity %d is an IP Entity\n", i);
- if( numRoutes == index ) break;
- else numRoutes++;
- }
+ if( isIpEntity( tcpFile, &entitySet[i] ) ) {
+ DPRINT("Entity %d is an IP Entity\n", i);
+ if( numRoutes == index ) break;
+ else numRoutes++;
+ }
}
if( numRoutes == index && i < numEntities ) {
- DPRINT("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;
+ DPRINT("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;
+ tdiFreeThingSet( entitySet );
+ return STATUS_UNSUCCESSFUL;
}
}
memset( entry, 0, sizeof( *entry ) );
DPRINT("TdiGetMibForIpEntity(tcpFile %x,entityId %x)\n",
- (DWORD)tcpFile, ent->tei_instance);
+ (DWORD)tcpFile, ent->tei_instance);
req.ID.toi_class = INFO_CLASS_PROTOCOL;
req.ID.toi_type = INFO_TYPE_PROVIDER;
req.ID.toi_entity = *ent;
status = DeviceIoControl( tcpFile,
- IOCTL_TCP_QUERY_INFORMATION_EX,
- &req,
- sizeof(req),
- entry,
- sizeof(*entry),
- &returnSize,
- NULL );
+ IOCTL_TCP_QUERY_INFORMATION_EX,
+ &req,
+ sizeof(req),
+ entry,
+ sizeof(*entry),
+ &returnSize,
+ NULL );
DPRINT("TdiGetMibForIpEntity() => {\n"
- " ipsi_forwarding ............ %d\n"
- " ipsi_defaultttl ............ %d\n"
- " ipsi_inreceives ............ %d\n"
- " ipsi_indelivers ............ %d\n"
- " ipsi_outrequests ........... %d\n"
- " ipsi_routingdiscards ....... %d\n"
- " ipsi_outdiscards ........... %d\n"
- " ipsi_outnoroutes ........... %d\n"
- " ipsi_numif ................. %d\n"
- " ipsi_numaddr ............... %d\n"
- " ipsi_numroutes ............. %d\n"
- "} status %08x\n",
- entry->ipsi_forwarding,
- entry->ipsi_defaultttl,
- entry->ipsi_inreceives,
- entry->ipsi_indelivers,
- entry->ipsi_outrequests,
- entry->ipsi_routingdiscards,
- entry->ipsi_outdiscards,
- entry->ipsi_outnoroutes,
- entry->ipsi_numif,
- entry->ipsi_numaddr,
- entry->ipsi_numroutes,
- status);
-
+ " ipsi_forwarding ............ %d\n"
+ " ipsi_defaultttl ............ %d\n"
+ " ipsi_inreceives ............ %d\n"
+ " ipsi_indelivers ............ %d\n"
+ " ipsi_outrequests ........... %d\n"
+ " ipsi_routingdiscards ....... %d\n"
+ " ipsi_outdiscards ........... %d\n"
+ " ipsi_outnoroutes ........... %d\n"
+ " ipsi_numif ................. %d\n"
+ " ipsi_numaddr ............... %d\n"
+ " ipsi_numroutes ............. %d\n"
+ "} status %08x\n",
+ entry->ipsi_forwarding,
+ entry->ipsi_defaultttl,
+ entry->ipsi_inreceives,
+ entry->ipsi_indelivers,
+ entry->ipsi_outrequests,
+ entry->ipsi_routingdiscards,
+ entry->ipsi_outdiscards,
+ entry->ipsi_outnoroutes,
+ entry->ipsi_numif,
+ entry->ipsi_numaddr,
+ entry->ipsi_numroutes,
+ status);
+
return status;
}
NTSTATUS status = STATUS_SUCCESS;
DPRINT("TdiGetRoutesForIpEntity(tcpFile %x,entityId %x)\n",
- (DWORD)tcpFile, ent->tei_instance);
+ (DWORD)tcpFile, ent->tei_instance);
status = tdiGetSetOfThings( tcpFile,
- INFO_CLASS_PROTOCOL,
- INFO_TYPE_PROVIDER,
- IP_MIB_ROUTETABLE_ENTRY_ID,
- ent->tei_entity,
- 0,
- sizeof(IPRouteEntry),
- (PVOID *)routes,
- numRoutes);
+ INFO_CLASS_PROTOCOL,
+ INFO_TYPE_PROVIDER,
+ IP_MIB_ROUTETABLE_ENTRY_ID,
+ ent->tei_entity,
+ 0,
+ sizeof(IPRouteEntry),
+ (PVOID *)routes,
+ numRoutes);
return status;
}
NTSTATUS status;
DPRINT("TdiGetIpAddrsForIpEntity(tcpFile %x,entityId %x)\n",
- (DWORD)tcpFile, ent->tei_instance);
+ (DWORD)tcpFile, ent->tei_instance);
status = tdiGetSetOfThings( tcpFile,
- INFO_CLASS_PROTOCOL,
- INFO_TYPE_PROVIDER,
- IP_MIB_ADDRTABLE_ENTRY_ID,
- ent->tei_entity,
- 0,
- sizeof(IPAddrEntry),
- (PVOID *)addrs,
- numAddrs );
+ INFO_CLASS_PROTOCOL,
+ INFO_TYPE_PROVIDER,
+ IP_MIB_ADDRTABLE_ENTRY_ID,
+ ent->tei_entity,
+ 0,
+ sizeof(IPAddrEntry),
+ (PVOID *)addrs,
+ numAddrs );
return status;
}
status = openTcpFile( &tcpFile );
if( !NT_SUCCESS(status) ) {
- TRACE("failure: %08x\n", (int)status );
- return 0;
+ TRACE("failure: %08x\n", (int)status );
+ return 0;
}
status = tdiGetEntityIDSet( tcpFile, &entitySet, &numEntities );
if( !NT_SUCCESS(status) ) {
- TRACE("failure: %08x\n", (int)status );
- return 0;
+ TRACE("failure: %08x\n", (int)status );
+ 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 );
- return status;
- }
- numRoutes += isnmp.ipsi_numroutes;
- }
+ if( isIpEntity( tcpFile, &entitySet[i] ) ) {
+ IPSNMPInfo isnmp;
+ memset( &isnmp, 0, sizeof( isnmp ) );
+ status = tdiGetMibForIpEntity( tcpFile, &entitySet[i], &isnmp );
+ if( !NT_SUCCESS(status) ) {
+ tdiFreeThingSet( entitySet );
+ return status;
+ }
+ numRoutes += isnmp.ipsi_numroutes;
+ }
}
TRACE("numRoutes: %d\n", (int)numRoutes);
int i;
for( i = 0; i < Len; i++ ) {
- if( !(i & 0xf) ) {
- if( i ) fprintf(stderr,"\n");
- fprintf(stderr,"%08x:", i);
- }
- fprintf( stderr, " %02x", Data[i] & 0xff );
+ if( !(i & 0xf) ) {
+ if( i ) fprintf(stderr,"\n");
+ fprintf(stderr,"%08x:", i);
+ }
+ fprintf( stderr, " %02x", Data[i] & 0xff );
}
fprintf(stderr,"\n");
}
int i;
if( !NT_SUCCESS(status) )
- return 0;
+ return 0;
out_route_table = HeapAlloc( GetProcessHeap(), 0,
- sizeof(RouteTable) +
- (sizeof(RouteEntry) * (numRoutes - 1)) );
+ sizeof(RouteTable) +
+ (sizeof(RouteEntry) * (numRoutes - 1)) );
out_route_table->numRoutes = numRoutes;
for( i = 0; routesAdded < numRoutes; i++ ) {
- int j;
- IPRouteEntry *route_set;
+ int j;
+ IPRouteEntry *route_set;
- getNthIpEntity( tcpFile, i, &ent );
- tdiGetMibForIpEntity( tcpFile, &ent, &snmpInfo );
+ getNthIpEntity( tcpFile, i, &ent );
+ tdiGetMibForIpEntity( tcpFile, &ent, &snmpInfo );
- DPRINT( "%d routes in instance %d\n", snmpInfo.ipsi_numroutes, i );
+ DPRINT( "%d routes in instance %d\n", snmpInfo.ipsi_numroutes, i );
- if( !route_set ) {
- closeTcpFile( tcpFile );
- HeapFree( GetProcessHeap(), 0, out_route_table );
- return 0;
- }
+ if( !route_set ) {
+ closeTcpFile( tcpFile );
+ HeapFree( GetProcessHeap(), 0, out_route_table );
+ return 0;
+ }
- tdiGetRoutesForIpEntity( tcpFile, &ent, &route_set, &numRoutes );
+ tdiGetRoutesForIpEntity( tcpFile, &ent, &route_set, &numRoutes );
- DPRINT("Route set returned\n");
+ DPRINT("Route set returned\n");
#if 0
- HexDump( route_set,
- sizeof( IPRouteEntry ) *
- snmpInfo.ipsi_numroutes );
+ HexDump( route_set,
+ sizeof( IPRouteEntry ) *
+ snmpInfo.ipsi_numroutes );
#endif
- for( j = 0; j < snmpInfo.ipsi_numroutes; j++ ) {
- int routeNum = j + routesAdded;
- out_route_table->routes[routeNum].dest =
- route_set[j].ire_dest;
- out_route_table->routes[routeNum].mask =
- route_set[j].ire_mask;
- out_route_table->routes[routeNum].gateway =
- route_set[j].ire_gw;
- out_route_table->routes[routeNum].ifIndex =
- route_set[j].ire_index;
- out_route_table->routes[routeNum].metric =
- route_set[j].ire_metric;
- }
-
- if( route_set ) tdiFreeThingSet( route_set );
-
- routesAdded += snmpInfo.ipsi_numroutes;
+ for( j = 0; j < snmpInfo.ipsi_numroutes; j++ ) {
+ int routeNum = j + routesAdded;
+ out_route_table->routes[routeNum].dest =
+ route_set[j].ire_dest;
+ out_route_table->routes[routeNum].mask =
+ route_set[j].ire_mask;
+ out_route_table->routes[routeNum].gateway =
+ route_set[j].ire_gw;
+ out_route_table->routes[routeNum].ifIndex =
+ route_set[j].ire_index;
+ out_route_table->routes[routeNum].metric =
+ route_set[j].ire_metric;
+ }
+
+ if( route_set ) tdiFreeThingSet( route_set );
+
+ routesAdded += snmpInfo.ipsi_numroutes;
}
return out_route_table;