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.

211 lines
5.2 KiB

  1. /*++
  2. Copyright (c) 1997-1999 Microsoft Corporation
  3. Module Name:
  4. addrgen.cpp
  5. Abstract:
  6. This module provides the definitions for the PORT allocation and release APIs.
  7. (Address allocation stuff removed by ZoltanS 6-1-98.)
  8. Author:
  9. B. Rajeev (rajeevb) 17-mar-1997
  10. Revision History:
  11. --*/
  12. #include "stdafx.h"
  13. #include <windows.h>
  14. #include <wtypes.h>
  15. #include <winsock2.h>
  16. #include "addrgen.h"
  17. #include "blbdbg.h"
  18. extern "C"
  19. {
  20. #include <wincrypt.h>
  21. #include <sclogon.h>
  22. #include <dhcpcapi.h>
  23. }
  24. // these constants represent the port range for corresponding media
  25. const WORD BASE_AUDIO_PORT = 16384;
  26. const WORD AUDIO_PORT_MASK = 0x3fff;
  27. const WORD BASE_WHITEBOARD_PORT = 32768;
  28. const WORD WHITEBOARD_PORT_MASK = 0x3fff;
  29. const WORD BASE_VIDEO_PORT = 49152;
  30. const WORD VIDEO_PORT_MASK = 0x3ffe;
  31. /*++
  32. Routine Description:
  33. This routine is used to reserve as well as renew local ports.
  34. Arguments:
  35. lpScope - Supplies a pointer to structure describing the port group.
  36. IsRenewal - Supplies a boolean value that describes whether the allocation call
  37. is a renewal attempt or a new allocation request.
  38. NumberOfPorts - Supplies the number of ports requested.
  39. lpFirstPort - Supplies the first port to be renewed in case of renewal
  40. (strictly an IN parameter).
  41. Returns the first port allocated otherwise
  42. (strictly an OUT parameter).
  43. Return Value:
  44. BOOL - TRUE if successful, FALSE otherwise. Further error information can be obtained by
  45. calling GetLastError(). These error codes are -
  46. NO_ERROR - The call was successful.
  47. MSA_INVALID_PORT_GROUP - The port group information is invalid (either if the PortType is
  48. invalid or the port range is unacceptable)
  49. MSA_RENEWAL_FAILED - System unable to renew the given ports.
  50. ERROR_INVALID_PARAMETER - One or more parameters is invalid.
  51. MSA_INVALID_DATA - One or more parameters has an invalid value.
  52. Remarks:
  53. All values are in host byte order
  54. --*/
  55. ADDRGEN_LIB_API BOOL WINAPI
  56. MSAAllocatePorts(
  57. IN LPMSA_PORT_GROUP lpPortGroup,
  58. IN BOOL IsRenewal,
  59. IN WORD NumberOfPorts,
  60. IN OUT LPWORD lpFirstPort
  61. )
  62. {
  63. // check if parameters are valid
  64. // if lpPortGroup or lpFirstPort is NULL - fail
  65. if ( (NULL == lpPortGroup) ||
  66. (NULL == lpFirstPort) )
  67. {
  68. SetLastError(ERROR_INVALID_PARAMETER);
  69. return FALSE;
  70. }
  71. // check if renewal - fail
  72. if ( IsRenewal )
  73. {
  74. SetLastError(MSA_INVALID_DATA);
  75. return FALSE;
  76. }
  77. //
  78. // PREFIXBUG 49741, 49742 - VLADE
  79. // We should initialize the variables
  80. //
  81. WORD BasePort = 0;
  82. WORD Mask = 0;
  83. // determine port range
  84. switch(lpPortGroup->PortType)
  85. {
  86. case AUDIO_PORT:
  87. {
  88. BasePort = BASE_AUDIO_PORT;
  89. Mask = AUDIO_PORT_MASK;
  90. }
  91. break;
  92. case WHITEBOARD_PORT:
  93. {
  94. BasePort = BASE_WHITEBOARD_PORT;
  95. Mask = WHITEBOARD_PORT_MASK;
  96. }
  97. break;
  98. case VIDEO_PORT:
  99. {
  100. BasePort = BASE_VIDEO_PORT;
  101. Mask = VIDEO_PORT_MASK;
  102. }
  103. break;
  104. case OTHER_PORT:
  105. {
  106. WORD StartPort;
  107. WORD EndPort;
  108. }
  109. break;
  110. default:
  111. {
  112. SetLastError(MSA_INVALID_PORT_GROUP);
  113. return FALSE;
  114. }
  115. };
  116. // if the desired number of ports are more than the range allows
  117. if ( NumberOfPorts > Mask )
  118. {
  119. SetLastError(MSA_NOT_AVAILABLE);
  120. return FALSE;
  121. }
  122. // choose random port in the range as the start
  123. *lpFirstPort = BasePort + (rand() & (Mask - NumberOfPorts));
  124. SetLastError(NO_ERROR);
  125. return TRUE;
  126. }
  127. /*++
  128. Routine Description:
  129. This routine is used to release previously allocated multicast ports.
  130. Arguments:
  131. NumberOfPorts - Supplies the number of ports to be released.
  132. StartPort - Supplies the starting port of the port range to be released.
  133. Return Value:
  134. BOOL - TRUE if successful, FALSE otherwise. Further error information can be obtained by
  135. calling GetLastError(). These error codes are -
  136. NO_ERROR - The call was successful.
  137. MSA_NO_SUCH_RESERVATION - There is no such reservation.
  138. ERROR_INVALID_PARAMETER - One or more parameters is invalid.
  139. MSA_INVALID_DATA - One or more parameters has an invalid value.
  140. Remarks:
  141. if range [a..c] is reserved and the release is attempted on [a..d], the call fails with
  142. MSA_NO_SUCH_RESERVATION without releasing [a..c].
  143. All values are in host byte order
  144. ++*/
  145. ADDRGEN_LIB_API BOOL WINAPI
  146. MSAReleasePorts(
  147. IN WORD NumberOfPorts,
  148. IN WORD StartPort
  149. )
  150. {
  151. return TRUE;
  152. }