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.

330 lines
9.8 KiB

  1. //=============================================================================
  2. // MODULE: cdp.c
  3. //
  4. // Description:
  5. //
  6. // Bloodhound Parser DLL for the Cluster Datagram Protocol
  7. //
  8. // Modification History
  9. //
  10. // Mike Massa 03/21/97 Created
  11. //=============================================================================
  12. #include "precomp.h"
  13. #pragma hdrstop
  14. //
  15. // Constants
  16. //
  17. //
  18. // Types
  19. //
  20. typedef struct {
  21. USHORT SourcePort;
  22. USHORT DestinationPort;
  23. USHORT PayloadLength;
  24. USHORT Checksum;
  25. } CDP_HEADER, *PCDP_HEADER;
  26. //
  27. // Data
  28. //
  29. //=============================================================================
  30. // Forward references.
  31. //=============================================================================
  32. VOID WINAPIV CdpFormatSummary(LPPROPERTYINST lpPropertyInst);
  33. //=============================================================================
  34. // CDP database.
  35. //=============================================================================
  36. #define CDP_SUMMARY 0
  37. #define CDP_SOURCE_PORT 1
  38. #define CDP_DESTINATION_PORT 2
  39. #define CDP_PAYLOAD_LENGTH 3
  40. #define CDP_RESERVED 4
  41. #define CDP_DATA 5
  42. PROPERTYINFO CdpDatabase[] =
  43. {
  44. { // CDP_SUMMARY 0
  45. 0,0,
  46. "Summary",
  47. "Summary of the CDP packet",
  48. PROP_TYPE_SUMMARY,
  49. PROP_QUAL_NONE,
  50. NULL,
  51. 132,
  52. CdpFormatSummary},
  53. { // CDP_SOURCE_PORT 1
  54. 0,0,
  55. "Source Port",
  56. "Endpoint from which the packet originated",
  57. PROP_TYPE_WORD,
  58. PROP_QUAL_NONE,
  59. NULL,
  60. 80,
  61. FormatPropertyInstance},
  62. { // CDP_DESTINATION_PORT 2
  63. 0,0,
  64. "Destination Port",
  65. "Endpoint for which the packet is destined",
  66. PROP_TYPE_WORD,
  67. PROP_QUAL_NONE,
  68. NULL,
  69. 80,
  70. FormatPropertyInstance},
  71. { // CDP_PAYLOAD_LENGTH 3
  72. 0,0,
  73. "Payload Length",
  74. "Number of data bytes carried by the packet",
  75. PROP_TYPE_WORD,
  76. PROP_QUAL_NONE,
  77. NULL,
  78. 80,
  79. FormatPropertyInstance},
  80. { // CDP_RESERVED 4
  81. 0,0,
  82. "Reserved",
  83. "Reserved field",
  84. PROP_TYPE_WORD,
  85. PROP_QUAL_NONE,
  86. NULL,
  87. 80,
  88. FormatPropertyInstance},
  89. { // CDP_DATA 5
  90. 0,0,
  91. "Data",
  92. "Amount of data in this datagram",
  93. PROP_TYPE_RAW_DATA,
  94. PROP_QUAL_NONE,
  95. NULL,
  96. 80,
  97. FormatPropertyInstance},
  98. };
  99. DWORD nCdpProperties = ((sizeof CdpDatabase) / PROPERTYINFO_SIZE);
  100. //=============================================================================
  101. // FUNCTION: CdpRegister()
  102. //
  103. // Modification History
  104. //
  105. // Steve Hiskey 07/07/94 Created
  106. //=============================================================================
  107. VOID WINAPI CdpRegister(HPROTOCOL hCdpProtocol)
  108. {
  109. register DWORD i;
  110. //=========================================================================
  111. // Create the property database.
  112. //=========================================================================
  113. CreatePropertyDatabase(hCdpProtocol, nCdpProperties);
  114. for(i = 0; i < nCdpProperties; ++i)
  115. {
  116. AddProperty(hCdpProtocol, &CdpDatabase[i]);
  117. }
  118. }
  119. //=============================================================================
  120. // FUNCTION: Deregister()
  121. //
  122. // Modification History
  123. //
  124. // Steve Hiskey 07/07/94 Created
  125. //=============================================================================
  126. VOID WINAPI CdpDeregister(HPROTOCOL hCdpProtocol)
  127. {
  128. DestroyPropertyDatabase(hCdpProtocol);
  129. }
  130. //=============================================================================
  131. // FUNCTION: CdpRecognizeFrame()
  132. //
  133. // Modification History
  134. //
  135. // Steve Hiskey 07/07/94 Created
  136. //=============================================================================
  137. LPBYTE WINAPI CdpRecognizeFrame(HFRAME hFrame, //... frame handle.
  138. LPBYTE MacFrame, //... Frame pointer.
  139. LPBYTE MyFrame, //... Relative pointer.
  140. DWORD MacType, //... MAC type.
  141. DWORD MyBytesLeft, //... Bytes left.
  142. HPROTOCOL hPreviousProtocol, //... Previous protocol or NULL if none.
  143. DWORD nPreviousProtocolOffset, //... Offset of previous protocol.
  144. LPDWORD ProtocolStatusCode, //... Pointer to return status code in.
  145. LPHPROTOCOL hNextProtocol, //... Next protocol to call (optional).
  146. LPDWORD InstData) //... Next protocol instance data.
  147. {
  148. CDP_HEADER UNALIGNED * cdpHeader = (CDP_HEADER UNALIGNED *) MyFrame;
  149. LPBYTE lpNextByte = (LPBYTE) (cdpHeader + 1);
  150. if (MyBytesLeft > sizeof(CDP_HEADER)) {
  151. MyBytesLeft -= sizeof(CDP_HEADER);
  152. if ( (cdpHeader->SourcePort == 1) ||
  153. (cdpHeader->DestinationPort == 1)
  154. )
  155. {
  156. //
  157. // This is a regroup packet.
  158. //
  159. *hNextProtocol = hRGP;
  160. *ProtocolStatusCode = PROTOCOL_STATUS_NEXT_PROTOCOL;
  161. }
  162. else {
  163. //
  164. // This is probably an RPC packet. Let the follow set
  165. // have it.
  166. //
  167. *hNextProtocol = NULL;
  168. *ProtocolStatusCode = PROTOCOL_STATUS_RECOGNIZED;
  169. }
  170. }
  171. else {
  172. *ProtocolStatusCode = PROTOCOL_STATUS_CLAIMED;
  173. }
  174. return lpNextByte;
  175. }
  176. //=============================================================================
  177. // FUNCTION: CdpAttachProperties()
  178. //
  179. // Modification History
  180. //
  181. // Steve Hiskey 07/07/94 Created
  182. //=============================================================================
  183. LPBYTE WINAPI CdpAttachProperties(HFRAME hFrame,
  184. LPBYTE Frame,
  185. LPBYTE MyFrame,
  186. DWORD MacType,
  187. DWORD BytesLeft,
  188. HPROTOCOL hPreviousProtocol,
  189. DWORD nPreviousProtocolOffset,
  190. DWORD InstData)
  191. {
  192. CDP_HEADER UNALIGNED * cdpHeader = (CDP_HEADER UNALIGNED *) MyFrame;
  193. AttachPropertyInstance(hFrame,
  194. CdpDatabase[CDP_SUMMARY].hProperty,
  195. sizeof(CDP_HEADER),
  196. cdpHeader,
  197. 0, 0, 0);
  198. AttachPropertyInstance(hFrame,
  199. CdpDatabase[CDP_SOURCE_PORT].hProperty,
  200. sizeof(WORD),
  201. &(cdpHeader->SourcePort),
  202. 0, 1, 0);
  203. AttachPropertyInstance(hFrame,
  204. CdpDatabase[CDP_DESTINATION_PORT].hProperty,
  205. sizeof(WORD),
  206. &(cdpHeader->DestinationPort),
  207. 0, 1, 0);
  208. AttachPropertyInstance(hFrame,
  209. CdpDatabase[CDP_PAYLOAD_LENGTH].hProperty,
  210. sizeof(WORD),
  211. &(cdpHeader->PayloadLength),
  212. 0, 1, 0);
  213. AttachPropertyInstance(hFrame,
  214. CdpDatabase[CDP_RESERVED].hProperty,
  215. sizeof(WORD),
  216. &(cdpHeader->Checksum),
  217. 0, 1, 0);
  218. AttachPropertyInstance(hFrame,
  219. CdpDatabase[CDP_DATA].hProperty,
  220. BytesLeft - sizeof(CDP_HEADER),
  221. (LPBYTE)cdpHeader + sizeof(CDP_HEADER),
  222. 0, 1, 0);
  223. return NULL;
  224. }
  225. //==============================================================================
  226. // FUNCTION: CdpFormatSummary()
  227. //
  228. // Modification History
  229. //
  230. // Steve Hiskey 07/07/94 Created
  231. //==============================================================================
  232. VOID WINAPIV CdpFormatSummary(LPPROPERTYINST lpPropertyInst)
  233. {
  234. LPSTR SummaryStr;
  235. DWORD Length;
  236. CDP_HEADER UNALIGNED * cdpHeader =
  237. (CDP_HEADER UNALIGNED *) lpPropertyInst->lpData;
  238. Length = wsprintf( lpPropertyInst->szPropertyText,
  239. "Src Port = %u; Dst Port = %u; Payload Length = %u",
  240. cdpHeader->SourcePort,
  241. cdpHeader->DestinationPort,
  242. cdpHeader->PayloadLength
  243. );
  244. }
  245. //==============================================================================
  246. // FUNCTION: CdpFormatProperties()
  247. //
  248. // Modification History
  249. //
  250. // Steve Hiskey 07/07/94 Created
  251. //==============================================================================
  252. DWORD WINAPI CdpFormatProperties(HFRAME hFrame,
  253. LPBYTE MacFrame,
  254. LPBYTE FrameData,
  255. DWORD nPropertyInsts,
  256. LPPROPERTYINST p)
  257. {
  258. //=========================================================================
  259. // Format each property in the property instance table.
  260. //
  261. // The property-specific instance data was used to store the address of a
  262. // property-specific formatting function so all we do here is call each
  263. // function via the instance data pointer.
  264. //=========================================================================
  265. while (nPropertyInsts--)
  266. {
  267. ((FORMAT) p->lpPropertyInfo->InstanceData)(p);
  268. p++;
  269. }
  270. return NMERR_SUCCESS;
  271. }