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.

202 lines
5.6 KiB

  1. /*==========================================================================
  2. *
  3. * Copyright (C) 1998-2002 Microsoft Corporation. All Rights Reserved.
  4. *
  5. * File: DebugUtils.cpp
  6. * Content: Winsock service provider debug utility functions
  7. *
  8. *
  9. * History:
  10. * Date By Reason
  11. * ==== == ======
  12. * 11/25/98 jtk Created
  13. ***************************************************************************/
  14. #include "dnwsocki.h"
  15. #ifdef DBG
  16. //**********************************************************************
  17. // Constant definitions
  18. //**********************************************************************
  19. //**********************************************************************
  20. // Macro definitions
  21. //**********************************************************************
  22. //**********************************************************************
  23. // Structure definitions
  24. //**********************************************************************
  25. //**********************************************************************
  26. // Variable definitions
  27. //**********************************************************************
  28. //**********************************************************************
  29. // Function prototypes
  30. //**********************************************************************
  31. //**********************************************************************
  32. // Function definitions
  33. //**********************************************************************
  34. //**********************************************************************
  35. // ------------------------------
  36. // HexDump - perform a hex dump of information
  37. //
  38. // Entry: Pointer to data
  39. // Data size
  40. //
  41. // Exit: Nothing
  42. // ------------------------------
  43. #undef DPF_MODNAME
  44. #define DPF_MODNAME "HexDump"
  45. void HexDump( PVOID pData, UINT32 uDataSize )
  46. {
  47. DWORD uIdx = 0;
  48. // go through all data
  49. while ( uIdx < uDataSize )
  50. {
  51. // output character
  52. DPFX(DPFPREP, 0, "0x%2x ", ( (LPBYTE) pData )[ uIdx ] );
  53. // increment index
  54. uIdx++;
  55. // are we off the end of a line?
  56. if ( ( uIdx % 12 ) == 0 )
  57. {
  58. DPFX(DPFPREP, 0, "\n" );
  59. }
  60. }
  61. }
  62. //**********************************************************************
  63. //**********************************************************************
  64. // ------------------------------
  65. // DumpSocketAddress - dump a socket address
  66. //
  67. // Entry: Debug level
  68. // Pointer to socket address
  69. // Socket family
  70. //
  71. // Exit: Nothing
  72. // ------------------------------
  73. #undef DPF_MODNAME
  74. #define DPF_MODNAME "DumpSocketAddress"
  75. void DumpSocketAddress( const DWORD dwDebugLevel, const SOCKADDR *const pSocketAddress, const DWORD dwFamily )
  76. {
  77. switch ( dwFamily )
  78. {
  79. case AF_INET:
  80. {
  81. const SOCKADDR_IN *const pInetAddress = reinterpret_cast<const SOCKADDR_IN*>( pSocketAddress );
  82. DPFX(DPFPREP, dwDebugLevel, "IPv4 socket: Address: %d.%d.%d.%d Port: %d",
  83. pInetAddress->sin_addr.S_un.S_un_b.s_b1,
  84. pInetAddress->sin_addr.S_un.S_un_b.s_b2,
  85. pInetAddress->sin_addr.S_un.S_un_b.s_b3,
  86. pInetAddress->sin_addr.S_un.S_un_b.s_b4,
  87. NTOHS( pInetAddress->sin_port )
  88. );
  89. break;
  90. }
  91. #ifndef DPNBUILD_NOIPX
  92. case AF_IPX:
  93. {
  94. const SOCKADDR_IPX *const pIPXAddress = reinterpret_cast<const SOCKADDR_IPX*>( pSocketAddress );
  95. DPFX(DPFPREP, dwDebugLevel, "IPX socket: Net (hex) %x-%x-%x-%x Node (hex): %x-%x-%x-%x-%x-%x Socket: %d",
  96. (BYTE)pIPXAddress->sa_netnum[ 0 ],
  97. (BYTE)pIPXAddress->sa_netnum[ 1 ],
  98. (BYTE)pIPXAddress->sa_netnum[ 2 ],
  99. (BYTE)pIPXAddress->sa_netnum[ 3 ],
  100. (BYTE)pIPXAddress->sa_nodenum[ 0 ],
  101. (BYTE)pIPXAddress->sa_nodenum[ 1 ],
  102. (BYTE)pIPXAddress->sa_nodenum[ 2 ],
  103. (BYTE)pIPXAddress->sa_nodenum[ 3 ],
  104. (BYTE)pIPXAddress->sa_nodenum[ 4 ],
  105. (BYTE)pIPXAddress->sa_nodenum[ 5 ],
  106. NTOHS( pIPXAddress->sa_socket )
  107. );
  108. break;
  109. }
  110. #endif // ! DPNBUILD_NOIPX
  111. #ifndef DPNBUILD_NOIPV6
  112. case AF_INET6:
  113. {
  114. WCHAR wszString[INET6_ADDRSTRLEN];
  115. const SOCKADDR_IN6 *const pInet6Address = reinterpret_cast<const SOCKADDR_IN6*>( pSocketAddress );
  116. DNIpv6AddressToStringW(&pInet6Address->sin6_addr, wszString);
  117. DPFX(DPFPREP, dwDebugLevel, "IPv6 socket: Address: %ls Port: %d Scope: %d",
  118. wszString,
  119. NTOHS( pInet6Address->sin6_port ),
  120. pInet6Address->sin6_scope_id
  121. );
  122. break;
  123. }
  124. #endif // ! DPNBUILD_NOIPV6
  125. default:
  126. {
  127. DPFX(DPFPREP, 0, "Unknown socket type!" );
  128. DNASSERT( FALSE );
  129. break;
  130. }
  131. }
  132. }
  133. //**********************************************************************
  134. //**********************************************************************
  135. // ------------------------------
  136. // DumpAddress - convert an address to a URL and output via debugger
  137. //
  138. // Entry: Debug level
  139. // Pointer to base message string
  140. // Pointer to address
  141. //
  142. // Exit: Nothing
  143. // ------------------------------
  144. #undef DPF_MODNAME
  145. #define DPF_MODNAME "DumpAddress"
  146. void DumpAddress( const DWORD dwDebugLevel, const TCHAR *const pBaseString, IDirectPlay8Address *const pAddress )
  147. {
  148. HRESULT hr;
  149. TCHAR tszURL[512];
  150. DWORD dwURLSize;
  151. DNASSERT( pBaseString != NULL );
  152. DNASSERT( pAddress != NULL );
  153. dwURLSize = sizeof(tszURL) / sizeof(TCHAR);
  154. hr = IDirectPlay8Address_GetURL( pAddress, tszURL, &dwURLSize );
  155. if ( hr == DPN_OK )
  156. {
  157. DPFX(DPFPREP, dwDebugLevel, "%s 0x%p - \"%s\"", pBaseString, pAddress, tszURL );
  158. }
  159. else
  160. {
  161. DPFX(DPFPREP, dwDebugLevel, "Failing DumpAddress (err = 0x%x):", hr );
  162. DisplayDNError( dwDebugLevel, hr );
  163. }
  164. return;
  165. }
  166. #endif // DBG