ReactOS 0.4.15-dev-5667-ged97270
GetInterfaceName.c File Reference
#include <apitest.h>
#include <iphlpapi.h>
#include <ndk/rtlfuncs.h>
#include <initguid.h>
Include dependency graph for GetInterfaceName.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

 DEFINE_GUID (MY_TEST_GUID, 0x8D1AB70F, 0xADF0, 0x49FC, 0x9D, 0x07, 0x4E, 0x89, 0x29, 0x2D, 0xC5, 0x2B)
 
static DWORD (WINAPI *pNhGetInterfaceNameFromGuid)(PVOID
 
static VOID test_NhGetInterfaceNameFromGuid (GUID AdapterGUID, DWORD par1, DWORD par2)
 
static VOID test_NhGetInterfaceNameFromDeviceGuid (GUID AdapterGUID, DWORD par1, DWORD par2)
 
static VOID test_GetInterfaceName (VOID)
 
 START_TEST (GetInterfaceName)
 

Variables

static PVOID
 
static PULONG
 
static DWORD
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetInterfaceName.c.

Function Documentation

◆ DEFINE_GUID()

DEFINE_GUID ( MY_TEST_GUID  ,
0x8D1AB70F  ,
0xADF0  ,
0x49FC  ,
0x9D  ,
0x07  ,
0x4E  ,
0x89  ,
0x29  ,
0x2D  ,
0xC5  ,
0x2B   
)

◆ DWORD()

static DWORD ( WINAPI pNhGetInterfaceNameFromGuid)
static

◆ START_TEST()

START_TEST ( GetInterfaceName  )

Definition at line 394 of file GetInterfaceName.c.

395{
397}
static VOID test_GetInterfaceName(VOID)

◆ test_GetInterfaceName()

static VOID test_GetInterfaceName ( VOID  )
static

Definition at line 292 of file GetInterfaceName.c.

293{
294 PIP_INTERFACE_INFO pInfo = NULL;
295 ULONG ulOutBufLen = 0;
296 DWORD ApiReturn;
299 GUID AdapterGUID;
300 HINSTANCE hIpHlpApi;
301
302 ApiReturn = GetInterfaceInfo(pInfo, &ulOutBufLen);
303 ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER,
304 "GetInterfaceInfo(pInfo, &ulOutBufLen) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
305 ApiReturn);
306 if (ApiReturn != ERROR_INSUFFICIENT_BUFFER)
307 {
308 skip("Can't determine size of IP_INTERFACE_INFO. Can't proceed\n");
309 return;
310 }
311
313 if (pInfo == NULL)
314 {
315 skip("pInfo is NULL. Can't proceed\n");
316 return;
317 }
318
319 ApiReturn = GetInterfaceInfo(pInfo, &ulOutBufLen);
320 ok(ApiReturn == NO_ERROR,
321 "GetInterfaceInfo(pInfo, &ulOutBufLen) returned %ld, expected NO_ERROR\n",
322 ApiReturn);
323 if (ApiReturn != NO_ERROR || ulOutBufLen == 0)
324 {
325 skip("GetInterfaceInfo failed with error %ld. Can't proceed\n", ApiReturn);
326 return;
327 }
328
329 if (pInfo->NumAdapters > 0)
330 CopyMemory(&Name, &pInfo->Adapter[0].Name, sizeof(Name));
331
332 if (pInfo->NumAdapters == 0)
333 {
334 HeapFree(GetProcessHeap(), 0, pInfo);
335 skip("pInfo->NumAdapters = 0. Can't proceed\n");
336 return;
337 }
338 trace("pInfo->NumAdapters: %lu\n", pInfo->NumAdapters);
339
340 HeapFree(GetProcessHeap(), 0, pInfo);
341
342 ApiReturn = wcsncmp(Name, L"\\DEVICE\\TCPIP_", 14);
343 ok(ApiReturn == 0,
344 "wcsncmp(Name, L\"\\DEVICE\\TCPIP_\", 14) returned %ld, expected 0\n",
345 ApiReturn);
346 if (ApiReturn != 0)
347 {
348 if (wcslen(Name) == 0)
349 {
350 skip("pInfo->Adapter[0].Name is empty. Can't proceed\n");
351 return;
352 }
353 else
354 {
355 // workaround for ReactOS
356 trace("pInfo->Adapter[0].Name = \"%ls\" is incorrect.\n", Name);
358 }
359 }
360 else
361 {
363 }
364
365 ApiReturn = RtlGUIDFromString(&GuidString, &AdapterGUID);
366 if (ApiReturn != 0)
367 {
368 skip("RtlGUIDFromString failed. Can't proceed\n");
369 return;
370 }
371
372 hIpHlpApi = GetModuleHandleW(L"iphlpapi.dll");
373 if (!hIpHlpApi)
374 {
375 skip("Failed to load iphlpapi.dll. Can't proceed\n");
376 return;
377 }
378
379 pNhGetInterfaceNameFromGuid = (void *)GetProcAddress(hIpHlpApi, "NhGetInterfaceNameFromGuid");
380
381 if (!pNhGetInterfaceNameFromGuid)
382 skip("NhGetInterfaceNameFromGuid not found. Can't proceed\n");
383 else
384 test_NhGetInterfaceNameFromGuid(AdapterGUID, 0, 0);
385
386 pNhGetInterfaceNameFromDeviceGuid = (void *)GetProcAddress(hIpHlpApi, "NhGetInterfaceNameFromDeviceGuid");
387
388 if (!pNhGetInterfaceNameFromDeviceGuid)
389 skip("NhGetInterfaceNameFromDeviceGuid not found. Can't proceed\n");
390 else
391 test_NhGetInterfaceNameFromDeviceGuid(AdapterGUID, 1, 0);
392}
static VOID test_NhGetInterfaceNameFromDeviceGuid(GUID AdapterGUID, DWORD par1, DWORD par2)
static VOID test_NhGetInterfaceNameFromGuid(GUID AdapterGUID, DWORD par1, DWORD par2)
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define GetProcAddress(x, y)
Definition: compat.h:753
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
unsigned long DWORD
Definition: ntddk_ex.h:95
_CRTIMP size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
NTSYSAPI NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING, GUID *)
#define MAX_ADAPTER_NAME
Definition: ipexport.h:143
DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
static PWSTR GuidString
Definition: apphelp.c:93
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl wcsncmp(_In_reads_or_z_(_MaxCount) const wchar_t *_Str1, _In_reads_or_z_(_MaxCount) const wchar_t *_Str2, _In_ size_t _MaxCount)
WCHAR Name[MAX_ADAPTER_NAME]
Definition: ipexport.h:147
IP_ADAPTER_INDEX_MAP Adapter[1]
Definition: ipexport.h:152
uint32_t ULONG
Definition: typedefs.h:59
#define CopyMemory
Definition: winbase.h:1668
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by START_TEST().

