@@ -328,6 +328,124 @@ IpShowDns(
328328}
329329
330330
331+ static
332+ DWORD
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+
331449static
332450DWORD
333451WINAPI
@@ -350,6 +468,8 @@ IpStart(
350468 ContextAttributes .ulNumGroups = sizeof (IpGroups ) / sizeof (CMD_GROUP_ENTRY );
351469 ContextAttributes .pCmdGroups = IpGroups ;
352470
471+ ContextAttributes .pfnDumpFn = IpDumpFn ;
472+
353473 RegisterContext (& ContextAttributes );
354474
355475 return ERROR_SUCCESS ;
0 commit comments