@@ -93,7 +93,8 @@ FormatIPv4Address(
9393static
9494DWORD
9595IpShowAdapters (
96- _In_ DWORD DisplayFlags )
96+ _In_ DWORD DisplayFlags ,
97+ _In_ PWSTR InterfaceName )
9798{
9899 PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL , Ptr ;
99100 PIP_ADAPTER_UNICAST_ADDRESS pUnicastAddress ;
@@ -132,111 +133,114 @@ IpShowAdapters(
132133 Ptr = pAdapterAddresses ;
133134 while (Ptr )
134135 {
135- PrintMessageFromModule (hDllInstance , IDS_IP_HEADER , Ptr -> FriendlyName );
136-
137- if (DisplayFlags & DISPLAY_ADRESSES )
136+ if (InterfaceName == NULL || MatchToken (InterfaceName , Ptr -> FriendlyName ))
138137 {
139- PrintMessageFromModule (hDllInstance , ( Ptr -> Flags & IP_ADAPTER_DHCP_ENABLED ) ? IDS_DHCP_ON : IDS_DHCP_OFF );
138+ PrintMessageFromModule (hDllInstance , IDS_IP_HEADER , Ptr -> FriendlyName );
140139
141- if (Ptr -> FirstUnicastAddress == NULL )
142- {
143- PrintMessageFromModule (hDllInstance , IDS_NOIPADDRESS );
144- }
145- else
140+ if (DisplayFlags & DISPLAY_ADRESSES )
146141 {
147- First = TRUE;
148- pUnicastAddress = Ptr -> FirstUnicastAddress ;
149- while (pUnicastAddress )
142+ PrintMessageFromModule (hDllInstance , (Ptr -> Flags & IP_ADAPTER_DHCP_ENABLED ) ? IDS_DHCP_ON : IDS_DHCP_OFF );
143+
144+ if (Ptr -> FirstUnicastAddress == NULL )
145+ {
146+ PrintMessageFromModule (hDllInstance , IDS_NOIPADDRESS );
147+ }
148+ else
150149 {
151- if (FormatIPv4Address (IpBuffer , & pUnicastAddress -> Address ))
150+ First = TRUE;
151+ pUnicastAddress = Ptr -> FirstUnicastAddress ;
152+ while (pUnicastAddress )
152153 {
153- if (First )
154- {
155- PrintMessageFromModule (hDllInstance , (pUnicastAddress -> Next )? IDS_IPADDRESSES : IDS_IPADDRESS , IpBuffer );
156- }
157- else
154+ if (FormatIPv4Address (IpBuffer , & pUnicastAddress -> Address ))
158155 {
159- PrintMessageFromModule (hDllInstance , IDS_EMPTYLINE , IpBuffer );
156+ if (First )
157+ {
158+ PrintMessageFromModule (hDllInstance , (pUnicastAddress -> Next )? IDS_IPADDRESSES : IDS_IPADDRESS , IpBuffer );
159+ }
160+ else
161+ {
162+ PrintMessageFromModule (hDllInstance , IDS_EMPTYLINE , IpBuffer );
163+ }
164+ First = FALSE;
160165 }
161- First = FALSE;
162- }
163166
164- pUnicastAddress = pUnicastAddress -> Next ;
167+ pUnicastAddress = pUnicastAddress -> Next ;
168+ }
165169 }
166- }
167170
168- if (Ptr -> FirstPrefix == NULL )
169- {
170- PrintMessage (L" SubnetMask: %s\n" , L"None" );
171- }
172- else
173- {
174- First = TRUE;
175- pPrefix = Ptr -> FirstPrefix ;
176- while (pPrefix )
171+ if (Ptr -> FirstPrefix == NULL )
177172 {
178- if (FormatIPv4Address (IpBuffer , & pPrefix -> Address ))
173+ PrintMessage (L" SubnetMask: %s\n" , L"None" );
174+ }
175+ else
176+ {
177+ First = TRUE;
178+ pPrefix = Ptr -> FirstPrefix ;
179+ while (pPrefix )
179180 {
180- if (First )
181+ if (FormatIPv4Address ( IpBuffer , & pPrefix -> Address ) )
181182 {
182- if (pPrefix -> Next )
183- PrintMessage (L" SubnetMasks: %s/%lu\n" , IpBuffer , pPrefix -> PrefixLength );
183+ if (First )
184+ {
185+ if (pPrefix -> Next )
186+ PrintMessage (L" SubnetMasks: %s/%lu\n" , IpBuffer , pPrefix -> PrefixLength );
187+ else
188+ PrintMessage (L" IP Address: %s/%lu\n" , IpBuffer , pPrefix -> PrefixLength );
189+ }
184190 else
185- PrintMessage (L" IP Address: %s/%lu\n" , IpBuffer , pPrefix -> PrefixLength );
186- }
187- else
188- {
189- PrintMessage (L" %s/%lu\n" , IpBuffer , pPrefix -> PrefixLength );
191+ {
192+ PrintMessage (L" %s/%lu\n" , IpBuffer , pPrefix -> PrefixLength );
193+ }
194+ First = FALSE;
190195 }
191- First = FALSE;
192- }
193196
194- pPrefix = pPrefix -> Next ;
197+ pPrefix = pPrefix -> Next ;
198+ }
195199 }
196- }
197200
198- // PrintMessage(L" Default Gateway: %s\n", L"---");
199- // PrintMessage(L" Gateway Metric: %s\n", L"---");
200- // PrintMessage(L" Interface Metric: %s\n", L"---");
201- }
201+ // PrintMessage(L" Default Gateway: %s\n", L"---");
202+ // PrintMessage(L" Gateway Metric: %s\n", L"---");
203+ // PrintMessage(L" Interface Metric: %s\n", L"---");
204+ }
202205
203- if (DisplayFlags & DISPLAY_DNS )
204- {
205- if (Ptr -> FirstDnsServerAddress == NULL )
206+ if (DisplayFlags & DISPLAY_DNS )
206207 {
207- if (Ptr -> Flags & IP_ADAPTER_DHCP_ENABLED )
208- PrintMessage (L" DNS servers configured through DHCP: %s\n" , L"None" );
208+ if (Ptr -> FirstDnsServerAddress == NULL )
209+ {
210+ if (Ptr -> Flags & IP_ADAPTER_DHCP_ENABLED )
211+ PrintMessage (L" DNS servers configured through DHCP: %s\n" , L"None" );
212+ else
213+ PrintMessage (L" Statically configured DNS Servers: %s\n" , L"None" );
214+ }
209215 else
210- PrintMessage (L" Statically configured DNS Servers: %s\n" , L"None" );
211- }
212- else
213- {
214- First = TRUE;
215- pDnsServer = Ptr -> FirstDnsServerAddress ;
216- while (pDnsServer )
217216 {
218- if (FormatIPv4Address (IpBuffer , & pDnsServer -> Address ))
217+ First = TRUE;
218+ pDnsServer = Ptr -> FirstDnsServerAddress ;
219+ while (pDnsServer )
219220 {
220- if (First == TRUE )
221+ if (FormatIPv4Address ( IpBuffer , & pDnsServer -> Address ) )
221222 {
222- if (Ptr -> Flags & IP_ADAPTER_DHCP_ENABLED )
223- PrintMessage (L" DNS servers configured through DHCP: %s\n" , IpBuffer );
223+ if (First == TRUE)
224+ {
225+ if (Ptr -> Flags & IP_ADAPTER_DHCP_ENABLED )
226+ PrintMessage (L" DNS servers configured through DHCP: %s\n" , IpBuffer );
227+ else
228+ PrintMessage (L" Statically configured DNS Servers: %s\n" , IpBuffer );
229+ }
224230 else
225- PrintMessage ( L" Statically configured DNS Servers: %s\n" , IpBuffer );
226- }
227- else
228- {
229- PrintMessage ( L" %s\n" , IpBuffer ) ;
231+ {
232+ PrintMessage ( L" %s\n" , IpBuffer );
233+ }
234+
235+ First = FALSE ;
230236 }
231237
232- First = FALSE ;
238+ pDnsServer = pDnsServer -> Next ;
233239 }
234-
235- pDnsServer = pDnsServer -> Next ;
236240 }
237- }
238241
239- // PrintMessage(L" Register with which suffix:\n");
242+ // PrintMessage(L" Register with which suffix:\n");
243+ }
240244 }
241245
242246 Ptr = Ptr -> Next ;
@@ -264,7 +268,15 @@ IpShowAddresses(
264268 LPCVOID pvData ,
265269 BOOL * pbDone )
266270{
267- return IpShowAdapters (DISPLAY_ADRESSES );
271+ PWSTR pszInterfaceName = NULL ;
272+
273+ if (dwArgCount - dwCurrentIndex > 1 )
274+ return ERROR_INVALID_PARAMETER ;
275+
276+ if (dwArgCount - dwCurrentIndex == 1 )
277+ pszInterfaceName = argv [dwCurrentIndex ];
278+
279+ return IpShowAdapters (DISPLAY_ADRESSES , pszInterfaceName );
268280}
269281
270282
@@ -280,7 +292,15 @@ IpShowConfig(
280292 LPCVOID pvData ,
281293 BOOL * pbDone )
282294{
283- return IpShowAdapters (DISPLAY_ADRESSES | DISPLAY_DNS );
295+ PWSTR pszInterfaceName = NULL ;
296+
297+ if (dwArgCount - dwCurrentIndex > 1 )
298+ return ERROR_INVALID_PARAMETER ;
299+
300+ if (dwArgCount - dwCurrentIndex == 1 )
301+ pszInterfaceName = argv [dwCurrentIndex ];
302+
303+ return IpShowAdapters (DISPLAY_ADRESSES | DISPLAY_DNS , pszInterfaceName );
284304}
285305
286306
@@ -296,7 +316,15 @@ IpShowDns(
296316 LPCVOID pvData ,
297317 BOOL * pbDone )
298318{
299- return IpShowAdapters (DISPLAY_DNS );
319+ PWSTR pszInterfaceName = NULL ;
320+
321+ if (dwArgCount - dwCurrentIndex > 1 )
322+ return ERROR_INVALID_PARAMETER ;
323+
324+ if (dwArgCount - dwCurrentIndex == 1 )
325+ pszInterfaceName = argv [dwCurrentIndex ];
326+
327+ return IpShowAdapters (DISPLAY_DNS , pszInterfaceName );
300328}
301329
302330
0 commit comments