mirror of
https://github.com/reactos/reactos.git
synced 2025-08-05 06:22:58 +00:00
[IPHLPAPI] Retrieve DHCP information from the registry
This commit is contained in:
parent
fa7890f39d
commit
3fe4b41f20
3 changed files with 88 additions and 37 deletions
|
@ -9,10 +9,9 @@
|
||||||
#ifndef WINE_DHCP_H_
|
#ifndef WINE_DHCP_H_
|
||||||
#define WINE_DHCP_H_
|
#define WINE_DHCP_H_
|
||||||
|
|
||||||
DWORD getDhcpInfoForAdapter(DWORD AdapterIndex,
|
DWORD
|
||||||
PBOOL DhcpEnabled,
|
getDhcpInfoForAdapter(
|
||||||
PDWORD DhcpServer,
|
DWORD AdapterIndex,
|
||||||
time_t *LeaseObtained,
|
PIP_ADAPTER_INFO ptr);
|
||||||
time_t *LeaseExpires);
|
|
||||||
|
|
||||||
#endif /* ndef WINE_DHCP_H_ */
|
#endif /* ndef WINE_DHCP_H_ */
|
||||||
|
|
|
@ -8,35 +8,94 @@
|
||||||
|
|
||||||
#include "iphlpapi_private.h"
|
#include "iphlpapi_private.h"
|
||||||
|
|
||||||
DWORD APIENTRY DhcpRosGetAdapterInfo(DWORD AdapterIndex,
|
DWORD
|
||||||
PBOOL DhcpEnabled,
|
getDhcpInfoForAdapter(
|
||||||
PDWORD DhcpServer,
|
DWORD AdapterIndex,
|
||||||
time_t *LeaseObtained,
|
PIP_ADAPTER_INFO ptr)
|
||||||
time_t *LeaseExpires);
|
|
||||||
|
|
||||||
DWORD getDhcpInfoForAdapter(DWORD AdapterIndex,
|
|
||||||
PBOOL DhcpEnabled,
|
|
||||||
PDWORD DhcpServer,
|
|
||||||
time_t *LeaseObtained,
|
|
||||||
time_t *LeaseExpires)
|
|
||||||
{
|
{
|
||||||
DWORD Status, Version = 0;
|
const char *ifname = NULL;
|
||||||
|
HKEY hKeyInterfaces = NULL, hKeyInterface = NULL;
|
||||||
|
DWORD dwValue, dwSize, dwType;
|
||||||
|
DWORD ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
Status = DhcpCApiInitialize(&Version);
|
ptr->DhcpEnabled = 0;
|
||||||
if (Status != ERROR_SUCCESS)
|
ptr->LeaseObtained = 0;
|
||||||
|
ptr->LeaseExpires = 0;
|
||||||
|
strcpy(ptr->DhcpServer.IpAddress.String, "");
|
||||||
|
|
||||||
|
ifname = getInterfaceNameByIndex(AdapterIndex);
|
||||||
|
if (!ifname)
|
||||||
|
return ERROR_OUTOFMEMORY;
|
||||||
|
|
||||||
|
ret = RegOpenKeyExW(HKEY_LOCAL_MACHINE,
|
||||||
|
L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces",
|
||||||
|
0,
|
||||||
|
KEY_READ,
|
||||||
|
&hKeyInterfaces);
|
||||||
|
if (ret != ERROR_SUCCESS)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
ret = RegOpenKeyExA(hKeyInterfaces,
|
||||||
|
ifname,
|
||||||
|
0,
|
||||||
|
KEY_READ,
|
||||||
|
&hKeyInterface);
|
||||||
|
if (ret != ERROR_SUCCESS)
|
||||||
|
goto done;
|
||||||
|
|
||||||
|
dwSize = sizeof(ptr->DhcpEnabled);
|
||||||
|
ret = RegQueryValueExW(hKeyInterface,
|
||||||
|
L"EnableDHCP",
|
||||||
|
NULL,
|
||||||
|
&dwType,
|
||||||
|
(PBYTE)&ptr->DhcpEnabled,
|
||||||
|
&dwSize);
|
||||||
|
if (ret != ERROR_SUCCESS)
|
||||||
|
ptr->DhcpEnabled = 0;
|
||||||
|
|
||||||
|
if (ptr->DhcpEnabled != 0)
|
||||||
{
|
{
|
||||||
/* We assume that the DHCP service isn't running yet */
|
dwSize = sizeof(ptr->LeaseObtained);
|
||||||
*DhcpEnabled = FALSE;
|
ret = RegQueryValueExW(hKeyInterface,
|
||||||
*DhcpServer = htonl(INADDR_NONE);
|
L"LeaseObtainedTime",
|
||||||
*LeaseObtained = 0;
|
NULL,
|
||||||
*LeaseExpires = 0;
|
&dwType,
|
||||||
return ERROR_SUCCESS;
|
(PBYTE)&dwValue,
|
||||||
|
&dwSize);
|
||||||
|
if (ret == ERROR_SUCCESS)
|
||||||
|
ptr->LeaseObtained = (time_t)dwValue;
|
||||||
|
|
||||||
|
dwSize = sizeof(dwValue);
|
||||||
|
ret = RegQueryValueExW(hKeyInterface,
|
||||||
|
L"LeaseTerminatesTime",
|
||||||
|
NULL,
|
||||||
|
&dwType,
|
||||||
|
(PBYTE)&dwValue,
|
||||||
|
&dwSize);
|
||||||
|
if (ret == ERROR_SUCCESS)
|
||||||
|
ptr->LeaseExpires = (time_t)dwValue;
|
||||||
|
|
||||||
|
dwSize = sizeof(ptr->DhcpServer.IpAddress.String);
|
||||||
|
ret = RegQueryValueExA(hKeyInterface,
|
||||||
|
"DhcpServer",
|
||||||
|
NULL,
|
||||||
|
&dwType,
|
||||||
|
(PBYTE)&ptr->DhcpServer.IpAddress.String,
|
||||||
|
&dwSize);
|
||||||
|
if (ret != ERROR_SUCCESS)
|
||||||
|
strcpy(ptr->DhcpServer.IpAddress.String, "");
|
||||||
}
|
}
|
||||||
|
ret = ERROR_SUCCESS;
|
||||||
|
|
||||||
Status = DhcpRosGetAdapterInfo(AdapterIndex, DhcpEnabled, DhcpServer,
|
done:
|
||||||
LeaseObtained, LeaseExpires);
|
if (hKeyInterface)
|
||||||
|
RegCloseKey(hKeyInterface);
|
||||||
|
|
||||||
DhcpCApiCleanup();
|
if (hKeyInterfaces)
|
||||||
|
RegCloseKey(hKeyInterfaces);
|
||||||
|
|
||||||
return Status;
|
if (ifname)
|
||||||
|
consumeInterfaceName(ifname);
|
||||||
|
|
||||||
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
|
@ -686,8 +686,6 @@ DWORD WINAPI GetAdapterIndex(LPWSTR AdapterName, PULONG IfIndex)
|
||||||
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
|
DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
|
||||||
{
|
{
|
||||||
DWORD ret;
|
DWORD ret;
|
||||||
BOOL dhcpEnabled;
|
|
||||||
DWORD dhcpServer;
|
|
||||||
|
|
||||||
TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
|
TRACE("pAdapterInfo %p, pOutBufLen %p\n", pAdapterInfo, pOutBufLen);
|
||||||
if (!pOutBufLen)
|
if (!pOutBufLen)
|
||||||
|
@ -771,12 +769,7 @@ DWORD WINAPI GetAdaptersInfo(PIP_ADAPTER_INFO pAdapterInfo, PULONG pOutBufLen)
|
||||||
ptr->IpAddressList.Context = ptr->Index;
|
ptr->IpAddressList.Context = ptr->Index;
|
||||||
toIPAddressString(getInterfaceGatewayByIndex(table->indexes[ndx]),
|
toIPAddressString(getInterfaceGatewayByIndex(table->indexes[ndx]),
|
||||||
ptr->GatewayList.IpAddress.String);
|
ptr->GatewayList.IpAddress.String);
|
||||||
getDhcpInfoForAdapter(table->indexes[ndx], &dhcpEnabled,
|
getDhcpInfoForAdapter(table->indexes[ndx], ptr);
|
||||||
&dhcpServer, &ptr->LeaseObtained,
|
|
||||||
&ptr->LeaseExpires);
|
|
||||||
ptr->DhcpEnabled = (DWORD) dhcpEnabled;
|
|
||||||
toIPAddressString(dhcpServer,
|
|
||||||
ptr->DhcpServer.IpAddress.String);
|
|
||||||
if (winsEnabled) {
|
if (winsEnabled) {
|
||||||
ptr->HaveWins = TRUE;
|
ptr->HaveWins = TRUE;
|
||||||
memcpy(ptr->PrimaryWinsServer.IpAddress.String,
|
memcpy(ptr->PrimaryWinsServer.IpAddress.String,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue