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.

429 lines
11 KiB

  1. /*++
  2. Copyright (c) 1992 Microsoft Corporation
  3. Module Name:
  4. addr.c
  5. Abstract:
  6. Implements the addr command.
  7. Author:
  8. Keith Moore (keithmo) 19-Apr-1995
  9. Environment:
  10. User Mode.
  11. Revision History:
  12. --*/
  13. #include "afdkdp.h"
  14. #pragma hdrstop
  15. //
  16. // Public functions.
  17. //
  18. DECLARE_API( addr )
  19. /*++
  20. Routine Description:
  21. Dumps the TRANSPORT_ADDRESS structure at the specified address.
  22. Arguments:
  23. None.
  24. Return Value:
  25. None.
  26. --*/
  27. {
  28. UCHAR transportAddress[MAX_TRANSPORT_ADDR];
  29. ULONG64 address = 0;
  30. ULONG result;
  31. INT i;
  32. USHORT length;
  33. CHAR expr[MAX_ADDRESS_EXPRESSION];
  34. PCHAR argp;
  35. gClient = pClient;
  36. if (!CheckKmGlobals ()) {
  37. return E_INVALIDARG;
  38. }
  39. argp = ProcessOptions ((PCHAR)args);
  40. if (argp==NULL)
  41. return E_INVALIDARG;
  42. //
  43. // Snag the address from the command line.
  44. //
  45. while (sscanf( argp, "%s%n", expr, &i )==1) {
  46. if( CheckControlC() ) {
  47. break;
  48. }
  49. argp+=i;
  50. address = GetExpression (expr);
  51. result = GetFieldValue (address,
  52. "AFD!TRANSPORT_ADDRESS",
  53. "Address[0].AddressLength",
  54. length);
  55. if (result!=0) {
  56. dprintf("\naddr: Could not read length of TRANSPORT_ADDRESS @ %p, err: %ld\n",
  57. address, result);
  58. continue;
  59. }
  60. length = (USHORT)FIELD_OFFSET (TRANSPORT_ADDRESS, Address[0].Address[length]);
  61. if (!ReadMemory (address,
  62. transportAddress,
  63. length < sizeof (transportAddress)
  64. ? length
  65. : sizeof (transportAddress),
  66. &result)) {
  67. dprintf("\naddr: Could not read TRANSPORT_ADDRESS @ %p (%ld bytes)\n",
  68. address, length);
  69. continue;
  70. }
  71. if (Options & AFDKD_BRIEF_DISPLAY) {
  72. dprintf ("\n%s", TransportAddressToString (
  73. (PTRANSPORT_ADDRESS)transportAddress,
  74. address));
  75. }
  76. else {
  77. DumpTransportAddress(
  78. "",
  79. (PTRANSPORT_ADDRESS)transportAddress,
  80. address
  81. );
  82. }
  83. if (Options & AFDKD_FIELD_DISPLAY) {
  84. ProcessFieldOutput (address, "AFD!TRANSPORT_ADDRESS");
  85. }
  86. }
  87. dprintf ("\n");
  88. return S_OK;
  89. } // addr
  90. DECLARE_API( addrlist )
  91. /*++
  92. Routine Description:
  93. Dumps the list of addresses registered by the TDI transports,
  94. Arguments:
  95. None.
  96. Return Value:
  97. None.
  98. --*/
  99. {
  100. ULONG64 address, listHead;
  101. ULONG result;
  102. LIST_ENTRY64 listEntry;
  103. ULONG64 nextEntry;
  104. ULONG64 nameAddress;
  105. WCHAR deviceName[MAX_PATH];
  106. UCHAR transportAddress[MAX_TRANSPORT_ADDR];
  107. USHORT length;
  108. PCHAR argp;
  109. gClient = pClient;
  110. if (!CheckKmGlobals ()) {
  111. return E_INVALIDARG;
  112. }
  113. argp = ProcessOptions ((PCHAR)args);
  114. if (argp==NULL)
  115. return E_INVALIDARG;
  116. if (Options&AFDKD_BRIEF_DISPLAY) {
  117. dprintf (AFDKD_BRIEF_ADDRLIST_DISPLAY_HEADER);
  118. }
  119. address = listHead = GetExpression( "afd!AfdAddressEntryList" );
  120. if( address == 0 ) {
  121. dprintf( "\naddrlist: Could not find afd!AfdEndpointlistHead\n" );
  122. return E_INVALIDARG;
  123. }
  124. if( !ReadListEntry(
  125. listHead,
  126. &listEntry) ) {
  127. dprintf(
  128. "\naddrlist: Could not read afd!AfdAddressEntryList @ %p\n",
  129. listHead
  130. );
  131. return E_INVALIDARG;
  132. }
  133. nextEntry = listEntry.Flink;
  134. while( nextEntry != listHead ) {
  135. if (nextEntry==0) {
  136. dprintf ("\naddrlist: Flink is NULL, last entry: %p\n", address);
  137. break;
  138. }
  139. if( CheckControlC() ) {
  140. break;
  141. }
  142. address = nextEntry-AddressEntryLinkOffset;
  143. result = (ULONG)InitTypeRead (address, AFD!AFD_ADDRESS_ENTRY);
  144. if (result!=0) {
  145. dprintf(
  146. "\naddrlist: Could not read AFD_ADDRESS_ENTRY @ %p\n",
  147. address
  148. );
  149. break;
  150. }
  151. nextEntry = ReadField (AddressListLink.Flink);
  152. nameAddress = ReadField (DeviceName.Buffer);
  153. length = (USHORT)ReadField (DeviceName.Length);
  154. if (!ReadMemory (nameAddress,
  155. deviceName,
  156. length < sizeof (deviceName)-1
  157. ? length
  158. : sizeof (deviceName)-1,
  159. &result)) {
  160. dprintf(
  161. "\naddrlist: Could not read DeviceName for address entry @ %p\n",
  162. address
  163. );
  164. continue;
  165. }
  166. deviceName[result/2+1] = 0;
  167. length = (USHORT)ReadField (Address.AddressLength);
  168. length = (USHORT)FIELD_OFFSET (TA_ADDRESS, Address[length]);
  169. if (!ReadMemory (address+AddressEntryAddressOffset,
  170. transportAddress+FIELD_OFFSET(TRANSPORT_ADDRESS, Address),
  171. length < sizeof (transportAddress)-FIELD_OFFSET(TRANSPORT_ADDRESS, Address)
  172. ? length
  173. : sizeof (transportAddress)-FIELD_OFFSET(TRANSPORT_ADDRESS, Address),
  174. &result)) {
  175. dprintf("\naddrlist: Could not read TRANSPORT_ADDRESS for address entry @ %p (%d bytes)\n",
  176. address, length);
  177. continue;
  178. }
  179. if (!(Options & AFDKD_CONDITIONAL) ||
  180. CheckConditional (address, "AFD!AFD_ADDRESS_ENTRY") ) {
  181. if (Options & AFDKD_BRIEF_DISPLAY) {
  182. dprintf (
  183. IsPtr64 ()
  184. ? "\n%011.011p %-37.37ls %-32.32s"
  185. : "\n%008.008p %-37.37ls %-32.32s",
  186. DISP_PTR(address),
  187. &deviceName[sizeof("\\Device\\")-1],
  188. TransportAddressToString (
  189. (PTRANSPORT_ADDRESS)transportAddress,
  190. address +
  191. AddressEntryAddressOffset -
  192. FIELD_OFFSET(TRANSPORT_ADDRESS, Address))
  193. );
  194. }
  195. else {
  196. dprintf ("\nAddress List Entry @ %p\n", address);
  197. dprintf (" DeviceName = %ls\n", deviceName);
  198. DumpTransportAddress(
  199. " ",
  200. (PTRANSPORT_ADDRESS)transportAddress,
  201. address+AddressEntryAddressOffset-FIELD_OFFSET(TRANSPORT_ADDRESS, Address)
  202. );
  203. }
  204. if (Options & AFDKD_FIELD_DISPLAY) {
  205. ProcessFieldOutput (address, "AFD!AFD_ADDRESS_ENTRY");
  206. }
  207. }
  208. else
  209. dprintf (".");
  210. }
  211. if (Options&AFDKD_BRIEF_DISPLAY) {
  212. dprintf (AFDKD_BRIEF_ADDRLIST_DISPLAY_TRAILER);
  213. }
  214. else {
  215. dprintf ("\n");
  216. }
  217. return S_OK;
  218. }
  219. DECLARE_API( tranlist )
  220. /*++
  221. Routine Description:
  222. Dumps the list of transports which have open sockets associated with them.
  223. Arguments:
  224. None.
  225. Return Value:
  226. None.
  227. --*/
  228. {
  229. ULONG64 address;
  230. ULONG result;
  231. LIST_ENTRY64 listEntry;
  232. ULONG64 nextEntry;
  233. ULONG64 listHead;
  234. PAFDKD_TRANSPORT_INFO transportInfo;
  235. PCHAR argp;
  236. gClient = pClient;
  237. if (!CheckKmGlobals ()) {
  238. return E_INVALIDARG;
  239. }
  240. argp = ProcessOptions ((PCHAR)args);
  241. if (argp==NULL)
  242. return E_INVALIDARG;
  243. if (Options&AFDKD_BRIEF_DISPLAY) {
  244. dprintf (AFDKD_BRIEF_TRANSPORT_DISPLAY_HEADER);
  245. }
  246. listHead = address = GetExpression( "afd!AfdTransportInfoListHead" );
  247. if( listHead == 0 ) {
  248. dprintf( "\ntranlist: Could not find afd!AfdTransportInfoListHead\n" );
  249. return E_INVALIDARG;
  250. }
  251. if( !ReadListEntry(
  252. listHead,
  253. &listEntry) ) {
  254. dprintf(
  255. "\ntranlist: Could not read afd!AfdTransportInfoListHead @ %p\n",
  256. listHead
  257. );
  258. return E_INVALIDARG;
  259. }
  260. //
  261. // Free the old list
  262. //
  263. while (!IsListEmpty (&TransportInfoList)) {
  264. PLIST_ENTRY plistEntry;
  265. plistEntry = RemoveHeadList (&TransportInfoList);
  266. transportInfo = CONTAINING_RECORD (plistEntry,
  267. AFDKD_TRANSPORT_INFO,
  268. Link);
  269. RtlFreeHeap (RtlProcessHeap (), 0, transportInfo);
  270. }
  271. nextEntry = listEntry.Flink;
  272. while( nextEntry != listHead ) {
  273. if (nextEntry==0) {
  274. dprintf ("\ntranlist: Flink is NULL, last entry: %p\n", address);
  275. break;
  276. }
  277. if( CheckControlC() ) {
  278. break;
  279. }
  280. address = nextEntry-TransportInfoLinkOffset;
  281. result = (ULONG)InitTypeRead (address, AFD!AFD_TRANSPORT_INFO);
  282. if (result!=0) {
  283. dprintf(
  284. "\ntranlist: Could not read AFD_TRANSPORT_INFO @ %p\n",
  285. address
  286. );
  287. break;
  288. }
  289. nextEntry = ReadField (TransportInfoListEntry.Flink);
  290. transportInfo = ReadTransportInfo (address);
  291. if (transportInfo!=NULL) {
  292. InsertHeadList (&TransportInfoList, &transportInfo->Link);
  293. if (!(Options & AFDKD_CONDITIONAL) ||
  294. CheckConditional (address, "AFD!AFD_TRANSPORT_INFO") ) {
  295. if (Options & AFDKD_BRIEF_DISPLAY) {
  296. DumpTransportInfoBrief (transportInfo);
  297. }
  298. else {
  299. DumpTransportInfo (transportInfo);
  300. }
  301. if (Options & AFDKD_FIELD_DISPLAY) {
  302. ProcessFieldOutput (address, "AFD!AFD_TRANSPORT_INFO");
  303. }
  304. }
  305. else
  306. dprintf (".");
  307. }
  308. else
  309. break;
  310. }
  311. if (Options&AFDKD_BRIEF_DISPLAY) {
  312. dprintf (AFDKD_BRIEF_TRANSPORT_DISPLAY_TRAILER);
  313. }
  314. else {
  315. dprintf ("\n");
  316. }
  317. return S_OK;
  318. }