ReactOS 0.4.15-dev-7705-g2320c37
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 360 of file GetInterfaceName.c.

361{
363}
static VOID test_GetInterfaceName(VOID)

◆ test_GetInterfaceName()

static VOID test_GetInterfaceName ( VOID  )
static

Definition at line 258 of file GetInterfaceName.c.

259{
260 PIP_INTERFACE_INFO pInfo = NULL;
261 ULONG ulOutBufLen = 0;
262 DWORD ApiReturn;
265 GUID AdapterGUID;
266 HINSTANCE hIpHlpApi;
267
268 ApiReturn = GetInterfaceInfo(pInfo, &ulOutBufLen);
269 ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER,
270 "GetInterfaceInfo(pInfo, &ulOutBufLen) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
271 ApiReturn);
272 if (ApiReturn != ERROR_INSUFFICIENT_BUFFER)
273 {
274 skip("Can't determine size of IP_INTERFACE_INFO. Can't proceed\n");
275 return;
276 }
277
279 if (pInfo == NULL)
280 {
281 skip("pInfo is NULL. Can't proceed\n");
282 return;
283 }
284
285 ApiReturn = GetInterfaceInfo(pInfo, &ulOutBufLen);
286 ok(ApiReturn == NO_ERROR,
287 "GetInterfaceInfo(pInfo, &ulOutBufLen) returned %ld, expected NO_ERROR\n",
288 ApiReturn);
289 if (ApiReturn != NO_ERROR || ulOutBufLen == 0)
290 {
291 skip("GetInterfaceInfo failed with error %ld. Can't proceed\n", ApiReturn);
292 return;
293 }
294
295 if (pInfo->NumAdapters > 0)
296 CopyMemory(&Name, &pInfo->Adapter[0].Name, sizeof(Name));
297
298 if (pInfo->NumAdapters == 0)
299 {
300 HeapFree(GetProcessHeap(), 0, pInfo);
301 skip("pInfo->NumAdapters = 0. Can't proceed\n");
302 return;
303 }
304 trace("pInfo->NumAdapters: %lu\n", pInfo->NumAdapters);
305
306 HeapFree(GetProcessHeap(), 0, pInfo);
307
308 ApiReturn = wcsncmp(Name, L"\\DEVICE\\TCPIP_", 14);
309 ok(ApiReturn == 0,
310 "wcsncmp(Name, L\"\\DEVICE\\TCPIP_\", 14) returned %ld, expected 0\n",
311 ApiReturn);
312 if (ApiReturn != 0)
313 {
314 if (wcslen(Name) == 0)
315 {
316 skip("pInfo->Adapter[0].Name is empty. Can't proceed\n");
317 return;
318 }
319 else
320 {
321 // workaround for ReactOS
322 trace("pInfo->Adapter[0].Name = \"%ls\" is incorrect.\n", Name);
324 }
325 }
326 else
327 {
329 }
330
331 ApiReturn = RtlGUIDFromString(&GuidString, &AdapterGUID);
332 if (ApiReturn != 0)
333 {
334 skip("RtlGUIDFromString failed. Can't proceed\n");
335 return;
336 }
337
338 hIpHlpApi = GetModuleHandleW(L"iphlpapi.dll");
339 if (!hIpHlpApi)
340 {
341 skip("Failed to load iphlpapi.dll. Can't proceed\n");
342 return;
343 }
344
345 pNhGetInterfaceNameFromGuid = (void *)GetProcAddress(hIpHlpApi, "NhGetInterfaceNameFromGuid");
346
347 if (!pNhGetInterfaceNameFromGuid)
348 skip("NhGetInterfaceNameFromGuid not found. Can't proceed\n");
349 else
350 test_NhGetInterfaceNameFromGuid(AdapterGUID, 0, 0);
351
352 pNhGetInterfaceNameFromDeviceGuid = (void *)GetProcAddress(hIpHlpApi, "NhGetInterfaceNameFromDeviceGuid");
353
354 if (!pNhGetInterfaceNameFromDeviceGuid)
355 skip("NhGetInterfaceNameFromDeviceGuid not found. Can't proceed\n");
356 else
357 test_NhGetInterfaceNameFromDeviceGuid(AdapterGUID, 1, 0);
358}
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:1710
__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 139 of file GetInterfaceName.c.

