Leaked source code of windows server 2003
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.

119 lines
3.0 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. TDIEntityID* pEntity = NULL;
  41. memset(&req, 0, sizeof(req));
  42. req.ID.toi_entity.tei_entity = GENERIC_ENTITY;
  43. req.ID.toi_entity.tei_instance = 0;
  44. req.ID.toi_class = INFO_CLASS_GENERIC;
  45. req.ID.toi_type = INFO_TYPE_PROVIDER;
  46. req.ID.toi_id = ENTITY_LIST_ID;
  47. inputLen = sizeof(req);
  48. outputLen = sizeof(TDIEntityID) * DEFAULT_MINIMUM_ENTITIES;
  49. //
  50. // this is over-engineered - its very unlikely that we'll ever get >32
  51. // entities returned, never mind >64K's worth
  52. //
  53. for (;;) {
  54. DWORD previousOutputLen;
  55. previousOutputLen = outputLen;
  56. if (pEntity) {
  57. ReleaseMemory((void*)pEntity);
  58. }
  59. pEntity = (TDIEntityID*)NEW_MEMORY((size_t)outputLen);
  60. if (!pEntity) {
  61. DEBUG_PRINT(("GetEntityList: failed to allocate entity buffer (%ld bytes)\n",
  62. outputLen
  63. ));
  64. return NULL;
  65. }
  66. status = WsControl(IPPROTO_TCP,
  67. WSCNTL_TCPIP_QUERY_INFO,
  68. (LPVOID)&req,
  69. &inputLen,
  70. (LPVOID)pEntity,
  71. &outputLen
  72. );
  73. if (status == NO_ERROR) {
  74. break;
  75. } else if (status == ERROR_INSUFFICIENT_BUFFER) {
  76. outputLen = previousOutputLen +
  77. sizeof(TDIEntityID) * DEFAULT_MINIMUM_ENTITIES;
  78. } else {
  79. DEBUG_PRINT(("GetEntityList: WsControl(GENERIC_ENTITY) returns %ld, outputLen = %ld\n",
  80. status,
  81. outputLen
  82. ));
  83. ReleaseMemory((void*)pEntity);
  84. return NULL;
  85. }
  86. }
  87. DEBUG_PRINT(("%d entities returned\n", (outputLen / sizeof(TDIEntityID))));
  88. *EntityCount = (UINT)(outputLen / sizeof(TDIEntityID));
  89. return pEntity;
  90. }