Reactos

[IFMON] Implement a basic dump functionality

Eric Kohl 82aaf156 d0333017

+164 -2
+31 -2
dll/win32/ifmon/interface.c
··· 60 60 } 61 61 62 62 63 + static 64 + DWORD 65 + WINAPI 66 + InterfaceDumpFn( 67 + _In_ LPCWSTR pwszRouter, 68 + _In_ LPWSTR *ppwcArguments, 69 + _In_ DWORD dwArgCount, 70 + _In_ LPCVOID pvData) 71 + { 72 + DPRINT("InterfaceDumpFn(%S %p %lu %p)\n", pwszRouter, ppwcArguments, dwArgCount, pvData); 73 + 74 + PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE); 75 + PrintMessage(L"# Interface Configuration\n"); 76 + PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE); 77 + PrintMessage(L"pushd\n"); 78 + PrintMessage(L"interface\n"); 79 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 80 + 81 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 82 + PrintMessage(L"popd\n"); 83 + PrintMessage(L"# End of Interface Configuration\n"); 84 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 85 + 86 + return ERROR_SUCCESS; 87 + } 88 + 89 + 63 90 DWORD 64 91 WINAPI 65 92 InterfaceStart( ··· 68 95 { 69 96 NS_CONTEXT_ATTRIBUTES ContextAttributes; 70 97 71 - DPRINT1("InterfaceStart()\n"); 98 + DPRINT("InterfaceStart()\n"); 72 99 73 100 ZeroMemory(&ContextAttributes, sizeof(ContextAttributes)); 74 101 ContextAttributes.dwVersion = 1; ··· 81 108 ContextAttributes.ulNumGroups = sizeof(InterfaceGroups) / sizeof(CMD_GROUP_ENTRY); 82 109 ContextAttributes.pCmdGroups = InterfaceGroups; 83 110 111 + ContextAttributes.pfnDumpFn = InterfaceDumpFn; 112 + 84 113 RegisterContext(&ContextAttributes); 85 114 86 115 return ERROR_SUCCESS; ··· 93 122 { 94 123 NS_HELPER_ATTRIBUTES HelperAttributes; 95 124 96 - DPRINT1("RegisterInterfaceHelper()\n"); 125 + DPRINT("RegisterInterfaceHelper()\n"); 97 126 98 127 ZeroMemory(&HelperAttributes, sizeof(HelperAttributes)); 99 128 HelperAttributes.dwVersion = 1;
+120
dll/win32/ifmon/ip.c
··· 331 331 static 332 332 DWORD 333 333 WINAPI 334 + IpDumpFn( 335 + _In_ LPCWSTR pwszRouter, 336 + _In_ LPWSTR *ppwcArguments, 337 + _In_ DWORD dwArgCount, 338 + _In_ LPCVOID pvData) 339 + { 340 + PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL, Ptr; 341 + PIP_ADAPTER_UNICAST_ADDRESS pUnicastAddress; 342 + PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsServer; 343 + WCHAR AddressBuffer[17], MaskBuffer[17]; 344 + ULONG adaptOutBufLen = 15000; 345 + ULONG Flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST; 346 + DWORD Error = ERROR_SUCCESS; 347 + 348 + DPRINT("IpDumpFn(%S %p %lu %p)\n", pwszRouter, ppwcArguments, dwArgCount, pvData); 349 + 350 + PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE); 351 + PrintMessage(L"# Interface IP Configuration\n"); 352 + PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE); 353 + PrintMessage(L"pushd\n"); 354 + PrintMessage(L"interface ip\n"); 355 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 356 + 357 + /* set required buffer size */ 358 + pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen); 359 + if (pAdapterAddresses == NULL) 360 + { 361 + Error = ERROR_NOT_ENOUGH_MEMORY; 362 + goto done; 363 + } 364 + 365 + Error = GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen); 366 + if (Error == ERROR_BUFFER_OVERFLOW) 367 + { 368 + free(pAdapterAddresses); 369 + pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen); 370 + if (pAdapterAddresses == NULL) 371 + { 372 + Error = ERROR_NOT_ENOUGH_MEMORY; 373 + goto done; 374 + } 375 + } 376 + 377 + Error = GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen); 378 + if (Error != ERROR_SUCCESS) 379 + goto done; 380 + 381 + Ptr = pAdapterAddresses; 382 + while (Ptr) 383 + { 384 + if (Ptr->IfType != IF_TYPE_SOFTWARE_LOOPBACK) 385 + { 386 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 387 + PrintMessageFromModule(hDllInstance, IDS_DUMP_IP_HEADER, Ptr->FriendlyName); 388 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 389 + 390 + if (Ptr->Flags & IP_ADAPTER_DHCP_ENABLED) 391 + { 392 + PrintMessage(L"set address name=\"%s\" source=dhcp\n", 393 + Ptr->FriendlyName); 394 + } 395 + else 396 + { 397 + pUnicastAddress = Ptr->FirstUnicastAddress; 398 + while (pUnicastAddress) 399 + { 400 + FormatIPv4Address(AddressBuffer, &pUnicastAddress->Address); 401 + wcscpy(MaskBuffer, L"?"); 402 + 403 + PrintMessage(L"set address name=\"%s\" source=static address=%s mask=%s\n", 404 + Ptr->FriendlyName, AddressBuffer, MaskBuffer); 405 + 406 + pUnicastAddress = pUnicastAddress->Next; 407 + } 408 + } 409 + 410 + if (Ptr->Flags & IP_ADAPTER_DHCP_ENABLED) 411 + { 412 + PrintMessage(L"set dns name=\"%s\" source=dhcp\n", 413 + Ptr->FriendlyName); 414 + } 415 + else 416 + { 417 + pDnsServer = Ptr->FirstDnsServerAddress; 418 + while (pDnsServer) 419 + { 420 + FormatIPv4Address(AddressBuffer, &pDnsServer->Address); 421 + 422 + PrintMessage(L"set dns name=\"%s\" source=%s address=%s\n", 423 + Ptr->FriendlyName); 424 + 425 + pDnsServer = pDnsServer->Next; 426 + } 427 + 428 + } 429 + 430 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 431 + } 432 + 433 + Ptr = Ptr->Next; 434 + } 435 + 436 + done: 437 + if (pAdapterAddresses) 438 + free(pAdapterAddresses); 439 + 440 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 441 + PrintMessage(L"popd\n"); 442 + PrintMessage(L"# End of Interface IP Configuration\n"); 443 + PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE); 444 + 445 + return ERROR_SUCCESS; 446 + } 447 + 448 + 449 + static 450 + DWORD 451 + WINAPI 334 452 IpStart( 335 453 _In_ const GUID *pguidParent, 336 454 _In_ DWORD dwVersion) ··· 349 467 350 468 ContextAttributes.ulNumGroups = sizeof(IpGroups) / sizeof(CMD_GROUP_ENTRY); 351 469 ContextAttributes.pCmdGroups = IpGroups; 470 + 471 + ContextAttributes.pfnDumpFn = IpDumpFn; 352 472 353 473 RegisterContext(&ContextAttributes); 354 474
+9
dll/win32/ifmon/lang/en-US.rc
··· 25 25 IDS_SUBNETMASKS " Subnet Masks: %s\n" 26 26 27 27 IDS_EMPTYLINE " %s\n" 28 + 29 + 30 + 31 + IDS_DUMP_NEWLINE "\n" 32 + IDS_DUMP_HEADERLINE "# ----------------------------------\n" 33 + 34 + IDS_DUMP_IP_HEADER "# Interface IP Configuration for ""%s""\n" 35 + 36 + 28 37 END
+4
dll/win32/ifmon/resource.h
··· 22 22 #define IDS_SUBNETMASKS 308 23 23 24 24 #define IDS_EMPTYLINE 400 25 + 26 + #define IDS_DUMP_NEWLINE 800 27 + #define IDS_DUMP_HEADERLINE 801 28 + #define IDS_DUMP_IP_HEADER 802