mirror of
https://github.com/ApfelTeeSaft/reactos.git
synced 2026-08-26 19:33:31 +00:00
[IFMON] Add the winsock helper and clean up the function declarations
This commit is contained in:
@@ -7,6 +7,7 @@ list(APPEND SOURCE
|
||||
ifmon.rc
|
||||
interface.c
|
||||
ip.c
|
||||
winsock.c
|
||||
${CMAKE_CURRENT_BINARY_DIR}/ifmon.def)
|
||||
|
||||
add_library(ifmon MODULE ${SOURCE})
|
||||
|
||||
@@ -2,4 +2,4 @@
|
||||
DEFINE_GUID(GUID_IFMON_INTERFACE, 0x0705eca1, 0x7aac, 0x11d2, 0x89, 0xdc, 0x00, 0x60, 0x08, 0xb0, 0xe5, 0xb9);
|
||||
//DEFINE_GUID(GUID_IFMON_INTERFACE, 0x0705ECB2, 0x7AAC, 0x11D2, 0x89, 0xDC, 0x00, 0x60, 0x08, 0xB0, 0xE5, 0xB9);
|
||||
DEFINE_GUID(GUID_IFMON_IP, 0x725588AC, 0x7A11, 0x4220, 0xA1, 0x21, 0xC9, 0x2C, 0x91, 0x5E, 0x8B, 0x73);
|
||||
|
||||
DEFINE_GUID(GUID_IFMON_WINSOCK, 0xB2C0EEF4, 0xCCE5, 0x4F55, 0x93, 0x4E, 0xAB, 0xF6, 0x0F, 0x3D, 0xCF, 0x56);
|
||||
|
||||
@@ -26,6 +26,8 @@ InitHelperDll(
|
||||
dwError = RegisterInterfaceHelper();
|
||||
if (dwError == ERROR_SUCCESS)
|
||||
dwError = RegisterIpHelper();
|
||||
if (dwError == ERROR_SUCCESS)
|
||||
dwError = RegisterWinsockHelper();
|
||||
|
||||
return dwError;
|
||||
}
|
||||
|
||||
@@ -15,17 +15,7 @@
|
||||
#include "guid.h"
|
||||
#include "resource.h"
|
||||
|
||||
static
|
||||
DWORD
|
||||
WINAPI
|
||||
InterfaceShowInterface(
|
||||
LPCWSTR pwszMachine,
|
||||
LPWSTR *argv,
|
||||
DWORD dwCurrentIndex,
|
||||
DWORD dwArgCount,
|
||||
DWORD dwFlags,
|
||||
LPCVOID pvData,
|
||||
BOOL *pbDone);
|
||||
static FN_HANDLE_CMD InterfaceShowInterface;
|
||||
|
||||
static
|
||||
CMD_ENTRY
|
||||
|
||||
+43
-47
@@ -18,41 +18,10 @@
|
||||
#define DISPLAY_ADRESSES 0x1
|
||||
#define DISPLAY_DNS 0x2
|
||||
|
||||
static
|
||||
DWORD
|
||||
WINAPI
|
||||
IpShowAddresses(
|
||||
LPCWSTR pwszMachine,
|
||||
LPWSTR *argv,
|
||||
DWORD dwCurrentIndex,
|
||||
DWORD dwArgCount,
|
||||
DWORD dwFlags,
|
||||
LPCVOID pvData,
|
||||
BOOL *pbDone);
|
||||
|
||||
static
|
||||
DWORD
|
||||
WINAPI
|
||||
IpShowConfig(
|
||||
LPCWSTR pwszMachine,
|
||||
LPWSTR *argv,
|
||||
DWORD dwCurrentIndex,
|
||||
DWORD dwArgCount,
|
||||
DWORD dwFlags,
|
||||
LPCVOID pvData,
|
||||
BOOL *pbDone);
|
||||
|
||||
static
|
||||
DWORD
|
||||
WINAPI
|
||||
IpShowDns(
|
||||
LPCWSTR pwszMachine,
|
||||
LPWSTR *argv,
|
||||
DWORD dwCurrentIndex,
|
||||
DWORD dwArgCount,
|
||||
DWORD dwFlags,
|
||||
LPCVOID pvData,
|
||||
BOOL *pbDone);
|
||||
static FN_HANDLE_CMD IpShowAddresses;
|
||||
static FN_HANDLE_CMD IpShowConfig;
|
||||
static FN_HANDLE_CMD IpShowDns;
|
||||
|
||||
|
||||
static
|
||||
@@ -90,6 +59,24 @@ FormatIPv4Address(
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
BOOL
|
||||
FormatIPv4NetMask(
|
||||
_Out_ PWCHAR pBuffer,
|
||||
_In_ ULONG PrefixLength)
|
||||
{
|
||||
ULONG i;
|
||||
IN_ADDR NetMask;
|
||||
|
||||
NetMask.S_un.S_addr = 0;
|
||||
for (i = 0; i < PrefixLength; i++)
|
||||
NetMask.S_un.S_addr = NetMask.S_un.S_addr | (1 << (31 - i));
|
||||
|
||||
RtlIpv4AddressToStringW(&NetMask, pBuffer);
|
||||
return TRUE;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
DWORD
|
||||
IpShowAdapters(
|
||||
@@ -100,7 +87,7 @@ IpShowAdapters(
|
||||
PIP_ADAPTER_UNICAST_ADDRESS pUnicastAddress;
|
||||
PIP_ADAPTER_PREFIX pPrefix;
|
||||
PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsServer;
|
||||
WCHAR IpBuffer[17];
|
||||
WCHAR IpBuffer[17], MaskBuffer[17];
|
||||
BOOL First;
|
||||
ULONG adaptOutBufLen = 15000;
|
||||
DWORD Error = ERROR_SUCCESS;
|
||||
@@ -117,13 +104,13 @@ IpShowAdapters(
|
||||
Error = GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen);
|
||||
if (Error == ERROR_BUFFER_OVERFLOW)
|
||||
{
|
||||
free(pAdapterAddresses);
|
||||
pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen);
|
||||
if (pAdapterAddresses == NULL)
|
||||
{
|
||||
Error = ERROR_NOT_ENOUGH_MEMORY;
|
||||
goto done;
|
||||
}
|
||||
free(pAdapterAddresses);
|
||||
pAdapterAddresses = (PIP_ADAPTER_ADDRESSES)malloc(adaptOutBufLen);
|
||||
if (pAdapterAddresses == NULL)
|
||||
{
|
||||
Error = ERROR_NOT_ENOUGH_MEMORY;
|
||||
goto done;
|
||||
}
|
||||
}
|
||||
|
||||
Error = GetAdaptersAddresses(AF_INET, Flags, NULL, pAdapterAddresses, &adaptOutBufLen);
|
||||
@@ -153,6 +140,8 @@ IpShowAdapters(
|
||||
{
|
||||
if (FormatIPv4Address(IpBuffer, &pUnicastAddress->Address))
|
||||
{
|
||||
PrintMessageFromModule(hDllInstance, IDS_IPADDRESS, IpBuffer);
|
||||
#if 0
|
||||
if (First)
|
||||
{
|
||||
PrintMessageFromModule(hDllInstance, (pUnicastAddress->Next)? IDS_IPADDRESSES : IDS_IPADDRESS, IpBuffer);
|
||||
@@ -162,6 +151,7 @@ IpShowAdapters(
|
||||
PrintMessageFromModule(hDllInstance, IDS_EMPTYLINE, IpBuffer);
|
||||
}
|
||||
First = FALSE;
|
||||
#endif
|
||||
}
|
||||
|
||||
pUnicastAddress = pUnicastAddress->Next;
|
||||
@@ -178,22 +168,27 @@ IpShowAdapters(
|
||||
pPrefix = Ptr->FirstPrefix;
|
||||
while (pPrefix)
|
||||
{
|
||||
FormatIPv4NetMask(MaskBuffer, pPrefix->PrefixLength);
|
||||
PrintMessage(L" SubnetMask: %s\n", MaskBuffer);
|
||||
#if 0
|
||||
if (FormatIPv4Address(IpBuffer, &pPrefix->Address))
|
||||
{
|
||||
FormatIPv4NetMask(MaskBuffer, pPrefix->PrefixLength);
|
||||
|
||||
if (First)
|
||||
{
|
||||
if (pPrefix->Next)
|
||||
PrintMessage(L" SubnetMasks: %s/%lu\n", IpBuffer, pPrefix->PrefixLength);
|
||||
PrintMessage(L" SubnetMasks: %s/%lu (Mask: %s)\n", IpBuffer, pPrefix->PrefixLength, MaskBuffer);
|
||||
else
|
||||
PrintMessage(L" IP Address: %s/%lu\n", IpBuffer, pPrefix->PrefixLength);
|
||||
PrintMessage(L" SubnetMask: %s/%lu (Mask: %s)\n", IpBuffer, pPrefix->PrefixLength, MaskBuffer);
|
||||
}
|
||||
else
|
||||
{
|
||||
PrintMessage(L" %s/%lu\n", IpBuffer, pPrefix->PrefixLength);
|
||||
PrintMessage(L" %s/%lu (Mask: %s)\n", IpBuffer, pPrefix->PrefixLength, MaskBuffer);
|
||||
}
|
||||
First = FALSE;
|
||||
}
|
||||
|
||||
#endif
|
||||
pPrefix = pPrefix->Next;
|
||||
}
|
||||
}
|
||||
@@ -339,10 +334,11 @@ IpDumpFn(
|
||||
{
|
||||
PIP_ADAPTER_ADDRESSES pAdapterAddresses = NULL, Ptr;
|
||||
PIP_ADAPTER_UNICAST_ADDRESS pUnicastAddress;
|
||||
// PIP_ADAPTER_PREFIX pPrefix;
|
||||
PIP_ADAPTER_DNS_SERVER_ADDRESS pDnsServer;
|
||||
WCHAR AddressBuffer[17], MaskBuffer[17];
|
||||
ULONG adaptOutBufLen = 15000;
|
||||
ULONG Flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST;
|
||||
ULONG Flags = GAA_FLAG_SKIP_ANYCAST | GAA_FLAG_SKIP_MULTICAST | GAA_FLAG_INCLUDE_PREFIX;
|
||||
DWORD Error = ERROR_SUCCESS;
|
||||
|
||||
DPRINT("IpDumpFn(%S %p %lu %p)\n", pwszRouter, ppwcArguments, dwArgCount, pvData);
|
||||
|
||||
@@ -28,11 +28,19 @@ Examples:\n\n\
|
||||
Parameters:\n\n\
|
||||
Tag Value\n\
|
||||
name The name of a specific interface.\n\n\
|
||||
Remarks:\n\n\
|
||||
Displays the DNS server configuration for a specific interface\nor interfaces.\n\n\
|
||||
Remarks: Displays the DNS server configuration for a specific interface\nor interfaces.\n\n\
|
||||
Examples:\n\n\
|
||||
%1!s! ""Local Area Network""\n"
|
||||
|
||||
IDS_HLP_WINSOCK_RESET "Resets the Winsock Catalog to a clean state.\n"
|
||||
IDS_HLP_WINSOCK_RESET_EX "\nUsage: %1!s!\n\n\
|
||||
Remarks: Resets the Winsock Catalog to a clean state.\n"
|
||||
IDS_HLP_WINSOCK_SHOW "Displays information.\n"
|
||||
IDS_HLP_WINSOCK_SHOW_CATALOG "Displays contents of Winsock Catalog.\n"
|
||||
IDS_HLP_WINSOCK_SHOW_CATALOG_EX "\nUsage: %1!s! [[type=]full]\n\n\
|
||||
Parameters:\n\n\
|
||||
\n"
|
||||
|
||||
IDS_IP_HEADER "\nConfiguration for interface ""%s""\n"
|
||||
IDS_DHCP_ON " DHCP enabled: Yes\n"
|
||||
IDS_DHCP_OFF " DHCP enabled: No\n"
|
||||
|
||||
@@ -33,4 +33,8 @@ DWORD
|
||||
WINAPI
|
||||
RegisterIpHelper(VOID);
|
||||
|
||||
DWORD
|
||||
WINAPI
|
||||
RegisterWinsockHelper(VOID);
|
||||
|
||||
#endif /* PRECOMP_H */
|
||||
|
||||
@@ -11,6 +11,12 @@
|
||||
#define IDS_HLP_DNS 215
|
||||
#define IDS_HLP_DNS_EX 216
|
||||
|
||||
#define IDS_HLP_WINSOCK_RESET 230
|
||||
#define IDS_HLP_WINSOCK_RESET_EX 231
|
||||
#define IDS_HLP_WINSOCK_SHOW 232
|
||||
#define IDS_HLP_WINSOCK_SHOW_CATALOG 233
|
||||
#define IDS_HLP_WINSOCK_SHOW_CATALOG_EX 234
|
||||
|
||||
#define IDS_IP_HEADER 300
|
||||
#define IDS_DHCP_ON 301
|
||||
#define IDS_DHCP_OFF 302
|
||||
@@ -26,3 +32,5 @@
|
||||
#define IDS_DUMP_NEWLINE 800
|
||||
#define IDS_DUMP_HEADERLINE 801
|
||||
#define IDS_DUMP_IP_HEADER 802
|
||||
|
||||
|
||||
|
||||
@@ -0,0 +1,116 @@
|
||||
/*
|
||||
* PROJECT: ReactOS IF Monitor DLL
|
||||
* LICENSE: GPL-2.0-or-later (https://spdx.org/licenses/GPL-2.0-or-later)
|
||||
* PURPOSE: NetSh Helper interface context functions
|
||||
* COPYRIGHT: Copyright 2025 Eric Kohl <[email protected]>
|
||||
*/
|
||||
|
||||
#include "precomp.h"
|
||||
|
||||
#include <guiddef.h>
|
||||
|
||||
#define NDEBUG
|
||||
#include <debug.h>
|
||||
|
||||
#include "guid.h"
|
||||
#include "resource.h"
|
||||
|
||||
static FN_HANDLE_CMD ResetCommand;
|
||||
static FN_HANDLE_CMD ShowCatalogCommand;
|
||||
|
||||
static
|
||||
CMD_ENTRY g_TestCmdTable[] =
|
||||
{
|
||||
{L"reset", ResetCommand, IDS_HLP_WINSOCK_RESET, IDS_HLP_WINSOCK_RESET_EX, 0}
|
||||
};
|
||||
|
||||
static
|
||||
CMD_ENTRY g_WinsockShowCmdTable[] =
|
||||
{
|
||||
{L"catalog", ShowCatalogCommand, IDS_HLP_WINSOCK_SHOW_CATALOG, IDS_HLP_WINSOCK_SHOW_CATALOG_EX, 0}
|
||||
};
|
||||
|
||||
static
|
||||
CMD_GROUP_ENTRY g_WinsockGroupCmds[] =
|
||||
{
|
||||
{L"show", IDS_HLP_WINSOCK_SHOW, sizeof(g_WinsockShowCmdTable)/sizeof(CMD_ENTRY), 0, g_WinsockShowCmdTable, NULL},
|
||||
};
|
||||
|
||||
|
||||
static
|
||||
DWORD
|
||||
WINAPI
|
||||
ResetCommand(
|
||||
LPCWSTR pwszMachine,
|
||||
LPWSTR *argv,
|
||||
DWORD dwCurrentIndex,
|
||||
DWORD dwArgCount,
|
||||
DWORD dwFlags,
|
||||
LPCVOID pvData,
|
||||
BOOL *pbDone)
|
||||
{
|
||||
PrintMessage(L"ResetCommand(): Not implemented yet!\n");
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
DWORD
|
||||
WINAPI
|
||||
ShowCatalogCommand(
|
||||
LPCWSTR pwszMachine,
|
||||
LPWSTR *argv,
|
||||
DWORD dwCurrentIndex,
|
||||
DWORD dwArgCount,
|
||||
DWORD dwFlags,
|
||||
LPCVOID pvData,
|
||||
BOOL *pbDone)
|
||||
{
|
||||
PrintMessage(L"ShowCatalogCommand(): Not implemented yet!\n");
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
static
|
||||
DWORD
|
||||
WINAPI
|
||||
WinsockStart(
|
||||
_In_ const GUID *pguidParent,
|
||||
_In_ DWORD dwVersion)
|
||||
{
|
||||
NS_CONTEXT_ATTRIBUTES ContextAttributes;
|
||||
|
||||
DPRINT1("WinsockStart()\n");
|
||||
|
||||
ZeroMemory(&ContextAttributes, sizeof(ContextAttributes));
|
||||
ContextAttributes.dwVersion = 1;
|
||||
ContextAttributes.pwszContext = L"winsock";
|
||||
ContextAttributes.guidHelper = GUID_IFMON_WINSOCK;
|
||||
|
||||
ContextAttributes.ulNumTopCmds = 1;
|
||||
ContextAttributes.pTopCmds = g_TestCmdTable;
|
||||
|
||||
ContextAttributes.ulNumGroups = 1;
|
||||
ContextAttributes.pCmdGroups = g_WinsockGroupCmds;
|
||||
|
||||
RegisterContext(&ContextAttributes);
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
|
||||
|
||||
DWORD
|
||||
WINAPI
|
||||
RegisterWinsockHelper(VOID)
|
||||
{
|
||||
NS_HELPER_ATTRIBUTES HelperAttributes;
|
||||
|
||||
ZeroMemory(&HelperAttributes, sizeof(HelperAttributes));
|
||||
HelperAttributes.dwVersion = 1;
|
||||
HelperAttributes.guidHelper = GUID_IFMON_WINSOCK;
|
||||
HelperAttributes.pfnStart = WinsockStart;
|
||||
HelperAttributes.pfnStop = NULL;
|
||||
RegisterHelper(NULL, &HelperAttributes);
|
||||
|
||||
return ERROR_SUCCESS;
|
||||
}
|
||||
Reference in New Issue
Block a user