tangled
alpha
login
or
join now
huwcampbell.com
/
reactos
0
fork
atom
Reactos
0
fork
atom
overview
issues
pulls
pipelines
[IFMON] Implement a basic dump functionality
Eric Kohl
5 months ago
82aaf156
d0333017
+164
-2
4 changed files
expand all
collapse all
unified
split
dll
win32
ifmon
interface.c
ip.c
lang
en-US.rc
resource.h
+31
-2
dll/win32/ifmon/interface.c
···
60
60
}
61
61
62
62
63
63
+
static
64
64
+
DWORD
65
65
+
WINAPI
66
66
+
InterfaceDumpFn(
67
67
+
_In_ LPCWSTR pwszRouter,
68
68
+
_In_ LPWSTR *ppwcArguments,
69
69
+
_In_ DWORD dwArgCount,
70
70
+
_In_ LPCVOID pvData)
71
71
+
{
72
72
+
DPRINT("InterfaceDumpFn(%S %p %lu %p)\n", pwszRouter, ppwcArguments, dwArgCount, pvData);
73
73
+
74
74
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE);
75
75
+
PrintMessage(L"# Interface Configuration\n");
76
76
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE);
77
77
+
PrintMessage(L"pushd\n");
78
78
+
PrintMessage(L"interface\n");
79
79
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
80
80
+
81
81
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
82
82
+
PrintMessage(L"popd\n");
83
83
+
PrintMessage(L"# End of Interface Configuration\n");
84
84
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
85
85
+
86
86
+
return ERROR_SUCCESS;
87
87
+
}
88
88
+
89
89
+
63
90
DWORD
64
91
WINAPI
65
92
InterfaceStart(
···
68
95
{
69
96
NS_CONTEXT_ATTRIBUTES ContextAttributes;
70
97
71
71
-
DPRINT1("InterfaceStart()\n");
98
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
111
+
ContextAttributes.pfnDumpFn = InterfaceDumpFn;
112
112
+
84
113
RegisterContext(&ContextAttributes);
85
114
86
115
return ERROR_SUCCESS;
···
93
122
{
94
123
NS_HELPER_ATTRIBUTES HelperAttributes;
95
124
96
96
-
DPRINT1("RegisterInterfaceHelper()\n");
125
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
334
+
IpDumpFn(
335
335
+
_In_ LPCWSTR pwszRouter,
336
336
+
_In_ LPWSTR *ppwcArguments,
337
337
+
_In_ DWORD dwArgCount,
338
338
+
_In_ LPCVOID pvData)
339
339
+
{
340
340
+
PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL, Ptr;
341
341
+
PIP_ADAPTER_UNICAST_ADDRESS pUnicastAddress;
342
342
+
PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsServer;
343
343
+
WCHAR AddressBuffer[17], MaskBuffer[17];
344
344
+
ULONG adaptOutBufLen = 15000;
345
345
+
ULONG Flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST;
346
346
+
DWORD Error = ERROR_SUCCESS;
347
347
+
348
348
+
DPRINT("IpDumpFn(%S %p %lu %p)\n", pwszRouter, ppwcArguments, dwArgCount, pvData);
349
349
+
350
350
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE);
351
351
+
PrintMessage(L"# Interface IP Configuration\n");
352
352
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_HEADERLINE);
353
353
+
PrintMessage(L"pushd\n");
354
354
+
PrintMessage(L"interface ip\n");
355
355
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
356
356
+
357
357
+
/* set required buffer size */
358
358
+
pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen);
359
359
+
if (pAdapterAddresses == NULL)
360
360
+
{
361
361
+
Error = ERROR_NOT_ENOUGH_MEMORY;
362
362
+
goto done;
363
363
+
}
364
364
+
365
365
+
Error = GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen);
366
366
+
if (Error == ERROR_BUFFER_OVERFLOW)
367
367
+
{
368
368
+
free(pAdapterAddresses);
369
369
+
pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen);
370
370
+
if (pAdapterAddresses == NULL)
371
371
+
{
372
372
+
Error = ERROR_NOT_ENOUGH_MEMORY;
373
373
+
goto done;
374
374
+
}
375
375
+
}
376
376
+
377
377
+
Error = GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen);
378
378
+
if (Error != ERROR_SUCCESS)
379
379
+
goto done;
380
380
+
381
381
+
Ptr = pAdapterAddresses;
382
382
+
while (Ptr)
383
383
+
{
384
384
+
if (Ptr->IfType != IF_TYPE_SOFTWARE_LOOPBACK)
385
385
+
{
386
386
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
387
387
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_IP_HEADER, Ptr->FriendlyName);
388
388
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
389
389
+
390
390
+
if (Ptr->Flags & IP_ADAPTER_DHCP_ENABLED)
391
391
+
{
392
392
+
PrintMessage(L"set address name=\"%s\" source=dhcp\n",
393
393
+
Ptr->FriendlyName);
394
394
+
}
395
395
+
else
396
396
+
{
397
397
+
pUnicastAddress = Ptr->FirstUnicastAddress;
398
398
+
while (pUnicastAddress)
399
399
+
{
400
400
+
FormatIPv4Address(AddressBuffer, &pUnicastAddress->Address);
401
401
+
wcscpy(MaskBuffer, L"?");
402
402
+
403
403
+
PrintMessage(L"set address name=\"%s\" source=static address=%s mask=%s\n",
404
404
+
Ptr->FriendlyName, AddressBuffer, MaskBuffer);
405
405
+
406
406
+
pUnicastAddress = pUnicastAddress->Next;
407
407
+
}
408
408
+
}
409
409
+
410
410
+
if (Ptr->Flags & IP_ADAPTER_DHCP_ENABLED)
411
411
+
{
412
412
+
PrintMessage(L"set dns name=\"%s\" source=dhcp\n",
413
413
+
Ptr->FriendlyName);
414
414
+
}
415
415
+
else
416
416
+
{
417
417
+
pDnsServer = Ptr->FirstDnsServerAddress;
418
418
+
while (pDnsServer)
419
419
+
{
420
420
+
FormatIPv4Address(AddressBuffer, &pDnsServer->Address);
421
421
+
422
422
+
PrintMessage(L"set dns name=\"%s\" source=%s address=%s\n",
423
423
+
Ptr->FriendlyName);
424
424
+
425
425
+
pDnsServer = pDnsServer->Next;
426
426
+
}
427
427
+
428
428
+
}
429
429
+
430
430
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
431
431
+
}
432
432
+
433
433
+
Ptr = Ptr->Next;
434
434
+
}
435
435
+
436
436
+
done:
437
437
+
if (pAdapterAddresses)
438
438
+
free(pAdapterAddresses);
439
439
+
440
440
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
441
441
+
PrintMessage(L"popd\n");
442
442
+
PrintMessage(L"# End of Interface IP Configuration\n");
443
443
+
PrintMessageFromModule(hDllInstance, IDS_DUMP_NEWLINE);
444
444
+
445
445
+
return ERROR_SUCCESS;
446
446
+
}
447
447
+
448
448
+
449
449
+
static
450
450
+
DWORD
451
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
470
+
471
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
28
+
29
29
+
30
30
+
31
31
+
IDS_DUMP_NEWLINE "\n"
32
32
+
IDS_DUMP_HEADERLINE "# ----------------------------------\n"
33
33
+
34
34
+
IDS_DUMP_IP_HEADER "# Interface IP Configuration for ""%s""\n"
35
35
+
36
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
25
+
26
26
+
#define IDS_DUMP_NEWLINE 800
27
27
+
#define IDS_DUMP_HEADERLINE 801
28
28
+
#define IDS_DUMP_IP_HEADER 802