◆ test_NhGetInterfaceNameFromDeviceGuid()

static VOID test_NhGetInterfaceNameFromDeviceGuid ( GUID  AdapterGUID,
DWORD  par1,
DWORD  par2 
)
static

Definition at line 157 of file GetInterfaceName.c.

158{
159 DWORD ApiReturn, Error;
160 ULONG ulOutBufLen;
162 GUID UniqueGUID = MY_TEST_GUID;
164
165 // Test NULL GUID
166 // Windows XP: NhGetInterfaceNameFromDeviceGuid throws exception here
167 SetLastError(0xbeeffeed);
168 Error = 0xbeeffeed;
169 ZeroMemory(&Name, sizeof(Name));
170 ApiReturn = ERROR_SUCCESS;
171 ulOutBufLen = sizeof(Name);
172 StartSeh()
173 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(NULL, &Name, &ulOutBufLen, par1, par2);
176
177 ok(ApiReturn == ERROR_INVALID_PARAMETER,
178 "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
179 ApiReturn);
181 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
182 Error);
183 ok(ulOutBufLen == sizeof(Name),
184 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
185 ulOutBufLen);
186 ok_wstr(L"", Name);
187
188 // Test correct GUID, but NULL name
189 SetLastError(0xbeeffeed);
190 Error = 0xbeeffeed;
192 ApiReturn = ERROR_SUCCESS;
193 StartSeh()
194 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, NULL, &ulOutBufLen, par1, par2);
197
198 ok(ApiReturn == ERROR_INVALID_PARAMETER,
199 "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
200 ApiReturn);
202 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
203 Error);
204 ok(ulOutBufLen > 0,
205 "ulOutBufLen is %ld, expected > 0\n",
206 ulOutBufLen);
207 ok_wstr(L"", Name);
208
209 // NhGetInterfaceNameFromDeviceGuid will throw exception if pOutBufLen is NULL
210 SetLastError(0xbeeffeed);
211 Error = 0xbeeffeed;
213 ApiReturn = ERROR_SUCCESS;
214 StartSeh()
215 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, NULL, par1, par2);
218
219 ok(ApiReturn == ERROR_INVALID_PARAMETER,
220 "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
221 ApiReturn);
223 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
224 Error);
225 ok(ulOutBufLen > 0,
226 "ulOutBufLen is %ld, expected > 0\n",
227 ulOutBufLen);
228 ok_wstr(L"", Name);
229
230 // Test correct values
231 SetLastError(0xbeeffeed);
233 ulOutBufLen = sizeof(Name);
234 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
236
237 ok(ApiReturn == ERROR_SUCCESS,
238 "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
239 ApiReturn);
241 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
242 Error);
243 ok(ulOutBufLen > 0,
244 "ulOutBufLen is %ld, expected > 0\n",
245 ulOutBufLen);
246 Length = wcslen(Name);
247 ok(Length > 0,
248 "wcslen(Name) is %ld, expected > 0\n",
249 Length);
250 if (Length > 0)
251 trace("Adapter name: \"%S\"\n", Name);
252
253 // Test correct values, but with new unique GUID
254 SetLastError(0xbeeffeed);
256 ulOutBufLen = sizeof(Name);
257 ApiReturn = pNhGetInterfaceNameFromDeviceGuid((PVOID)&UniqueGUID, &Name, &ulOutBufLen, par1, par2);
259
260 ok(ApiReturn == ERROR_NOT_FOUND,
261 "ApiReturn returned %ld, expected ERROR_NOT_FOUND\n",
262 ApiReturn);
264 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
265 Error);
266 ok(ulOutBufLen == sizeof(Name),
267 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
268 ulOutBufLen);
269 ok_wstr(L"", Name);
270
271 // Test correct values, but with small length
272 SetLastError(0xbeeffeed);
274 ulOutBufLen = 0;
275 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
277
278 ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER,
279 "ApiReturn returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
280 ApiReturn);
282 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
283 Error);
284 ok(ulOutBufLen == MAX_INTERFACE_NAME_LEN * 2,
285 "ulOutBufLen is %ld, expected = MAX_INTERFACE_NAME_LEN * 2\n",
286 ulOutBufLen);
287 ok_wstr(L"", Name);
288}
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
struct NameRec_ * Name
Definition: cdprocs.h:460
#define ok_wstr(x, y)
Definition: atltest.h:130
BOOL Error
Definition: chkdsk.c:66
#define ERROR_SUCCESS
Definition: deptool.c:10
#define ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define SetLastError(x)
Definition: compat.h:752
GLdouble n
Definition: glext.h:7729
#define MAX_INTERFACE_NAME_LEN
Definition: ifmib.h:31
if(dx< 0)
Definition: linetemp.h:194
BOOL expected
Definition: store.c:2063
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:102
#define STATUS_SUCCESS
Definition: shellext.h:65
Definition: movable.cpp:9
Definition: name.c:39
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ZeroMemory
Definition: winbase.h:1670
DWORD WINAPI GetLastError(void)
Definition: except.c:1040
#define ERROR_NOT_FOUND
Definition: winerror.h:690
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList

