Skip to content

Commit f86835f

Browse files
committed
[IFMON] Improve the output of the 'show address' and 'dump' commands
1 parent f00e1cd commit f86835f

3 files changed

Lines changed: 81 additions & 50 deletions

File tree

‎dll/win32/ifmon/ip.c‎

Lines changed: 63 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -242,7 +242,7 @@ IpShowAdapters(
242242
WCHAR szFriendlyName[80];
243243
DWORD dwFriendlyNameSize;
244244
PTCPIP_PROPERTIES pProperties = NULL;
245-
PWSTR pBuffer;
245+
PWSTR pBuffer, pStart, pEnd;
246246

247247
dwError = NhpAllocateAndGetInterfaceInfoFromStack(&pTable,
248248
&dwCount,
@@ -291,58 +291,79 @@ IpShowAdapters(
291291
{
292292
PrintMessageFromModule(hDllInstance, (pProperties->dwDhcp) ? IDS_DHCP_ON : IDS_DHCP_OFF);
293293

294-
if (*pProperties->pszIpAddress == UNICODE_NULL)
295-
{
296-
PrintMessageFromModule(hDllInstance, IDS_NOIPADDRESS);
297-
}
298-
else
299-
{
300-
PrintMessageFromModule(hDllInstance, IDS_IPADDRESS, pProperties->pszIpAddress);
301-
}
302-
303-
if (*pProperties->pszSubnetMask == UNICODE_NULL)
304-
{
305-
PrintMessageFromModule(hDllInstance, IDS_NOSUBNETMASK);
306-
}
307-
else
308-
{
309-
PrintMessageFromModule(hDllInstance, IDS_SUBNETMASK, pProperties->pszSubnetMask);
310-
}
311-
312-
pBuffer = ExtractParameterValue(pProperties->pszParameters, L"DefGw");
313-
if (pBuffer)
294+
if (pProperties->dwDhcp == 0)
314295
{
315-
PrintMessage(L" Default Gateway: %s\n", pBuffer);
316-
HeapFree(GetProcessHeap(), 0, pBuffer);
317-
}
318-
319-
pBuffer = ExtractParameterValue(pProperties->pszParameters, L"GwMetric");
320-
if (pBuffer)
321-
{
322-
PrintMessage(L" Gateway Metric: %s\n", pBuffer);
323-
HeapFree(GetProcessHeap(), 0, pBuffer);
296+
if (*pProperties->pszIpAddress == UNICODE_NULL)
297+
{
298+
PrintMessageFromModule(hDllInstance, IDS_NOIPADDRESS);
299+
}
300+
else
301+
{
302+
PrintMessageFromModule(hDllInstance, IDS_IPADDRESS, pProperties->pszIpAddress);
303+
}
304+
305+
if (*pProperties->pszSubnetMask == UNICODE_NULL)
306+
{
307+
PrintMessageFromModule(hDllInstance, IDS_NOSUBNETMASK);
308+
}
309+
else
310+
{
311+
PrintMessageFromModule(hDllInstance, IDS_SUBNETMASK, pProperties->pszSubnetMask);
312+
}
313+
314+
pBuffer = ExtractParameterValue(pProperties->pszParameters, L"DefGw");
315+
if (pBuffer)
316+
{
317+
PrintMessageFromModule(hDllInstance, IDS_DEFAULTGATEWAY, pBuffer);
318+
HeapFree(GetProcessHeap(), 0, pBuffer);
319+
}
320+
321+
pBuffer = ExtractParameterValue(pProperties->pszParameters, L"GwMetric");
322+
if (pBuffer)
323+
{
324+
PrintMessageFromModule(hDllInstance, IDS_GATEWAYMETRIC, pBuffer);
325+
HeapFree(GetProcessHeap(), 0, pBuffer);
326+
}
324327
}
325328

326329
pBuffer = ExtractParameterValue(pProperties->pszParameters, L"IfMetric");
327330
if (pBuffer)
328331
{
329-
PrintMessage(L" Interface Metric: %s\n", pBuffer);
332+
PrintMessageFromModule(hDllInstance, IDS_INTERFACEMETRIC, pBuffer);
330333
HeapFree(GetProcessHeap(), 0, pBuffer);
331334
}
332335
}
333336

334337
if (DisplayFlags & DISPLAY_DNS)
335338
{
336-
337-
pBuffer = ExtractParameterValue(pProperties->pszParameters, L"DNS");
338-
if (pBuffer)
339+
if (pProperties->dwDhcp == 0)
339340
{
340-
PrintMessage(L" Statically configured DNS Servers: %s\n", pBuffer);
341-
HeapFree(GetProcessHeap(), 0, pBuffer);
341+
pBuffer = ExtractParameterValue(pProperties->pszParameters, L"DNS");
342+
if (pBuffer)
343+
{
344+
pEnd = wcschr(pBuffer, L',');
345+
if (pEnd == NULL)
346+
{
347+
PrintMessageFromModule(hDllInstance, IDS_STATICNAMESERVER, pBuffer);
348+
}
349+
else
350+
{
351+
pStart = pBuffer;
352+
*pEnd = UNICODE_NULL;
353+
PrintMessageFromModule(hDllInstance, IDS_STATICNAMESERVER, pBuffer);
354+
for (;;)
355+
{
356+
pStart = pEnd + 1;
357+
pEnd = wcschr(pStart, L',');
358+
if (pEnd == NULL)
359+
break;
360+
*pEnd = UNICODE_NULL;
361+
PrintMessageFromModule(hDllInstance, IDS_EMPTYLINE, pBuffer);
362+
}
363+
}
364+
HeapFree(GetProcessHeap(), 0, pBuffer);
365+
}
342366
}
343-
344-
// PrintMessage(L" DNS servers configured through DHCP: %s\n", IpBuffer);
345-
// PrintMessage(L" %s\n", IpBuffer);
346367
}
347368

348369
CoTaskMemFree(pProperties);
@@ -461,7 +482,7 @@ IpDumpFn(
461482
}
462483

463484
PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE);
464-
PrintMessage(L"# Interface IP Configuration\n");
485+
PrintMessageFromModule(hDllInstance, IDS_DUMP_IP_HEADER);
465486
PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE);
466487
PrintMessage(L"pushd interface ip\n");
467488
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
@@ -486,7 +507,7 @@ IpDumpFn(
486507
0);
487508

488509
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
489-
PrintMessageFromModule(hDllInstance, IDS_DUMP_IP_HEADER, szFriendlyName);
510+
PrintMessageFromModule(hDllInstance, IDS_DUMP_IP_INTERFACE, szFriendlyName);
490511
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
491512

492513
GetInterfaceProperties(&pTable[i].DeviceGuid, &pProperties);
@@ -532,7 +553,7 @@ IpDumpFn(
532553

533554
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
534555
PrintMessage(L"popd\n");
535-
PrintMessage(L"# End of Interface IP Configuration\n");
556+
PrintMessageFromModule(hDllInstance, IDS_DUMP_IP_FOOTER);
536557
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
537558

538559
if (pTable)

‎dll/win32/ifmon/lang/en-US.rc‎

Lines changed: 8 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,18 @@ Parameters:\n\n\
5050
IDS_NOSUBNETMASK " Subnet Mask: None\n"
5151
IDS_SUBNETMASK " Subnet Mask: %s\n"
5252
IDS_SUBNETMASKS " Subnet Masks: %s\n"
53-
53+
IDS_DEFAULTGATEWAY " Default Gateway: %s\n"
54+
IDS_GATEWAYMETRIC " Gateway Metric: %s\n"
55+
IDS_INTERFACEMETRIC " Interface Metric: %s\n"
56+
IDS_STATICNAMESERVER " Statically configured DNS Servers: %s\n"
57+
IDS_DHCPNAMESERVER " DNS servers configured through DHCP: %s\n"
5458
IDS_EMPTYLINE " %s\n"
5559

56-
57-
5860
IDS_DUMP_NEWLINE "\n"
5961
IDS_DUMP_HEADERLINE "# ----------------------------------\n"
6062

61-
IDS_DUMP_IP_HEADER "# Interface IP Configuration for ""%s""\n"
62-
63+
IDS_DUMP_IP_HEADER "# Interface IP Configuration\n"
64+
IDS_DUMP_IP_INTERFACE "# Interface IP Configuration for ""%s""\n"
65+
IDS_DUMP_IP_FOOTER "# End of Interface IP Configuration\n"
6366

6467
END

‎dll/win32/ifmon/resource.h‎

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,18 @@
2626
#define IDS_NOSUBNETMASK 306
2727
#define IDS_SUBNETMASK 307
2828
#define IDS_SUBNETMASKS 308
29+
#define IDS_DEFAULTGATEWAY 309
30+
#define IDS_GATEWAYMETRIC 310
31+
#define IDS_INTERFACEMETRIC 311
32+
#define IDS_STATICNAMESERVER 312
33+
#define IDS_DHCPNAMESERVER 313
2934

3035
#define IDS_EMPTYLINE 400
3136

32-
#define IDS_DUMP_NEWLINE 800
33-
#define IDS_DUMP_HEADERLINE 801
34-
#define IDS_DUMP_IP_HEADER 802
37+
#define IDS_DUMP_NEWLINE 800
38+
#define IDS_DUMP_HEADERLINE 801
39+
#define IDS_DUMP_IP_HEADER 802
40+
#define IDS_DUMP_IP_INTERFACE 803
41+
#define IDS_DUMP_IP_FOOTER 804
3542

3643

0 commit comments

Comments
 (0)