ReactOS  0.4.15-dev-1148-g8a4273b
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 
312  pInfo = (IP_INTERFACE_INFO *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulOutBufLen);
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 PWSTR GuidString
Definition: apphelp.c:91
IP_ADAPTER_INDEX_MAP Adapter[1]
Definition: ipexport.h:152
DWORD WINAPI GetInterfaceInfo(PIP_INTERFACE_INFO pIfTable, PULONG dwOutBufLen)
#define NO_ERROR
Definition: dderror.h:5
static VOID test_NhGetInterfaceNameFromDeviceGuid(GUID AdapterGUID, DWORD par1, DWORD par2)
smooth NULL
Definition: ftsmooth.c:416
WCHAR Name[MAX_ADAPTER_NAME]
Definition: ipexport.h:147
#define GetProcessHeap()
Definition: compat.h:484
#define trace
Definition: atltest.h:70
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define CopyMemory
Definition: winbase.h:1646
unsigned long DWORD
Definition: ntddk_ex.h:95
_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)
static const WCHAR L[]
Definition: oid.c:1250
NTSYSAPI NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING, GUID *)
static VOID test_NhGetInterfaceNameFromGuid(GUID AdapterGUID, DWORD par1, DWORD par2)
#define ok(value,...)
Definition: atltest.h:57
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
#define skip(...)
Definition: atltest.h:64
#define MAX_ADAPTER_NAME
Definition: ipexport.h:143
unsigned int ULONG
Definition: retypes.h:1
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:838
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define GetProcAddress(x, y)
Definition: compat.h:501
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:483
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

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;
163  SIZE_T Length;
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);
174  Error = GetLastError();
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);
195  Error = GetLastError();
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);
216  Error = GetLastError();
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);
235  Error = GetLastError();
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);
258  Error = GetLastError();
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);
276  Error = GetLastError();
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 ERROR_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
GLdouble n
Definition: glext.h:7729
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1648
Definition: movable.cpp:7
#define StartSeh()
Definition: _sntprintf.h:16
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
#define trace
Definition: atltest.h:70
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SetLastError(x)
Definition: compat.h:500
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
#define MAX_INTERFACE_NAME_LEN
Definition: ifmib.h:31
#define ok_wstr(x, y)
Definition: atltest.h:130
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_NOT_FOUND
Definition: winerror.h:690
Definition: name.c:38
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:3014
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL expected
Definition: store.c:2063
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

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;
30  SIZE_T Length;
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);
40  Error = GetLastError();
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);
58  Error = GetLastError();
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);
78  Error = GetLastError();
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);
97  Error = GetLastError();
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);
120  Error = GetLastError();
121 
122  ok(ApiReturn == ERROR_NOT_FOUND,
123  "ApiReturn returned %ld, expected ERROR_NOT_FOUND\n",
124  ApiReturn);
126  "GetLastError() returned %ld, expected ERROR_PATH_NOT_FOUND\n",
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);
138  Error = GetLastError();
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_INVALID_PARAMETER
Definition: compat.h:101
#define ERROR_SUCCESS
Definition: deptool.c:10
ActualNumberDriverObjects * sizeof(PDRIVER_OBJECT)) PDRIVER_OBJECT *DriverObjectList
GLdouble n
Definition: glext.h:7729
DWORD WINAPI GetLastError(VOID)
Definition: except.c:1044
#define ZeroMemory
Definition: winbase.h:1648
Definition: movable.cpp:7
#define StartSeh()
Definition: _sntprintf.h:16
struct NameRec_ * Name
Definition: cdprocs.h:459
smooth NULL
Definition: ftsmooth.c:416
#define trace
Definition: atltest.h:70
if(!(yy_init))
Definition: macro.lex.yy.c:714
__wchar_t WCHAR
Definition: xmlstorage.h:180
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
#define SetLastError(x)
Definition: compat.h:500
_In_ ULONG _In_ ULONG _In_ ULONG Length
Definition: ntddpcm.h:101
static const WCHAR L[]
Definition: oid.c:1250
#define MAX_INTERFACE_NAME_LEN
Definition: ifmib.h:31
#define ok_wstr(x, y)
Definition: atltest.h:130
ULONG_PTR SIZE_T
Definition: typedefs.h:80
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_NOT_FOUND
Definition: winerror.h:690
Definition: name.c:38
unsigned int ULONG
Definition: retypes.h:1
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
return STATUS_SUCCESS
Definition: btrfs.c:3014
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
BOOL expected
Definition: store.c:2063
#define EndSeh(ExpectedStatus)
Definition: _sntprintf.h:17
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

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.