Referenced by test_GetInterfaceName().

◆ test_NhGetInterfaceNameFromGuid()

static VOID test_NhGetInterfaceNameFromGuid ( GUID  AdapterGUID,
DWORD  par1,
DWORD  par2 
)
static

Definition at line 24 of file GetInterfaceName.c.

25{
26 DWORD ApiReturn, Error;
27 ULONG ulOutBufLen;
29 GUID UniqueGUID = MY_TEST_GUID;
31
32 // Test NULL GUID
33 SetLastError(0xbeeffeed);
34 Error = 0xbeeffeed;
35 ZeroMemory(&Name, sizeof(Name));
36 ApiReturn = ERROR_SUCCESS;
37 ulOutBufLen = sizeof(Name);
38 StartSeh()
39 ApiReturn = pNhGetInterfaceNameFromGuid(NULL, &Name, &ulOutBufLen, par1, par2);
42
43 ok(ApiReturn == ERROR_INVALID_PARAMETER,
44 "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
45 ApiReturn);
46 ok(Error == 0xbeeffeed,
47 "GetLastError() returned %ld, expected 0xbeeffeed\n",
48 Error);
49 ok(ulOutBufLen == sizeof(Name),
50 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
51 ulOutBufLen);
52 ok_wstr(L"", Name);
53
54 // Test correct GUID, but NULL name
55 SetLastError(0xbeeffeed);
57 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, NULL, &ulOutBufLen, par1, par2);
59
60 ok(ApiReturn == ERROR_SUCCESS,
61 "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
62 ApiReturn);
63 ok(Error == 0xbeeffeed,
64 "GetLastError() returned %ld, expected 0xbeeffeed\n",
65 Error);
66 ok(ulOutBufLen > 0,
67 "ulOutBufLen is %ld, expected > 0\n",
68 ulOutBufLen);
69 ok_wstr(L"", Name);
70
71 // NhGetInterfaceNameFromGuid will throw exception if pOutBufLen is NULL
72 SetLastError(0xbeeffeed);
73 Error = 0xbeeffeed;
75 ApiReturn = ERROR_SUCCESS;
76 StartSeh()
77 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, NULL, par1, par2);
80
81 ok(ApiReturn == ERROR_INVALID_PARAMETER,
82 "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
83 ApiReturn);
84 ok(Error == 0xbeeffeed,
85 "GetLastError() returned %ld, expected 0xbeeffeed\n",
86 Error);
87 ok(ulOutBufLen > 0,
88 "ulOutBufLen is %ld, expected > 0\n",
89 ulOutBufLen);
90 ok_wstr(L"", Name);
91
92 // Test correct values
93 SetLastError(0xbeeffeed);
95 ulOutBufLen = sizeof(Name);
96 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
98
99 ok(ApiReturn == ERROR_SUCCESS,
100 "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
101 ApiReturn);
102 ok(Error == 0xbeeffeed,
103 "GetLastError() returned %ld, expected 0xbeeffeed\n",
104 Error);
105 ok(ulOutBufLen > 0,
106 "ulOutBufLen is %ld, expected > 0\n",
107 ulOutBufLen);
108 Length = wcslen(Name);
109 ok(Length > 0,
110 "wcslen(Name) is %ld, expected > 0\n",
111 Length);
112 if (Length > 0)
113 trace("Adapter name: \"%S\"\n", Name);
114
115 // Test correct values, but with new unique GUID
116 SetLastError(0xbeeffeed);
118 ulOutBufLen = sizeof(Name);
119 ApiReturn = pNhGetInterfaceNameFromGuid((PVOID)&UniqueGUID, &Name, &ulOutBufLen, par1, par2);
121
122 ok(ApiReturn == ERROR_NOT_FOUND,
123 "ApiReturn returned %ld, expected ERROR_NOT_FOUND\n",
124 ApiReturn);
127 Error);
128 ok(ulOutBufLen == sizeof(Name),
129 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
130 ulOutBufLen);
131 ok_wstr(L"", Name);
132
133 // Test correct values, but with small length
134 SetLastError(0xbeeffeed);
136 ulOutBufLen = 0;
137 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
139
140 ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER,
141 "ApiReturn returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
142 ApiReturn);
143 ok(Error == 0xbeeffeed,
144 "GetLastError() returned %ld, expected 0xbeeffeed\n",
145 Error);
146 ok(ulOutBufLen == MAX_INTERFACE_NAME_LEN * 2,
147 "ulOutBufLen is %ld, expected = MAX_INTERFACE_NAME_LEN * 2\n",
148 ulOutBufLen);
149 ok_wstr(L"", Name);
150}
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106

Referenced by test_GetInterfaceName().

Variable Documentation

◆ DWORD

Definition at line 16 of file GetInterfaceName.c.

◆ PULONG

Definition at line 16 of file GetInterfaceName.c.

◆ PVOID

Definition at line 16 of file GetInterfaceName.c.