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.

249 lines
4.7 KiB

  1. /*++
  2. Copyright (c) 2001, Microsoft Corporation
  3. Module Name:
  4. cudpbcast.h
  5. Abstract:
  6. Declarations for CUdpBroadcastMapper -- support for mapping
  7. a public UDP port to the private network's broadcast address.
  8. Author:
  9. Jonathan Burstein (jonburs) 12 April 2001
  10. Revision History:
  11. --*/
  12. #pragma once
  13. #include <atlbase.h>
  14. extern CComModule _Module;
  15. #include <atlcom.h>
  16. #include "udpbcast.h"
  17. class CUdpBroadcast
  18. {
  19. public:
  20. LIST_ENTRY Link;
  21. USHORT usPublicPort;
  22. DWORD dwInterfaceIndex;
  23. ULONG ulDestinationAddress;
  24. HANDLE hDynamicRedirect;
  25. CUdpBroadcast(
  26. USHORT usPublicPort,
  27. DWORD dwInterfaceIndex,
  28. ULONG ulDestinationAddress
  29. )
  30. {
  31. InitializeListHead(&Link);
  32. this->usPublicPort = usPublicPort;
  33. this->dwInterfaceIndex = dwInterfaceIndex;
  34. this->ulDestinationAddress = ulDestinationAddress;
  35. hDynamicRedirect = NULL;
  36. };
  37. };
  38. class ATL_NO_VTABLE CUdpBroadcastMapper :
  39. public CComObjectRootEx<CComMultiThreadModel>,
  40. public IUdpBroadcastMapper
  41. {
  42. protected:
  43. //
  44. // The list of UDP Broadcast Mappings
  45. //
  46. LIST_ENTRY m_MappingList;
  47. //
  48. // Our UDP listening socket, to which the received
  49. // UDP packets on the public side will be redirected,
  50. // and the port of that socket
  51. //
  52. SOCKET m_hsUdpListen;
  53. USHORT m_usUdpListenPort;
  54. //
  55. // Our raw UDP socket, used to send the constructed
  56. // broadcast packet to the private network
  57. //
  58. SOCKET m_hsUdpRaw;
  59. //
  60. // Handle to the NAT
  61. //
  62. HANDLE m_hNat;
  63. //
  64. // Pointer to the NAT's component reference (needed
  65. // for asynch. socket routines
  66. //
  67. PCOMPONENT_REFERENCE m_pCompRef;
  68. //
  69. // Tracks whether or not we've been shutdown.
  70. //
  71. BOOL m_fActive;
  72. //
  73. // Tracks whether or not we've posted a read buffer.
  74. //
  75. BOOL m_fReadStarted;
  76. //
  77. // IP Identifier. This number has no intrinsic meaning --
  78. // it exists only so we don't send out ever packet w/
  79. // 0 in this field. Thread safety does not matter when
  80. //
  81. USHORT m_usIpId;
  82. public:
  83. BEGIN_COM_MAP(CUdpBroadcastMapper)
  84. COM_INTERFACE_ENTRY(IUdpBroadcastMapper)
  85. END_COM_MAP()
  86. DECLARE_PROTECT_FINAL_CONSTRUCT()
  87. //
  88. // Inline Constructor
  89. //
  90. CUdpBroadcastMapper()
  91. {
  92. InitializeListHead(&m_MappingList);
  93. m_hsUdpListen = INVALID_SOCKET;
  94. m_hsUdpRaw = INVALID_SOCKET;
  95. m_hNat = NULL;
  96. m_pCompRef = NULL;
  97. m_fActive = TRUE;
  98. m_fReadStarted = FALSE;
  99. m_usIpId = 0;
  100. };
  101. //
  102. // ATL Methods
  103. //
  104. HRESULT
  105. FinalConstruct();
  106. HRESULT
  107. FinalRelease();
  108. //
  109. // Initialization
  110. //
  111. HRESULT
  112. Initialize(
  113. PCOMPONENT_REFERENCE pComponentReference
  114. );
  115. //
  116. // IUdpBroadcastMapper methods
  117. //
  118. STDMETHODIMP
  119. CreateUdpBroadcastMapping(
  120. USHORT usPublicPort,
  121. DWORD dwPublicInterfaceIndex,
  122. ULONG ulDestinationAddress,
  123. VOID **ppvCookie
  124. );
  125. STDMETHODIMP
  126. CancelUdpBroadcastMapping(
  127. VOID *pvCookie
  128. );
  129. STDMETHODIMP
  130. Shutdown();
  131. protected:
  132. BOOL
  133. Active()
  134. {
  135. return m_fActive;
  136. };
  137. CUdpBroadcast*
  138. LookupMapping(
  139. USHORT usPublicPort,
  140. DWORD dwInterfaceIndex,
  141. PLIST_ENTRY *ppInsertionPoint
  142. );
  143. HRESULT
  144. StartUdpRead();
  145. static
  146. VOID
  147. UdpReadCompletionRoutine(
  148. ULONG ulError,
  149. ULONG ulBytesTransferred,
  150. PNH_BUFFER pBuffer
  151. );
  152. VOID
  153. ProcessUdpRead(
  154. ULONG ulError,
  155. ULONG ulBytesTransferred,
  156. PNH_BUFFER pBuffer
  157. );
  158. HRESULT
  159. BuildAndSendRawUdpPacket(
  160. ULONG ulDestinationAddress,
  161. USHORT usDestinationPort,
  162. PNH_BUFFER pPacketData
  163. );
  164. static
  165. VOID
  166. RawWriteCompletionRoutine(
  167. ULONG ulError,
  168. ULONG ulBytesTransferred,
  169. PNH_BUFFER pBuffer
  170. );
  171. };
  172. #include <packon.h>
  173. typedef struct _IP_HEADER {
  174. UCHAR VersionAndHeaderLength;
  175. UCHAR TypeOfService;
  176. USHORT TotalLength;
  177. USHORT Identification;
  178. USHORT OffsetAndFlags;
  179. UCHAR TimeToLive;
  180. UCHAR Protocol;
  181. USHORT Checksum;
  182. ULONG SourceAddress;
  183. ULONG DestinationAddress;
  184. } IP_HEADER, *PIP_HEADER;
  185. typedef struct _UDP_HEADER {
  186. USHORT SourcePort;
  187. USHORT DestinationPort;
  188. USHORT Length;
  189. USHORT Checksum;
  190. } UDP_HEADER, *PUDP_HEADER;
  191. #include <packoff.h>