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.

213 lines
4.3 KiB

  1. /*++
  2. Copyright (c) 1995 Microsoft Corporation
  3. Module Name:
  4. ripdbg.c
  5. Abstract:
  6. The debug functions
  7. Author:
  8. Stefan Solomon 03/22/1995
  9. Revision History:
  10. --*/
  11. #include "precomp.h"
  12. #pragma hdrstop
  13. //*** TRACE ID FOR RIP ***
  14. DWORD RipTraceID=INVALID_TRACEID;
  15. HANDLE RipEventLogHdl=NULL;
  16. DWORD RipEventLogMask=0;
  17. //*** Functions for Debug Printing ***
  18. #if DBG
  19. HANDLE DbgLogFileHandle;
  20. DWORD DebugLog = 1;
  21. DWORD DbgLevel = DEFAULT_DEBUG_LEVEL;
  22. VOID
  23. SsDbgInitialize(VOID)
  24. {
  25. if (DebugLog == 1) {
  26. CONSOLE_SCREEN_BUFFER_INFO csbi;
  27. COORD coord;
  28. (VOID)AllocConsole( );
  29. (VOID)GetConsoleScreenBufferInfo(
  30. GetStdHandle(STD_OUTPUT_HANDLE),
  31. &csbi
  32. );
  33. coord.X = (SHORT)(csbi.srWindow.Right - csbi.srWindow.Left + 1);
  34. coord.Y = (SHORT)((csbi.srWindow.Bottom - csbi.srWindow.Top + 1) * 20);
  35. (VOID)SetConsoleScreenBufferSize(
  36. GetStdHandle(STD_OUTPUT_HANDLE),
  37. coord
  38. );
  39. }
  40. if(DebugLog > 1) {
  41. DbgLogFileHandle = CreateFile("\\ipxrtdbg.log",
  42. GENERIC_READ | GENERIC_WRITE,
  43. FILE_SHARE_READ,
  44. NULL,
  45. CREATE_ALWAYS,
  46. 0,
  47. NULL);
  48. }
  49. }
  50. VOID
  51. SsAssert(
  52. IN PVOID FailedAssertion,
  53. IN PVOID FileName,
  54. IN ULONG LineNumber
  55. )
  56. {
  57. Trace(RIP_ALERT, "\nAssertion failed: %s\n at line %ld of %s\n",
  58. FailedAssertion, LineNumber, FileName);
  59. DbgUserBreakPoint( );
  60. } // SsAssert
  61. #endif
  62. #if DBG
  63. VOID
  64. SsPrintf (
  65. char *Format,
  66. ...
  67. )
  68. {
  69. va_list arglist;
  70. char OutputBuffer[1024];
  71. ULONG length;
  72. va_start( arglist, Format );
  73. vsprintf( OutputBuffer, Format, arglist );
  74. va_end( arglist );
  75. length = strlen( OutputBuffer );
  76. WriteFile( GetStdHandle(STD_OUTPUT_HANDLE), (LPVOID )OutputBuffer, length, &length, NULL );
  77. if(DbgLogFileHandle != INVALID_HANDLE_VALUE) {
  78. WriteFile(DbgLogFileHandle, (LPVOID )OutputBuffer, length, &length, NULL );
  79. }
  80. } // SsPrintf
  81. #endif
  82. #if DBG
  83. VOID
  84. SsPrintPacket(PUCHAR packetp)
  85. {
  86. USHORT pktlen, printlen, dstsock, srcsock, ripop, ticks, hops;
  87. GETSHORT2USHORT(&pktlen, packetp + IPXH_LENGTH);
  88. GETSHORT2USHORT(&dstsock, packetp + IPXH_DESTSOCK);
  89. GETSHORT2USHORT(&srcsock, packetp + IPXH_SRCSOCK);
  90. GETSHORT2USHORT(&ripop, packetp + RIP_OPCODE);
  91. SsPrintf("---- RIP packet ----\n");
  92. SsPrintf("dest net %.2x%.2x%.2x%.2x\n",
  93. *(packetp + IPXH_DESTNET),
  94. *(packetp + IPXH_DESTNET + 1),
  95. *(packetp + IPXH_DESTNET + 2),
  96. *(packetp + IPXH_DESTNET + 3));
  97. SsPrintf("dest node %.2x%.2x%.2x%.2x%.2x%.2x\n",
  98. *(packetp + IPXH_DESTNODE),
  99. *(packetp + IPXH_DESTNODE + 1),
  100. *(packetp + IPXH_DESTNODE + 2),
  101. *(packetp + IPXH_DESTNODE + 3),
  102. *(packetp + IPXH_DESTNODE + 4),
  103. *(packetp + IPXH_DESTNODE + 5));
  104. SsPrintf("dest socket %x\n", dstsock);
  105. SsPrintf("src net %.2x%.2x%.2x%.2x\n",
  106. *(packetp + IPXH_SRCNET),
  107. *(packetp + IPXH_SRCNET + 1),
  108. *(packetp + IPXH_SRCNET + 2),
  109. *(packetp + IPXH_SRCNET + 3));
  110. SsPrintf("src node %.2x%.2x%.2x%.2x%.2x%.2x\n",
  111. *(packetp + IPXH_SRCNODE),
  112. *(packetp + IPXH_SRCNODE + 1),
  113. *(packetp + IPXH_SRCNODE + 2),
  114. *(packetp + IPXH_SRCNODE + 3),
  115. *(packetp + IPXH_SRCNODE + 4),
  116. *(packetp + IPXH_SRCNODE + 5));
  117. SsPrintf("src socket %x\n", srcsock);
  118. SsPrintf("RIP operation: %d\n", ripop);
  119. printlen = RIP_INFO;
  120. while(printlen < pktlen) {
  121. SsPrintf("net entry network %.2x%.2x%.2x%.2x\n",
  122. *(packetp + printlen + NE_NETNUMBER),
  123. *(packetp + printlen + NE_NETNUMBER + 1),
  124. *(packetp + printlen + NE_NETNUMBER + 2),
  125. *(packetp + printlen + NE_NETNUMBER + 3));
  126. GETSHORT2USHORT(&ticks, packetp + printlen + NE_NROFTICKS);
  127. GETSHORT2USHORT(&hops, packetp + printlen + NE_NROFHOPS);
  128. SsPrintf("net entry ticks %d\n", ticks);
  129. SsPrintf("net entry hops %d\n", hops);
  130. printlen += NE_ENTRYSIZE;
  131. }
  132. }
  133. #endif
  134. VOID
  135. StartTracing(VOID)
  136. {
  137. RipTraceID = TraceRegisterA ("IPXRIP");
  138. RipEventLogHdl = RouterLogRegisterA ("IPXRIP");
  139. }
  140. VOID
  141. Trace(ULONG ComponentID,
  142. char *Format,
  143. ...)
  144. {
  145. if (RipTraceID!=INVALID_TRACEID) {
  146. va_list arglist;
  147. va_start(arglist, Format);
  148. TraceVprintfExA(RipTraceID,
  149. ComponentID | TRACE_USE_MASK,
  150. Format,
  151. arglist);
  152. va_end(arglist);
  153. }
  154. }
  155. VOID
  156. StopTracing(VOID)
  157. {
  158. if (RipTraceID!=INVALID_TRACEID)
  159. TraceDeregisterA(RipTraceID);
  160. if (RipEventLogHdl!=NULL)
  161. RouterLogDeregisterA (RipEventLogHdl);
  162. }