ReactOS  0.4.13-dev-1148-g9b75b67
resinfo_reactos.c File Reference
#include <config.h>
#include "iphlpapi_private.h"
Include dependency graph for resinfo_reactos.c:

Go to the source code of this file.

Classes

struct  _NAME_SERVER_LIST_PRIVATE
 

Typedefs

typedef struct _NAME_SERVER_LIST_PRIVATE NAME_SERVER_LIST_PRIVATE
 
typedef struct _NAME_SERVER_LIST_PRIVATEPNAME_SERVER_LIST_PRIVATE
 
typedef VOID(* ENUM_INTERFACE_CALLBACK) (HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
 

Functions

 WINE_DEFAULT_DEBUG_CHANNEL (iphlpapi)
 
LSTATUS QueryNameServer (IN HKEY hInterface, IN LPCWSTR NameServerKey, OUT LPWSTR *OutNameServer)
 
LSTATUS EnumNameServers (IN HKEY hInterface, IN LPWSTR InterfaceName, PVOID ServerCallbackContext, EnumNameServersFunc CallbackRoutine)
 
LSTATUS EnumInterfaces (ENUM_INTERFACE_CALLBACK CallbackRoutine, PVOID InterfaceCallbackContext)
 
VOID CountNameServerCallback (IN LPWSTR InterfaceName, IN LPWSTR Server, IN PVOID CallbackContext)
 
VOID CountServerCallbackTrampoline (HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
 
LSTATUS CountNameServers (IN PNAME_SERVER_LIST_PRIVATE PrivateData)
 
VOID CreateNameServerListCallback (IN LPWSTR InterfaceName, IN LPWSTR Server, IN PVOID CallbackContext)
 
VOID CreateNameServerListCallbackTrampoline (HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
 
LSTATUS MakeNameServerList (PNAME_SERVER_LIST_PRIVATE PrivateData)
 
PIPHLP_RES_INFO getResInfo ()
 
VOID disposeResInfo (PIPHLP_RES_INFO InfoPtr)
 

Typedef Documentation

◆ ENUM_INTERFACE_CALLBACK

typedef VOID(* ENUM_INTERFACE_CALLBACK) (HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)

Definition at line 34 of file resinfo_reactos.c.

◆ NAME_SERVER_LIST_PRIVATE

◆ PNAME_SERVER_LIST_PRIVATE

Function Documentation

◆ CountNameServerCallback()

VOID CountNameServerCallback ( IN LPWSTR  InterfaceName,
IN LPWSTR  Server,
IN PVOID  CallbackContext 
)

Definition at line 242 of file resinfo_reactos.c.

246 {
247  /* get context */
249 
250  /* increment server count */
251  Data->NumServers++;
252 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
struct _NAME_SERVER_LIST_PRIVATE * PNAME_SERVER_LIST_PRIVATE

Referenced by CountServerCallbackTrampoline().

◆ CountNameServers()

LSTATUS CountNameServers ( IN PNAME_SERVER_LIST_PRIVATE  PrivateData)

Definition at line 264 of file resinfo_reactos.c.

266 {
267  return EnumInterfaces(CountServerCallbackTrampoline, (PVOID)PrivateData);
268 }
VOID CountServerCallbackTrampoline(HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
LSTATUS EnumInterfaces(ENUM_INTERFACE_CALLBACK CallbackRoutine, PVOID InterfaceCallbackContext)

Referenced by getResInfo().

◆ CountServerCallbackTrampoline()

VOID CountServerCallbackTrampoline ( HKEY  ChildKeyHandle,
LPWSTR  ChildKeyName,
PVOID  CallbackContext 
)

Definition at line 255 of file resinfo_reactos.c.

259 {
260  EnumNameServers(ChildKeyHandle, ChildKeyName, CallbackContext, CountNameServerCallback);
261 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
LSTATUS EnumNameServers(IN HKEY hInterface, IN LPWSTR InterfaceName, PVOID ServerCallbackContext, EnumNameServersFunc CallbackRoutine)
VOID CountNameServerCallback(IN LPWSTR InterfaceName, IN LPWSTR Server, IN PVOID CallbackContext)

Referenced by CountNameServers().

◆ CreateNameServerListCallback()

VOID CreateNameServerListCallback ( IN LPWSTR  InterfaceName,
IN LPWSTR  Server,
IN PVOID  CallbackContext 
)

Definition at line 271 of file resinfo_reactos.c.

275 {
276  /* get context */
278 
279  /* convert to ansi ns string */
280  if (WideCharToMultiByte(CP_ACP, 0, Server, -1, Data->pCurrent->IpAddress.String, 16, NULL, NULL))
281  {
282  /* store offset to next name server struct */
283  Data->pCurrent->Next = (struct _IP_ADDR_STRING*)(Data->pCurrent + 1);
284 
285  /* move to next entry */
286  Data->pCurrent = Data->pCurrent->Next;
287 
288  /* increment server count */
289  Data->NumServers++;
290  }
291  else
292  {
293  /* failed to convert dns server */
294  Data->pCurrent->IpAddress.String[0] = '\0';
295  }
296 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
#define WideCharToMultiByte
Definition: compat.h:101
#define CP_ACP
Definition: compat.h:99
struct _NAME_SERVER_LIST_PRIVATE * PNAME_SERVER_LIST_PRIVATE
static void Server(int port)
Definition: srltest.c:69
smooth NULL
Definition: ftsmooth.c:416

Referenced by CreateNameServerListCallbackTrampoline().

◆ CreateNameServerListCallbackTrampoline()

VOID CreateNameServerListCallbackTrampoline ( HKEY  ChildKeyHandle,
LPWSTR  ChildKeyName,
PVOID  CallbackContext 
)

Definition at line 299 of file resinfo_reactos.c.

303 {
304  EnumNameServers(ChildKeyHandle, ChildKeyName, CallbackContext, CreateNameServerListCallback);
305 }
_IRQL_requires_same_ typedef _In_ ULONG _In_ UCHAR _In_ ULONGLONG _In_ ULONGLONG _In_opt_ PEVENT_FILTER_DESCRIPTOR _Inout_opt_ PVOID CallbackContext
Definition: wmitypes.h:55
VOID CreateNameServerListCallback(IN LPWSTR InterfaceName, IN LPWSTR Server, IN PVOID CallbackContext)
LSTATUS EnumNameServers(IN HKEY hInterface, IN LPWSTR InterfaceName, PVOID ServerCallbackContext, EnumNameServersFunc CallbackRoutine)

Referenced by MakeNameServerList().

◆ disposeResInfo()

VOID disposeResInfo ( PIPHLP_RES_INFO  InfoPtr)

Definition at line 379 of file resinfo_reactos.c.

380 {
381  HeapFree(GetProcessHeap(), 0, InfoPtr->DnsList);
382  RtlFreeHeap( GetProcessHeap(), 0, InfoPtr );
383 }
BOOLEAN NTAPI RtlFreeHeap(IN PVOID HeapHandle, IN ULONG Flags, IN PVOID HeapBase)
Definition: heap.c:606
IP_ADDR_STRING * DnsList
Definition: resinfo.h:26
#define GetProcessHeap()
Definition: compat.h:395
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ EnumInterfaces()

LSTATUS EnumInterfaces ( ENUM_INTERFACE_CALLBACK  CallbackRoutine,
PVOID  InterfaceCallbackContext 
)

Definition at line 164 of file resinfo_reactos.c.

167 {
168  HKEY hKey, hInterface;
169  LSTATUS Status;
170  DWORD NumInterfaces, InterfaceNameLen, Index, Length;
171  LPWSTR InterfaceName;
172 
173  /* first open interface key */
174  Status = RegOpenKeyExW(HKEY_LOCAL_MACHINE, L"SYSTEM\\CurrentControlSet\\Services\\Tcpip\\Parameters\\Interfaces", 0, KEY_READ, &hKey);
175 
176  /* check for success */
177  if (Status != ERROR_SUCCESS)
178  {
179  /* failed to open interface key */
180  return Status;
181  }
182 
183  /* now get maximum interface name length and number of interfaces */
184  Status = RegQueryInfoKeyW(hKey, NULL, NULL, NULL, &NumInterfaces, &InterfaceNameLen, NULL, NULL, NULL, NULL, NULL, NULL);
185  if (Status != ERROR_SUCCESS)
186  {
187  /* failed to get key info */
188  RegCloseKey(hKey);
189  return Status;
190  }
191 
192  /* RegQueryInfoKey does not include terminating null */
193  InterfaceNameLen++;
194 
195  /* allocate interface name */
196  InterfaceName = (LPWSTR) HeapAlloc(GetProcessHeap(), 0, InterfaceNameLen * sizeof(WCHAR));
197 
198  if (!InterfaceName)
199  {
200  /* no memory */
201  RegCloseKey(hKey);
202  return ERROR_OUTOFMEMORY;
203  }
204 
205  /* no enumerate all interfaces */
206  for(Index = 0; Index < NumInterfaces; Index++)
207  {
208  /* query interface name */
209  Length = InterfaceNameLen;
210  Status = RegEnumKeyExW(hKey, Index, InterfaceName, &Length, NULL, NULL, NULL, NULL);
211 
212  if (Status == ERROR_SUCCESS)
213  {
214  /* make sure it is null terminated */
215  InterfaceName[Length] = L'\0';
216 
217  /* now open child key */
218  Status = RegOpenKeyExW(hKey, InterfaceName, 0, KEY_READ, &hInterface);
219 
220  if (Status == ERROR_SUCCESS)
221  {
222  /* perform enumeration callback */
223  CallbackRoutine(hInterface, InterfaceName, InterfaceCallbackContext);
224 
225  /* close interface key */
226  RegCloseKey(hInterface);
227  }
228  }
229  }
230 
231  /* free interface name */
232  HeapFree(GetProcessHeap(), 0, InterfaceName);
233 
234  /* close root interface key */
235  RegCloseKey(hKey);
236 
237  /* done */
238  return Status;
239 }
#define ERROR_SUCCESS
Definition: deptool.c:10
#define KEY_READ
Definition: nt_native.h:1023
_Must_inspect_result_ _In_ PFLT_GET_OPERATION_STATUS_CALLBACK CallbackRoutine
Definition: fltkernel.h:1035
LONG WINAPI RegCloseKey(HKEY hKey)
Definition: reg.c:423
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
static const UCHAR Index[8]
Definition: usbohci.c:18
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
LONG WINAPI RegQueryInfoKeyW(HKEY hKey, LPWSTR lpClass, LPDWORD lpcClass, LPDWORD lpReserved, LPDWORD lpcSubKeys, LPDWORD lpcMaxSubKeyLen, LPDWORD lpcMaxClassLen, LPDWORD lpcValues, LPDWORD lpcMaxValueNameLen, LPDWORD lpcMaxValueLen, LPDWORD lpcbSecurityDescriptor, PFILETIME lpftLastWriteTime)
Definition: reg.c:3686
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
LONG WINAPI RegOpenKeyExW(HKEY hKey, LPCWSTR lpSubKey, DWORD ulOptions, REGSAM samDesired, PHKEY phkResult)
Definition: reg.c:3366
LONG WINAPI RegEnumKeyExW(_In_ HKEY hKey, _In_ DWORD dwIndex, _Out_ LPWSTR lpName, _Inout_ LPDWORD lpcbName, _Reserved_ LPDWORD lpReserved, _Out_opt_ LPWSTR lpClass, _Inout_opt_ LPDWORD lpcbClass, _Out_opt_ PFILETIME lpftLastWriteTime)
Definition: reg.c:2527
WCHAR * LPWSTR
Definition: xmlstorage.h:184
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define HKEY_LOCAL_MACHINE
Definition: winreg.h:12

Referenced by CountNameServers(), and MakeNameServerList().

◆ EnumNameServers()

LSTATUS EnumNameServers ( IN HKEY  hInterface,
IN LPWSTR  InterfaceName,
PVOID  ServerCallbackContext,
EnumNameServersFunc  CallbackRoutine 
)

Definition at line 93 of file resinfo_reactos.c.

98 {
100  LPWSTR NameServer;
101  WCHAR Buffer[50];
102  DWORD Length;
103  LPWSTR Start, Comma;
104 
105  /* query static assigned name server */
106  Status = QueryNameServer(hInterface, L"NameServer", &NameServer);
107  if (Status != ERROR_SUCCESS)
108  {
109  /* query dynamic assigned name server */
110  Status = QueryNameServer(hInterface, L"DhcpNameServer", &NameServer);
111 
112  if (Status != ERROR_SUCCESS)
113  {
114  /* failed to retrieve name servers */
115  return Status;
116  }
117  }
118 
119  /* enumerate all name servers, terminated by comma */
120  Start = NameServer;
121 
122  do
123  {
124  /* find next terminator */
125  Comma = wcschr(Start, L',');
126 
127  if (Comma)
128  {
129  /* calculate length */
130  Length = Comma - Start;
131 
132  /* copy name server */
133  RtlMoveMemory(Buffer, Start, Length * sizeof(WCHAR));
134 
135  /* null terminate it */
136  Buffer[Length] = L'\0';
137 
138  /* perform callback */
139  CallbackRoutine(InterfaceName, Buffer, ServerCallbackContext);
140 
141  }
142  else
143  {
144  /* perform callback */
145  CallbackRoutine(InterfaceName, Start, ServerCallbackContext);
146 
147  /* last entry */
148  break;
149  }
150 
151  /* increment offset */
152  Start = Comma + 1;
153 
154  }while(TRUE);
155 
156  /* free name server string */
157  HeapFree(GetProcessHeap(), 0, NameServer);
158 
159  /* done */
160  return ERROR_SUCCESS;
161 }
#define TRUE
Definition: types.h:120
#define ERROR_SUCCESS
Definition: deptool.c:10
#define RtlMoveMemory(Destination, Source, Length)
Definition: typedefs.h:263
_Must_inspect_result_ _In_ PFLT_GET_OPERATION_STATUS_CALLBACK CallbackRoutine
Definition: fltkernel.h:1035
Definition: bufpool.h:45
#define GetProcessHeap()
Definition: compat.h:395
_CONST_RETURN wchar_t *__cdecl wcschr(_In_z_ const wchar_t *_Str, wchar_t _Ch)
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
Definition: partlist.h:33
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
WCHAR * LPWSTR
Definition: xmlstorage.h:184
LSTATUS QueryNameServer(IN HKEY hInterface, IN LPCWSTR NameServerKey, OUT LPWSTR *OutNameServer)
#define HeapFree(x, y, z)
Definition: compat.h:394

Referenced by CountServerCallbackTrampoline(), and CreateNameServerListCallbackTrampoline().

◆ getResInfo()

PIPHLP_RES_INFO getResInfo ( )

Definition at line 315 of file resinfo_reactos.c.

316 {
317  NAME_SERVER_LIST_PRIVATE PrivateNSEnum;
319  IP_ADDR_STRING * DnsList = NULL;
320  LSTATUS Status;
321 
322  PrivateNSEnum.NumServers = 0;
323 
324  /* count name servers */
325  Status = CountNameServers(&PrivateNSEnum);
326 
327  if (Status != ERROR_SUCCESS)
328  {
329  /* failed to enumerate name servers */
330  return NULL;
331  }
332 
333  /* are there any servers */
334  if (PrivateNSEnum.NumServers)
335  {
336  /* allocate dns servers */
337  DnsList = HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, PrivateNSEnum.NumServers * sizeof(IP_ADDR_STRING));
338 
339  if (!DnsList)
340  {
341  /* no memory */
342  return NULL;
343  }
344  }
345 
346  /* allocate private struct */
348 
349  if(!ResInfo)
350  {
351  /* no memory */
352  if (DnsList)
353  {
354  /* free dns list */
355  HeapFree( GetProcessHeap(), 0, DnsList);
356  }
357  return NULL;
358  }
359 
360  /* are there any servers */
361  if (PrivateNSEnum.NumServers)
362  {
363  /* initialize enumeration context */
364  PrivateNSEnum.NumServers = 0;
365  PrivateNSEnum.pCurrent = DnsList;
366 
367  /* enumerate servers */
368  MakeNameServerList( &PrivateNSEnum );
369 
370  /* store result */
371  ResInfo->DnsList = DnsList;
372  ResInfo->riCount = PrivateNSEnum.NumServers;
373  }
374 
375  /* done */
376  return ResInfo;
377 }
DWORD riCount
Definition: resinfo.h:25
#define ERROR_SUCCESS
Definition: deptool.c:10
LSTATUS MakeNameServerList(PNAME_SERVER_LIST_PRIVATE PrivateData)
struct _IPHLP_RES_INFO * PIPHLP_RES_INFO
IPHLP_RES_INFO ResInfo
Definition: resinfo.c:52
IP_ADDR_STRING * DnsList
Definition: resinfo.h:26
smooth NULL
Definition: ftsmooth.c:416
LSTATUS CountNameServers(IN PNAME_SERVER_LIST_PRIVATE PrivateData)
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
Status
Definition: gdiplustypes.h:24
struct _IPHLP_RES_INFO IPHLP_RES_INFO
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
IP_ADDR_STRING * pCurrent
#define HeapFree(x, y, z)
Definition: compat.h:394

◆ MakeNameServerList()

LSTATUS MakeNameServerList ( PNAME_SERVER_LIST_PRIVATE  PrivateData)

Definition at line 308 of file resinfo_reactos.c.

310 {
312 }
VOID CreateNameServerListCallbackTrampoline(HKEY ChildKeyHandle, LPWSTR ChildKeyName, PVOID CallbackContext)
LSTATUS EnumInterfaces(ENUM_INTERFACE_CALLBACK CallbackRoutine, PVOID InterfaceCallbackContext)

Referenced by getResInfo().

◆ QueryNameServer()

LSTATUS QueryNameServer ( IN HKEY  hInterface,
IN LPCWSTR  NameServerKey,
OUT LPWSTR OutNameServer 
)

Definition at line 40 of file resinfo_reactos.c.

44 {
45  DWORD dwLength, dwType;
46  LPWSTR NameServer;
48 
49  /* query ns */
50  dwLength = 0;
51  Status = RegQueryValueExW(hInterface, NameServerKey, NULL, &dwType, NULL, &dwLength);
52 
53  if (Status != ERROR_SUCCESS)
54  {
55  /* failed to retrieve size */
56  TRACE("Status %x\n", Status);
57  return Status;
58  }
59 
60  /* add terminating null */
61  dwLength += sizeof(WCHAR);
62 
63  /* allocate name server */
64  NameServer = HeapAlloc(GetProcessHeap(), 0, dwLength);
65 
66  if (!NameServer)
67  {
68  /* no memory */
69  return ERROR_OUTOFMEMORY;
70  }
71 
72  /* query ns */
73  Status = RegQueryValueExW(hInterface, NameServerKey, NULL, &dwType, (LPBYTE)NameServer, &dwLength);
74 
75  if (Status != ERROR_SUCCESS || dwType != REG_SZ)
76  {
77  /* failed to retrieve ns */
78  HeapFree(GetProcessHeap(), 0, NameServer);
79  return Status;
80  }
81 
82  /* null terminate it */
83  NameServer[dwLength / sizeof(WCHAR)] = L'\0';
84 
85  /* store result */
86  *OutNameServer = NameServer;
87 
88  return STATUS_SUCCESS;
89 }
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned char * LPBYTE
Definition: typedefs.h:52
smooth NULL
Definition: ftsmooth.c:416
#define TRACE(s)
Definition: solgame.cpp:4
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
LONG WINAPI RegQueryValueExW(_In_ HKEY hkeyorg, _In_ LPCWSTR name, _In_ LPDWORD reserved, _In_ LPDWORD type, _In_ LPBYTE data, _In_ LPDWORD count)
Definition: reg.c:4116
__wchar_t WCHAR
Definition: xmlstorage.h:180
static DWORD DWORD * dwLength
Definition: fusion.c:83
unsigned long DWORD
Definition: ntddk_ex.h:95
static LSTATUS(WINAPI *pRegDeleteTreeW)(HKEY
static const WCHAR L[]
Definition: oid.c:1250
Status
Definition: gdiplustypes.h:24
WCHAR * LPWSTR
Definition: xmlstorage.h:184
return STATUS_SUCCESS
Definition: btrfs.c:2966
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define REG_SZ
Definition: layer.c:22

Referenced by EnumNameServers().

◆ WINE_DEFAULT_DEBUG_CHANNEL()

WINE_DEFAULT_DEBUG_CHANNEL ( iphlpapi  )