2 * COPYRIGHT: See COPYING in the top level directory
3 * PROJECT: ReactOS TDI interface
5 * PURPOSE: TDI entity enumeration
8 #include "iphlpapi_private.h"
11 /* A generic thing-getting function which interacts in the right way with
12 * TDI. This may seem oblique, but I'm using it to reduce code and hopefully
13 * make this thing easier to debug.
15 * The things returned can be any of:
23 NTSTATUS
tdiGetSetOfThings( HANDLE tcpFile
,
33 TCP_REQUEST_QUERY_INFORMATION_EX req
= TCP_REQUEST_QUERY_INFORMATION_INIT
;
35 NTSTATUS status
= STATUS_SUCCESS
;
36 DWORD allocationSizeForEntityArray
= entrySize
* MAX_TDI_ENTITIES
,
37 arraySize
= entrySize
* MAX_TDI_ENTITIES
;
39 req
.ID
.toi_class
= toiClass
;
40 req
.ID
.toi_type
= toiType
;
41 req
.ID
.toi_id
= toiId
;
42 req
.ID
.toi_entity
.tei_entity
= teiEntity
;
43 req
.ID
.toi_entity
.tei_instance
= teiInstance
;
45 /* There's a subtle problem here...
46 * If an interface is added at this exact instant, (as if by a PCMCIA
47 * card insertion), the array will still not have enough entries after
48 * have allocated it after the first DeviceIoControl call.
50 * We'll get around this by repeating until the number of interfaces
54 status
= DeviceIoControl( tcpFile
,
55 IOCTL_TCP_QUERY_INFORMATION_EX
,
60 &allocationSizeForEntityArray
,
65 return STATUS_UNSUCCESSFUL
;
68 arraySize
= allocationSizeForEntityArray
;
69 entitySet
= HeapAlloc( GetProcessHeap(), 0, arraySize
);
72 status
= STATUS_INSUFFICIENT_RESOURCES
;
76 status
= DeviceIoControl( tcpFile
,
77 IOCTL_TCP_QUERY_INFORMATION_EX
,
82 &allocationSizeForEntityArray
,
85 /* This is why we have the loop -- we might have added an adapter */
86 if( arraySize
== allocationSizeForEntityArray
)
89 HeapFree( GetProcessHeap(), 0, entitySet
);
93 return STATUS_UNSUCCESSFUL
;
94 } while( TRUE
); /* We break if the array we received was the size we
95 * expected. Therefore, we got here because it wasn't */
97 *numEntries
= (arraySize
- fixedPart
) / entrySize
;
98 *tdiEntitySet
= entitySet
;
100 return STATUS_SUCCESS
;
103 VOID
tdiFreeThingSet( PVOID things
) {
104 HeapFree( GetProcessHeap(), 0, things
);
107 NTSTATUS
tdiGetEntityIDSet( HANDLE tcpFile
,
108 TDIEntityID
**entitySet
,
109 PDWORD numEntities
) {
110 NTSTATUS status
= tdiGetSetOfThings( tcpFile
,