ReactOS Fundraising Campaign 2012
 
€ 4,410 / € 30,000

Information | Donate

Home | Info | Community | Development | myReactOS | Contact Us

  1. Home
  2. Community
  3. Development
  4. myReactOS
  5. Fundraiser 2012

  1. Main Page
  2. Alphabetical List
  3. Data Structures
  4. Directories
  5. File List
  6. Data Fields
  7. Globals
  8. Related Pages

ReactOS Development > Doxygen

enum.c
Go to the documentation of this file.
00001 /*
00002  * COPYRIGHT:   See COPYING in the top level directory
00003  * PROJECT:     ReactOS TDI interface
00004  * FILE:        enum.c
00005  * PURPOSE:     TDI entity enumeration
00006  */
00007 
00008 #include "iphlpapi_private.h"
00009 #include "tdilib.h"
00010 
00011 /* A generic thing-getting function which interacts in the right way with
00012  * TDI.  This may seem oblique, but I'm using it to reduce code and hopefully
00013  * make this thing easier to debug.
00014  *
00015  * The things returned can be any of:
00016  *   TDIEntityID
00017  *   TDIObjectID
00018  *   IFEntry
00019  *   IPSNMPInfo
00020  *   IPAddrEntry
00021  *   IPInterfaceInfo
00022  */
00023 NTSTATUS tdiGetSetOfThings( HANDLE tcpFile,
00024                             DWORD toiClass,
00025                             DWORD toiType,
00026                             DWORD toiId,
00027                             DWORD teiEntity,
00028                 DWORD teiInstance,
00029                             DWORD fixedPart,
00030                             DWORD entrySize,
00031                             PVOID *tdiEntitySet,
00032                             PDWORD numEntries ) {
00033     TCP_REQUEST_QUERY_INFORMATION_EX req = TCP_REQUEST_QUERY_INFORMATION_INIT;
00034     PVOID entitySet = 0;
00035     NTSTATUS status = STATUS_SUCCESS;
00036     DWORD allocationSizeForEntityArray = entrySize * MAX_TDI_ENTITIES,
00037         arraySize = entrySize * MAX_TDI_ENTITIES;
00038 
00039     req.ID.toi_class                = toiClass;
00040     req.ID.toi_type                 = toiType;
00041     req.ID.toi_id                   = toiId;
00042     req.ID.toi_entity.tei_entity    = teiEntity;
00043     req.ID.toi_entity.tei_instance  = teiInstance;
00044 
00045     /* There's a subtle problem here...
00046      * If an interface is added at this exact instant, (as if by a PCMCIA
00047      * card insertion), the array will still not have enough entries after
00048      * have allocated it after the first DeviceIoControl call.
00049      *
00050      * We'll get around this by repeating until the number of interfaces
00051      * stabilizes.
00052      */
00053     do {
00054         status = DeviceIoControl( tcpFile,
00055                                   IOCTL_TCP_QUERY_INFORMATION_EX,
00056                                   &req,
00057                                   sizeof(req),
00058                                   0,
00059                                   0,
00060                                   &allocationSizeForEntityArray,
00061                                   NULL );
00062 
00063         if(!status)
00064         {
00065             return STATUS_UNSUCCESSFUL;
00066         }
00067 
00068         arraySize = allocationSizeForEntityArray;
00069         entitySet = HeapAlloc( GetProcessHeap(), 0, arraySize );
00070 
00071         if( !entitySet ) {
00072             status = STATUS_INSUFFICIENT_RESOURCES;
00073             return status;
00074         }
00075 
00076         status = DeviceIoControl( tcpFile,
00077                                   IOCTL_TCP_QUERY_INFORMATION_EX,
00078                                   &req,
00079                                   sizeof(req),
00080                                   entitySet,
00081                                   arraySize,
00082                                   &allocationSizeForEntityArray,
00083                                   NULL );
00084 
00085         /* This is why we have the loop -- we might have added an adapter */
00086         if( arraySize == allocationSizeForEntityArray )
00087             break;
00088 
00089         HeapFree( GetProcessHeap(), 0, entitySet );
00090         entitySet = 0;
00091 
00092         if(!status)
00093             return STATUS_UNSUCCESSFUL;
00094     } while( TRUE ); /* We break if the array we received was the size we
00095                       * expected.  Therefore, we got here because it wasn't */
00096 
00097     *numEntries = (arraySize - fixedPart) / entrySize;
00098     *tdiEntitySet = entitySet;
00099 
00100     return STATUS_SUCCESS;
00101 }
00102 
00103 VOID tdiFreeThingSet( PVOID things ) {
00104     HeapFree( GetProcessHeap(), 0, things );
00105 }
00106 
00107 NTSTATUS tdiGetEntityIDSet( HANDLE tcpFile,
00108                             TDIEntityID **entitySet,
00109                             PDWORD numEntities ) {
00110     NTSTATUS status = tdiGetSetOfThings( tcpFile,
00111                                          INFO_CLASS_GENERIC,
00112                                          INFO_TYPE_PROVIDER,
00113                                          ENTITY_LIST_ID,
00114                                          GENERIC_ENTITY,
00115                      0,
00116                                          0,
00117                                          sizeof(TDIEntityID),
00118                                          (PVOID *)entitySet,
00119                                          numEntities );
00120 
00121     return status;
00122 }
00123 

Generated on Sat May 26 2012 04:20:15 for ReactOS by doxygen 1.7.6.1

ReactOS is a registered trademark or a trademark of ReactOS Foundation in the United States and other countries.