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.

301 lines
7.4 KiB

  1. /*++
  2. Copyright (c) 1999-2000 Microsoft Corporation
  3. Module Name:
  4. tcpdump.c
  5. Abstract:
  6. Contains macros for dumping object members.
  7. Author:
  8. Scott Holden (sholden) 24-Apr-1999
  9. Revision History:
  10. --*/
  11. #ifndef _TCPDUMP_H_
  12. #define _TCPDUMP_H_
  13. #define printx dprintf
  14. #define TAB "\t"
  15. #define ENDL "\n"
  16. typedef struct
  17. {
  18. ULONG Value;
  19. PCHAR pszDescription;
  20. } ENUM_INFO, *PENUM_INFO, FLAG_INFO, *PFLAG_INFO;
  21. extern VOID DumpIPAddr(IPAddr Address);
  22. extern VOID DumpPtrSymbol(PVOID pvSymbol);
  23. extern VOID DumpFlags(ULONG flags, PFLAG_INFO pFlagInfo);
  24. extern VOID DumpEnum(ULONG Value, PENUM_INFO pEnumInfo);
  25. extern FLAG_INFO FlagsTsr[];
  26. extern FLAG_INFO FlagsLLIPBindInfo[];
  27. extern FLAG_INFO FlagsTCPConn[];
  28. extern FLAG_INFO FlagsNTE[];
  29. extern FLAG_INFO FlagsIF[];
  30. extern FLAG_INFO FlagsRCE[];
  31. extern FLAG_INFO FlagsRTE[];
  32. extern FLAG_INFO FlagsTcb[];
  33. extern FLAG_INFO FlagsTCPHeader[];
  34. extern FLAG_INFO FlagsFastChk[];
  35. extern FLAG_INFO FlagsAO[];
  36. extern ENUM_INFO StateTcb[];
  37. extern ENUM_INFO CloseReason[];
  38. extern ENUM_INFO FsContext2[];
  39. extern ENUM_INFO Prot[];
  40. extern ENUM_INFO NdisMediumsEnum[];
  41. extern ENUM_INFO AteState[];
  42. //
  43. // Manipulate indentations.
  44. //
  45. extern int _Indent;
  46. extern char IndentBuf[ 80 ];
  47. #define IndentChange(cch) { IndentBuf[_Indent]=' '; _Indent += (cch); IndentBuf[_Indent]='\0';}
  48. #define Indent(cch) IndentChange(cch)
  49. #define Outdent(cch) IndentChange(-(cch))
  50. //
  51. //
  52. //
  53. #define ENDL "\n"
  54. //
  55. //
  56. //
  57. _inline BOOL
  58. InitTcpipx()
  59. {
  60. memset(IndentBuf, ' ', 80);
  61. IndentBuf[0] = 0;
  62. _Indent = 0;
  63. return (TRUE);
  64. }
  65. //
  66. // Starting/Ending structures.
  67. //
  68. #define PrintStartStruct() \
  69. { printx( "%s{\n", IndentBuf ); Indent(2); }
  70. #define PrintStartNamedStruct( _name, _addr ) \
  71. { printx( "%s%s @ %x {\n", IndentBuf, #_name, _addr ); Indent(2); }
  72. #define PrintEndStruct() \
  73. { Outdent(2); dprintf( "%s}\n", IndentBuf ); }
  74. #define PrintIndent() printx("%s", IndentBuf);
  75. _inline VOID PrintFieldNameX(CHAR *pszFieldName, char *p)
  76. {
  77. if (strlen(pszFieldName) > 35)
  78. {
  79. printx("%s%-.25s..%s %s ",
  80. IndentBuf,
  81. pszFieldName,
  82. &(pszFieldName[strlen(pszFieldName)-8]),
  83. p);
  84. }
  85. else
  86. {
  87. printx("%s%-35.35s %s ", IndentBuf, pszFieldName, p);
  88. }
  89. }
  90. #define PrintFieldName(_fn) PrintFieldNameX(_fn, "=")
  91. #define PrintFieldNameAt(_fn) PrintFieldNameX(_fn, "@")
  92. //
  93. // Real structures.
  94. // _p - Pointer to the structure.
  95. // _f - field in the structure.
  96. //
  97. #define Print_BOOLEAN(_p, _f) \
  98. PrintFieldName(#_f); \
  99. printx("%-10s" ENDL, _p->_f == TRUE ? "TRUE" : "FALSE")
  100. #define Print_uint(_p, _f) \
  101. PrintFieldName(#_f); \
  102. printx("%-10lu" ENDL, _p->_f);
  103. #define Print_uinthex(_p, _f) \
  104. PrintFieldName(#_f); \
  105. printx("0x%08lx" ENDL, _p->_f)
  106. #define Print_ULONG(_p, _f) Print_uint(_p, _f)
  107. #define Print_ulong(_p, _f) Print_uint(_p, _f)
  108. #define Print_ULONGhex(_p, _f) Print_uinthex(_p, _f)
  109. #define Print_int(_p, _f) \
  110. PrintFieldName(#_f); \
  111. printx("%-10d" ENDL, _p->_f);
  112. #define Print_long(_p, _f) Print_int(_p, _f)
  113. #define Print_ulonghton(_p, _f) \
  114. PrintFieldName(#_f); \
  115. printx("%-10lu" ENDL, net_long(_p->_f));
  116. #define Print_SeqNum(_p, _f) Print_ulonghton(_p, _f)
  117. #define Print_short(_p, _f) \
  118. PrintFieldName(#_f); \
  119. printx("%-10hd" ENDL, _p->_f);
  120. #define Print_ushort(_p, _f) \
  121. PrintFieldName(#_f); \
  122. printx("%-10hu" ENDL, _p->_f);
  123. #define Print_USHORT Print_ushort
  124. #define Print_ushorthex(_p, _f) \
  125. PrintFieldName(#_f); \
  126. printx("0x%04lx" ENDL, _p->_f)
  127. #define Print_ushorthton(_p, _f) \
  128. PrintFieldName(#_f); \
  129. printx("%-10hu" ENDL, net_short(_p->_f));
  130. #define Print_port(_p, _f) Print_ushorthton(_p, _f)
  131. #define Print_uchar(_p, _f) \
  132. PrintFieldName(#_f); \
  133. printx("%-10lu" ENDL, (uint) _p->_f);
  134. #define Print_ucharhex(_p, _f) \
  135. PrintFieldName(#_f); \
  136. printx("0x%08lx" ENDL, (ULONG) _p->_f)
  137. #define Print_ptr(_p, _f) \
  138. PrintFieldName(#_f); \
  139. printx("%-10lx" ENDL, _p->_f)
  140. #define Print_UINT_PTR Print_ptr
  141. #define Print_ULONG_PTR Print_ptr
  142. #define Print_addr(_p, _f, _t, _a) \
  143. PrintFieldNameAt(#_f); \
  144. printx("%-10lx" ENDL, (_a + FIELD_OFFSET(_t, _f)))
  145. #define Print_Lock(_p, _f) \
  146. PrintFieldName(#_f); \
  147. printx("( 0x%08lx ) %-10s" ENDL, _p->_f, (_p->_f != 0) ? "Locked" : "UnLocked")
  148. #define Print_CTELock Print_Lock
  149. #define Print_SL(_p, _f) \
  150. PrintFieldName(#_f##".Next"); \
  151. printx("%-10lx" ENDL, _p->_f.Next)
  152. #define Print_LL(_p, _f) \
  153. PrintFieldName(#_f); \
  154. printx("Flink = %-10lx", _p->_f.Flink); \
  155. printx("Blink = %-10lx", _p->_f.Blink); \
  156. printx("%s", (_p->_f.Flink == &_p->_f) ? "[Empty]" : ""); \
  157. printx(ENDL)
  158. #define Print_Queue(_p, _f) \
  159. PrintFieldName(#_f); \
  160. printx("q_next = %-10lx", _p->_f.q_next); \
  161. printx("q_prev = %-10lx", _p->_f.q_prev); \
  162. printx("%s", (_p->_f.q_next == &_p->_f) ? "[Empty]" : ""); \
  163. printx(ENDL)
  164. #define Print_IPAddr(_p, _f) \
  165. PrintFieldName(#_f); \
  166. DumpIPAddr(_p->_f); \
  167. printx(ENDL)
  168. #define Print_IPMask(_p, _f) Print_IPAddr(_p, _f)
  169. #define Print_PtrSymbol(_p, _f) \
  170. PrintFieldName(#_f); \
  171. DumpPtrSymbol(_p->_f); \
  172. printx(ENDL)
  173. #define Print_flags(_p, _f, _pfs) \
  174. PrintFieldName(#_f); \
  175. printx("0x%08lx (", (ULONG)_p->_f); \
  176. DumpFlags(_p->_f, _pfs); \
  177. printx(")" ENDL)
  178. #define Print_enum(_p, _f, _pes) \
  179. PrintFieldName(#_f); \
  180. printx("0x%08lx (",(ULONG) _p->_f); \
  181. DumpEnum((ULONG)_p->_f, _pes); \
  182. printx(")" ENDL)
  183. #define EXPAND_TAG(_Tag) ((CHAR *)(&_Tag))[0], \
  184. ((CHAR *)(&_Tag))[1], \
  185. ((CHAR *)(&_Tag))[2], \
  186. ((CHAR *)(&_Tag))[3]
  187. #define Print_sig(_p, _f) \
  188. PrintFieldName(#_f); \
  189. printx("%c%c%c%c" ENDL, \
  190. EXPAND_TAG(_p->_f))
  191. #define Print_Tag Print_sig
  192. #define Print_CTEEvent(_p, _f) \
  193. PrintFieldName(#_f); \
  194. DumpCTEEvent(&_p->_f)
  195. #define Print_KEVENT(_p, _f) \
  196. PrintFieldName(#_f); \
  197. DumpKEVENT(&_p->_f)
  198. #define Print_CTETimer(_p, _f) \
  199. PrintFieldName(#_f); \
  200. DumpCTETimer(&_p->_f)
  201. #define Print_CTEBlockStruc(_p, _f) \
  202. PrintFieldName(#_f); \
  203. DumpCTEBlockStruc(&_p->_f)
  204. #define Print_WORK_QUEUE_ITEM(_p, _f) \
  205. PrintFieldName(#_f); \
  206. DumpWORK_QUEUE_ITEM(&_p->_f)
  207. #define Print_IPOptInfo(_p, _f, _t, _a) \
  208. PrintFieldName(#_f); \
  209. DumpIPOptInfo(&_p->_f, _a + FIELD_OFFSET(_t, _f), verb)
  210. #define Print_SHARE_ACCESS(_p, _f) \
  211. PrintFieldName(#_f); \
  212. DumpSHARE_ACCESS(&_p->_f)
  213. #define Print_NDIS_STRING(_p, _f) \
  214. PrintFieldName(#_f); \
  215. DumpNDIS_STRING(&_p->_f)
  216. #define Print_UNICODE_STRING Print_NDIS_STRING
  217. #define EXPAND_HWADDR(_hwAddr) ((uchar *)(&_hwAddr))[0], \
  218. ((uchar *)(&_hwAddr))[1], \
  219. ((uchar *)(&_hwAddr))[2], \
  220. ((uchar *)(&_hwAddr))[3], \
  221. ((uchar *)(&_hwAddr))[4], \
  222. ((uchar *)(&_hwAddr))[5]
  223. #define Print_hwaddr(_p, _f) \
  224. PrintFieldName(#_f); \
  225. printx("%2.2x-%2.2x-%2.2x-%2.2x-%2.2x-%2.2x" ENDL, \
  226. EXPAND_HWADDR(_p->_f))
  227. #endif // _TCPDUMP_H_