ReactOS 0.4.16-dev-1040-g85afe48
dhcp_reactos.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS Networking
3 * LICENSE: GPL - See COPYING in the top level directory
4 * FILE: lib/iphlpapi/dhcp_reactos.c
5 * PURPOSE: DHCP helper functions for ReactOS
6 * COPYRIGHT: Copyright 2006 Ge van Geldorp <gvg@reactos.org>
7 */
8
9#include "iphlpapi_private.h"
10
13 DWORD AdapterIndex,
15{
16 const char *ifname = NULL;
17 HKEY hKeyInterfaces = NULL, hKeyInterface = NULL;
18 DWORD dwValue, dwSize, dwType;
20
21 ptr->DhcpEnabled = 0;
22 ptr->LeaseObtained = 0;
23 ptr->LeaseExpires = 0;
24 strcpy(ptr->DhcpServer.IpAddress.String, "");
25
26 ifname = getInterfaceNameByIndex(AdapterIndex);
27 if (!ifname)
28 return ERROR_OUTOFMEMORY;
29
31 L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces",
32 0,
34 &hKeyInterfaces);
35 if (ret != ERROR_SUCCESS)
36 goto done;
37
38 ret = RegOpenKeyExA(hKeyInterfaces,
39 ifname,
40 0,
42 &hKeyInterface);
43 if (ret != ERROR_SUCCESS)
44 goto done;
45
46 dwSize = sizeof(ptr->DhcpEnabled);
47 ret = RegQueryValueExW(hKeyInterface,
48 L"EnableDHCP",
49 NULL,
50 &dwType,
51 (PBYTE)&ptr->DhcpEnabled,
52 &dwSize);
53 if (ret != ERROR_SUCCESS)
54 ptr->DhcpEnabled = 0;
55
56 if (ptr->DhcpEnabled != 0)
57 {
58 dwSize = sizeof(ptr->LeaseObtained);
59 ret = RegQueryValueExW(hKeyInterface,
60 L"LeaseObtainedTime",
61 NULL,
62 &dwType,
63 (PBYTE)&dwValue,
64 &dwSize);
65 if (ret == ERROR_SUCCESS)
66 ptr->LeaseObtained = (time_t)dwValue;
67
68 dwSize = sizeof(dwValue);
69 ret = RegQueryValueExW(hKeyInterface,
70 L"LeaseTerminatesTime",
71 NULL,
72 &dwType,
73 (PBYTE)&dwValue,
74 &dwSize);
75 if (ret == ERROR_SUCCESS)
76 ptr->LeaseExpires = (time_t)dwValue;
77
78 dwSize = sizeof(ptr->DhcpServer.IpAddress.String);
79 ret = RegQueryValueExA(hKeyInterface,
80 "DhcpServer",
81 NULL,
82 &dwType,
83 (PBYTE)&ptr->DhcpServer.IpAddress.String,
84 &dwSize);
85 if (ret != ERROR_SUCCESS)
86 strcpy(ptr->DhcpServer.IpAddress.String, "");
87 }
89
90done:
91 if (hKeyInterface)
92 RegCloseKey(hKeyInterface);
93
94 if (hKeyInterfaces)
95 RegCloseKey(hKeyInterfaces);
96
97 if (ifname)
99
100 return ret;
101}
#define RegCloseKey(hKey)
Definition: registry.h:49
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
DWORD getDhcpInfoForAdapter(DWORD AdapterIndex, PIP_ADAPTER_INFO ptr)
Definition: dhcp_reactos.c:12
#define NULL
Definition: types.h:112
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3333
LONG WINAPI RegOpenKeyExA(_In_ HKEY hKey, _In_ LPCSTR lpSubKey, _In_ DWORD ulOptions, _In_ REGSAM samDesired, _Out_ PHKEY phkResult)
Definition: reg.c:3298
LONG WINAPI RegQueryValueExA(_In_ HKEY hkeyorg, _In_ LPCSTR name, _In_ LPDWORD reserved, _Out_opt_ LPDWORD type, _Out_opt_ LPBYTE data, _Inout_opt_ LPDWORD count)
Definition: reg.c:4009
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4103
__kernel_time_t time_t
Definition: linux.h:252
unsigned long DWORD
Definition: ntddk_ex.h:95
const char * getInterfaceNameByIndex(DWORD index)
void consumeInterfaceName(const char *ifname)
PSDBQUERYRESULT_VISTA PVOID DWORD * dwSize
Definition: env.c:56
static PVOID ptr
Definition: dispmode.c:27
#define KEY_READ
Definition: nt_native.h:1023
#define L(x)
Definition: ntvdm.h:50
BYTE * PBYTE
Definition: pedump.c:66
strcpy
Definition: string.h:131
int ret
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12