140{
141 DWORD ApiReturn, Error;
142 ULONG ulOutBufLen;
144 GUID UniqueGUID = MY_TEST_GUID;
146
147 // Test NULL GUID
148 // Windows XP: NhGetInterfaceNameFromDeviceGuid throws exception here
149 SetLastError(0xbeeffeed);
150 Error = 0xbeeffeed;
151 ZeroMemory(&Name, sizeof(Name));
152 ApiReturn = ERROR_SUCCESS;
153 ulOutBufLen = sizeof(Name);
154 StartSeh()
155 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(NULL, &Name, &ulOutBufLen, par1, par2);
158
159 ok_long(ApiReturn, ((GetVersion() & 0xFF) >= 6) ? ERROR_INVALID_PARAMETER : 0);
160 ok(Error == 0xbeeffeed,
161 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
162 Error);
163 ok(ulOutBufLen == sizeof(Name),
164 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
165 ulOutBufLen);
166 ok_wstr(L"", Name);
167
168 // Test correct GUID, but NULL name
169 SetLastError(0xbeeffeed);
170 Error = 0xbeeffeed;
172 ApiReturn = ERROR_SUCCESS;
173 StartSeh()
174 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, NULL, &ulOutBufLen, par1, par2);
177
178 ok_long(ApiReturn, ((GetVersion() & 0xFF) >= 6) ? ERROR_INVALID_PARAMETER : 0);
179 ok_long(Error, ((GetVersion() & 0xFF) >= 6) ? ERROR_SUCCESS : 0xbeeffeed);
180 ok(ulOutBufLen > 0,
181 "ulOutBufLen is %ld, expected > 0\n",
182 ulOutBufLen);
183 ok_wstr(L"", Name);
184
185 // NhGetInterfaceNameFromDeviceGuid will throw exception if pOutBufLen is NULL
186 SetLastError(0xbeeffeed);
187 Error = 0xbeeffeed;
189 ApiReturn = ERROR_SUCCESS;
190 StartSeh()
191 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, NULL, par1, par2);
194
195 ok_long(ApiReturn, 0);
196 ok_long(Error, 0xbeeffeed);
197 ok(ulOutBufLen > 0,
198 "ulOutBufLen is %ld, expected > 0\n",
199 ulOutBufLen);
200 ok_wstr(L"", Name);
201
202 // Test correct values
203 SetLastError(0xbeeffeed);
205 ulOutBufLen = sizeof(Name);
206 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
208
209 ok(ApiReturn == ERROR_SUCCESS,
210 "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
211 ApiReturn);
213 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
214 Error);
215 ok(ulOutBufLen > 0,
216 "ulOutBufLen is %ld, expected > 0\n",
217 ulOutBufLen);
218 Length = wcslen(Name);
219 ok(Length > 0,
220 "wcslen(Name) is %ld, expected > 0\n",
221 Length);
222 if (Length > 0)
223 trace("Adapter name: \"%S\"\n", Name);
224
225 // Test correct values, but with new unique GUID
226 SetLastError(0xbeeffeed);
228 ulOutBufLen = sizeof(Name);
229 ApiReturn = pNhGetInterfaceNameFromDeviceGuid((PVOID)&UniqueGUID, &Name, &ulOutBufLen, par1, par2);
231
232 ok_long(ApiReturn, ((GetVersion() & 0xFF) >= 6) ? ERROR_INVALID_PARAMETER : ERROR_NOT_FOUND);
234 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
235 Error);
236 ok(ulOutBufLen == sizeof(Name),
237 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
238 ulOutBufLen);
239 ok_wstr(L"", Name);
240
241 // Test correct values, but with small length
242 SetLastError(0xbeeffeed);
244 ulOutBufLen = 0;
245 ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
247
250 "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
251 Error);
252 ok_long(ulOutBufLen, MAX_INTERFACE_NAME_LEN * 2 + (((GetVersion() & 0xFF) >= 6) ? 2 : 0));
253 ok_wstr(L"", Name);
254}
#define StartSeh()
Definition: _sntprintf.h:16
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
struct NameRec_ * Name
Definition: cdprocs.h:460
#define ok_long(expression, result)
Definition: atltest.h:133
#define ok_wstr(x, y)
Definition: atltest.h:130
BOOL Error
Definition: chkdsk.c:66
#define ERROR_NOT_ENOUGH_MEMORY
Definition: dderror.h:7
#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_ACCESS_VIOLATION
Definition: ntstatus.h:242
DWORD WINAPI GetVersion()
Definition: redirtest.c:5
#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:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#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_long(ApiReturn, ((GetVersion() & 0xFF) >= 6) ? ERROR_INVALID_PARAMETER : ERROR_SUCCESS);
44 ok(Error == 0xbeeffeed,
45 "GetLastError() returned %ld, expected 0xbeeffeed\n",
46 Error);
47 ok(ulOutBufLen == sizeof(Name),
48 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
49 ulOutBufLen);
50 ok_wstr(L"", Name);
51
52 // Test correct GUID, but NULL name
53 SetLastError(0xbeeffeed);
55 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, NULL, &ulOutBufLen, par1, par2);
57
58 ok_long(ApiReturn, ((GetVersion() & 0xFF) >= 6) ? ERROR_INVALID_PARAMETER : ERROR_SUCCESS);
59 ok_long(Error, ((GetVersion() & 0xFF) >= 6) ? ERROR_SUCCESS : 0xbeeffeed);
60 ok(ulOutBufLen > 0,
61 "ulOutBufLen is %ld, expected > 0\n",
62 ulOutBufLen);
63 ok_wstr(L"", Name);
64
65 // NhGetInterfaceNameFromGuid will throw exception if pOutBufLen is NULL
66 SetLastError(0xbeeffeed);
67 Error = 0xbeeffeed;
69 ApiReturn = 0xdeadbeef;
70 StartSeh()
71 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, NULL, par1, par2);
74
75 ok(ApiReturn == 0xdeadbeef,
76 "ApiReturn returned %ld, expected 0xdeadbeef\n",
77 ApiReturn);
78 ok(Error == 0xbeeffeed,
79 "GetLastError() returned %ld, expected 0xbeeffeed\n",
80 Error);
81 ok(ulOutBufLen > 0,
82 "ulOutBufLen is %ld, expected > 0\n",
83 ulOutBufLen);
84 ok_wstr(L"", Name);
85
86 // Test correct values
87 SetLastError(0xbeeffeed);
89 ulOutBufLen = sizeof(Name);
90 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
92
93 ok(ApiReturn == ERROR_SUCCESS,
94 "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
95 ApiReturn);
96 ok_long(Error, ((GetVersion() & 0xFF) >= 6) ? 0 : 0xbeeffeed);
97 ok(ulOutBufLen > 0,
98 "ulOutBufLen is %ld, expected > 0\n",
99 ulOutBufLen);
100 Length = wcslen(Name);
101 ok(Length > 0,
102 "wcslen(Name) is %ld, expected > 0\n",
103 Length);
104 if (Length > 0)
105 trace("Adapter name: \"%S\"\n", Name);
106
107 // Test correct values, but with new unique GUID
108 SetLastError(0xbeeffeed);
110 ulOutBufLen = sizeof(Name);
111 ApiReturn = pNhGetInterfaceNameFromGuid((PVOID)&UniqueGUID, &Name, &ulOutBufLen, par1, par2);
113
114 ok_long(ApiReturn, ((GetVersion() & 0xFF) >= 6) ? ERROR_INVALID_PARAMETER : ERROR_NOT_FOUND);
115 ok_long(Error, 0);
116 ok(ulOutBufLen == sizeof(Name),
117 "ulOutBufLen is %ld, expected = sizeof(Name)\n",
118 ulOutBufLen);
119 ok_wstr(L"", Name);
120
121 // Test correct values, but with small length
122 SetLastError(0xbeeffeed);
124 ulOutBufLen = 0;
125 ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
127
129 ok_long(Error, ((GetVersion() & 0xFF) >= 6) ? 0 : 0xbeeffeed);
130 ok_long(ulOutBufLen, MAX_INTERFACE_NAME_LEN * 2 + ((GetVersion() & 0xFF) >= 6 ? 2 : 0));
131 ok_wstr(L"", Name);
132}

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.