Source code of Windows XP (NT5)
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

120 lines
2.9 KiB

  1. /*++
  2. Copyright (c) 1994 Microsoft Corporation
  3. Module Name:
  4. entity.c
  5. Abstract:
  6. This module contains functions to get the entity list from the TCP/IP
  7. device driver
  8. Contents:
  9. GetEntityList
  10. Author:
  11. Richard L Firth (rfirth) 20-May-1994
  12. Revision History:
  13. 20-May-1994 rfirth
  14. Created
  15. --*/
  16. #include "precomp.h"
  17. #pragma hdrstop
  18. /*******************************************************************************
  19. *
  20. * GetEntityList
  21. *
  22. * Allocates a buffer for, and retrieves, the list of entities supported by the
  23. * TCP/IP device driver
  24. *
  25. * ENTRY nothing
  26. *
  27. * EXIT EntityCount - number of entities in the buffer
  28. *
  29. * RETURNS Success - pointer to allocated buffer containing list of entities
  30. * Failure - NULL
  31. *
  32. * ASSUMES
  33. *
  34. ******************************************************************************/
  35. TDIEntityID* GetEntityList(UINT* EntityCount) {
  36. TCP_REQUEST_QUERY_INFORMATION_EX req;
  37. DWORD status;
  38. DWORD inputLen;
  39. DWORD outputLen;
  40. LPVOID buffer = NULL;
  41. TDIEntityID* pEntity = NULL;
  42. memset(&req, 0, sizeof(req));
  43. req.ID.toi_entity.tei_entity = GENERIC_ENTITY;
  44. req.ID.toi_entity.tei_instance = 0;
  45. req.ID.toi_class = INFO_CLASS_GENERIC;
  46. req.ID.toi_type = INFO_TYPE_PROVIDER;
  47. req.ID.toi_id = ENTITY_LIST_ID;
  48. inputLen = sizeof(req);
  49. outputLen = sizeof(TDIEntityID) * DEFAULT_MINIMUM_ENTITIES;
  50. //
  51. // this is over-engineered - its very unlikely that we'll ever get >32
  52. // entities returned, never mind >64K's worth
  53. //
  54. do {
  55. DWORD previousOutputLen;
  56. previousOutputLen = outputLen;
  57. if (pEntity) {
  58. ReleaseMemory((void*)pEntity);
  59. }
  60. pEntity = (TDIEntityID*)NEW_MEMORY((size_t)outputLen);
  61. if (!pEntity) {
  62. DEBUG_PRINT(("GetEntityList: failed to allocate entity buffer (%ld bytes)\n",
  63. outputLen
  64. ));
  65. return NULL;
  66. }
  67. status = WsControl(IPPROTO_TCP,
  68. WSCNTL_TCPIP_QUERY_INFO,
  69. (LPVOID)&req,
  70. &inputLen,
  71. (LPVOID)pEntity,
  72. &outputLen
  73. );
  74. if (status == NO_ERROR) {
  75. break;
  76. } else if (status == ERROR_INSUFFICIENT_BUFFER) {
  77. outputLen = previousOutputLen +
  78. sizeof(TDIEntityID) * DEFAULT_MINIMUM_ENTITIES;
  79. } else {
  80. DEBUG_PRINT(("GetEntityList: WsControl(GENERIC_ENTITY) returns %ld, outputLen = %ld\n",
  81. status,
  82. outputLen
  83. ));
  84. ReleaseMemory((void*)pEntity);
  85. return NULL;
  86. }
  87. } while ( TRUE );
  88. DEBUG_PRINT(("%d entities returned\n", (outputLen / sizeof(TDIEntityID))));
  89. *EntityCount = (UINT)(outputLen / sizeof(TDIEntityID));
  90. return pEntity;
  91. }