ReactOS  0.4.14-dev-384-g5b37caa
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 392 of file GetInterfaceName.c.

393 {
395 }
static VOID test_GetInterfaceName(VOID)

◆ test_GetInterfaceName()

static VOID test_GetInterfaceName ( VOID  )
static

Definition at line 290 of file GetInterfaceName.c.

291 {
292  PIP_INTERFACE_INFO pInfo = NULL;
293  ULONG ulOutBufLen = 0;
294  DWORD ApiReturn;
297  GUID AdapterGUID;
298  HINSTANCE hIpHlpApi;
299 
300  ApiReturn = GetInterfaceInfo(pInfo, &ulOutBufLen);
301  ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER,
302  "GetInterfaceInfo(pInfo, &ulOutBufLen) returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
303  ApiReturn);
304  if (ApiReturn != ERROR_INSUFFICIENT_BUFFER)
305  {
306  skip("Can't determine size of IP_INTERFACE_INFO. Can't proceed\n");
307  return;
308  }
309 
310  pInfo = (IP_INTERFACE_INFO *)HeapAlloc(GetProcessHeap(), HEAP_ZERO_MEMORY, ulOutBufLen);
311  if (pInfo == NULL)
312  {
313  skip("pInfo is NULL. Can't proceed\n");
314  return;
315  }
316 
317  ApiReturn = GetInterfaceInfo(pInfo, &ulOutBufLen);
318  ok(ApiReturn == NO_ERROR,
319  "GetInterfaceInfo(pInfo, &ulOutBufLen) returned %ld, expected NO_ERROR\n",
320  ApiReturn);
321  if (ApiReturn != NO_ERROR || ulOutBufLen == 0)
322  {
323  skip("GetInterfaceInfo failed with error %ld. Can't proceed\n", ApiReturn);
324  return;
325  }
326 
327  if (pInfo->NumAdapters > 0)
328  CopyMemory(&Name, &pInfo->Adapter[0].Name, sizeof(Name));
329 
330  if (pInfo->NumAdapters == 0)
331  {
332  HeapFree(GetProcessHeap(), 0, pInfo);
333  skip("pInfo->NumAdapters = 0. Can't proceed\n");
334  return;
335  }
336  trace("pInfo->NumAdapters: %lu\n", pInfo->NumAdapters);
337 
338  HeapFree(GetProcessHeap(), 0, pInfo);
339 
340  ApiReturn = wcsncmp(Name, L"\\DEVICE\\TCPIP_", 14);
341  ok(ApiReturn == 0,
342  "wcsncmp(Name, L\"\\DEVICE\\TCPIP_\", 14) returned %ld, expected 0\n",
343  ApiReturn);
344  if (ApiReturn != 0)
345  {
346  if (wcslen(Name) == 0)
347  {
348  skip("pInfo->Adapter[0].Name is empty. Can't proceed\n");
349  return;
350  }
351  else
352  {
353  // workaround for ReactOS
354  trace("pInfo->Adapter[0].Name = \"%ls\" is incorrect.\n", Name);
356  }
357  }
358  else
359  {
361  }
362 
363  ApiReturn = RtlGUIDFromString(&GuidString, &AdapterGUID);
364  if (ApiReturn != 0)
365  {
366  skip("RtlGUIDFromString failed. Can't proceed\n");
367  return;
368  }
369 
370  hIpHlpApi = GetModuleHandleW(L"iphlpapi.dll");
371  if (!hIpHlpApi)
372  {
373  skip("Failed to load iphlpapi.dll. Can't proceed\n");
374  return;
375  }
376 
377  pNhGetInterfaceNameFromGuid = (void *)GetProcAddress(hIpHlpApi, "NhGetInterfaceNameFromGuid");
378 
379  if (!pNhGetInterfaceNameFromGuid)
380  skip("NhGetInterfaceNameFromGuid not found. Can't proceed\n");
381  else
382  test_NhGetInterfaceNameFromGuid(AdapterGUID, 0, 0);
383 
384  pNhGetInterfaceNameFromDeviceGuid = (void *)GetProcAddress(hIpHlpApi, "NhGetInterfaceNameFromDeviceGuid");
385 
386  if (!pNhGetInterfaceNameFromDeviceGuid)
387  skip("NhGetInterfaceNameFromDeviceGuid not found. Can't proceed\n");
388  else
389  test_NhGetInterfaceNameFromDeviceGuid(AdapterGUID, 1, 0);
390 }
static PWSTR GuidString
Definition: apphelp.c:91
IP_ADAPTER_INDEX_MAP Adapter[1]
Definition: ipexport.h:141
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:136
#define GetProcessHeap()
Definition: compat.h:403
#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:1640
unsigned long DWORD
Definition: ntddk_ex.h:95
NTSYSAPI NTSTATUS WINAPI RtlGUIDFromString(PUNICODE_STRING, GUID *)
_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
static VOID test_NhGetInterfaceNameFromGuid(GUID AdapterGUID, DWORD par1, DWORD par2)
#define ok(value,...)
Definition: atltest.h:57
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
#define skip(...)
Definition: atltest.h:64
#define MAX_ADAPTER_NAME
Definition: ipexport.h:132
unsigned int ULONG
Definition: retypes.h:1
HMODULE WINAPI GetModuleHandleW(LPCWSTR lpModuleName)
Definition: loader.c:847
NTSYSAPI VOID NTAPI RtlInitUnicodeString(PUNICODE_STRING DestinationString, PCWSTR SourceString)
#define GetProcAddress(x, y)
Definition: compat.h:418
size_t __cdecl wcslen(_In_z_ const wchar_t *_Str)
#define HeapFree(x, y, z)
Definition: compat.h:402
#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 156 of file GetInterfaceName.c.

157 {
158  DWORD ApiReturn, Error;
159  ULONG ulOutBufLen;
161  GUID UniqueGUID = MY_TEST_GUID;
162 
163  // Test NULL GUID
164  // Windows XP: NhGetInterfaceNameFromDeviceGuid throws exception here
165  SetLastError(0xbeeffeed);
166  Error = 0xbeeffeed;
167  ZeroMemory(&Name, sizeof(Name));
168  ApiReturn = ERROR_SUCCESS;
169  ulOutBufLen = sizeof(Name);
170  StartSeh()
171  ApiReturn = pNhGetInterfaceNameFromDeviceGuid(NULL, &Name, &ulOutBufLen, par1, par2);
172  Error = GetLastError();
174 
175  ok(ApiReturn == ERROR_INVALID_PARAMETER,
176  "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
177  ApiReturn);
179  "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
180  Error);
181  ok(ulOutBufLen == sizeof(Name),
182  "ulOutBufLen is %ld, expected = sizeof(Name)\n",
183  ulOutBufLen);
184  ok_wstr(L"", Name);
185 
186  // Test correct GUID, but NULL name
187  SetLastError(0xbeeffeed);
188  Error = 0xbeeffeed;
190  ApiReturn = ERROR_SUCCESS;
191  StartSeh()
192  ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, NULL, &ulOutBufLen, par1, par2);
193  Error = GetLastError();
195 
196  ok(ApiReturn == ERROR_INVALID_PARAMETER,
197  "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
198  ApiReturn);
200  "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
201  Error);
202  ok(ulOutBufLen > 0,
203  "ulOutBufLen is %ld, expected > 0\n",
204  ulOutBufLen);
205  ok_wstr(L"", Name);
206 
207  // NhGetInterfaceNameFromDeviceGuid will throw exception if pOutBufLen is NULL
208  SetLastError(0xbeeffeed);
209  Error = 0xbeeffeed;
211  ApiReturn = ERROR_SUCCESS;
212  StartSeh()
213  ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, NULL, par1, par2);
214  Error = GetLastError();
216 
217  ok(ApiReturn == ERROR_INVALID_PARAMETER,
218  "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
219  ApiReturn);
221  "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
222  Error);
223  ok(ulOutBufLen > 0,
224  "ulOutBufLen is %ld, expected > 0\n",
225  ulOutBufLen);
226  ok_wstr(L"", Name);
227 
228  // Test correct values
229  SetLastError(0xbeeffeed);
231  ulOutBufLen = sizeof(Name);
232  ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
233  Error = GetLastError();
234 
235  ok(ApiReturn == ERROR_SUCCESS,
236  "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
237  ApiReturn);
239  "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
240  Error);
241  ok(ulOutBufLen > 0,
242  "ulOutBufLen is %ld, expected > 0\n",
243  ulOutBufLen);
244  Error = wcslen(Name);
245  ok(Error > 0,
246  "wcslen(Name) is %ld, expected > 0\n",
247  Error);
248  if (Error > 0)
249  trace("Adapter name: \"%S\"\n", Name);
250 
251  // Test correct values, but with new unique GUID
252  SetLastError(0xbeeffeed);
254  ulOutBufLen = sizeof(Name);
255  ApiReturn = pNhGetInterfaceNameFromDeviceGuid((PVOID)&UniqueGUID, &Name, &ulOutBufLen, par1, par2);
256  Error = GetLastError();
257 
258  ok(ApiReturn == ERROR_NOT_FOUND,
259  "ApiReturn returned %ld, expected ERROR_NOT_FOUND\n",
260  ApiReturn);
262  "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
263  Error);
264  ok(ulOutBufLen == sizeof(Name),
265  "ulOutBufLen is %ld, expected = sizeof(Name)\n",
266  ulOutBufLen);
267  ok_wstr(L"", Name);
268 
269  // Test correct values, but with small length
270  SetLastError(0xbeeffeed);
272  ulOutBufLen = 0;
273  ApiReturn = pNhGetInterfaceNameFromDeviceGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
274  Error = GetLastError();
275 
276  ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER,
277  "ApiReturn returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
278  ApiReturn);
280  "GetLastError() returned %ld, expected ERROR_SUCCESS\n",
281  Error);
282  ok(ulOutBufLen == MAX_INTERFACE_NAME_LEN * 2,
283  "ulOutBufLen is %ld, expected = MAX_INTERFACE_NAME_LEN * 2\n",
284  ulOutBufLen);
285  ok_wstr(L"", Name);
286 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#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:1059
#define ZeroMemory
Definition: winbase.h:1642
Definition: movable.cpp:7
#define StartSeh()
Definition: _sntprintf.h:16
struct NameRec_ * Name
Definition: cdprocs.h:464
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:417
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
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_NOT_FOUND
Definition: winerror.h:690
Definition: name.c:36
unsigned int ULONG
Definition: retypes.h:1
return STATUS_SUCCESS
Definition: btrfs.c:2938
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 
31  // Test NULL GUID
32  SetLastError(0xbeeffeed);
33  Error = 0xbeeffeed;
34  ZeroMemory(&Name, sizeof(Name));
35  ApiReturn = ERROR_SUCCESS;
36  ulOutBufLen = sizeof(Name);
37  StartSeh()
38  ApiReturn = pNhGetInterfaceNameFromGuid(NULL, &Name, &ulOutBufLen, par1, par2);
39  Error = GetLastError();
41 
42  ok(ApiReturn == ERROR_INVALID_PARAMETER,
43  "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
44  ApiReturn);
45  ok(Error == 0xbeeffeed,
46  "GetLastError() returned %ld, expected 0xbeeffeed\n",
47  Error);
48  ok(ulOutBufLen == sizeof(Name),
49  "ulOutBufLen is %ld, expected = sizeof(Name)\n",
50  ulOutBufLen);
51  ok_wstr(L"", Name);
52 
53  // Test correct GUID, but NULL name
54  SetLastError(0xbeeffeed);
56  ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, NULL, &ulOutBufLen, par1, par2);
57  Error = GetLastError();
58 
59  ok(ApiReturn == ERROR_SUCCESS,
60  "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
61  ApiReturn);
62  ok(Error == 0xbeeffeed,
63  "GetLastError() returned %ld, expected 0xbeeffeed\n",
64  Error);
65  ok(ulOutBufLen > 0,
66  "ulOutBufLen is %ld, expected > 0\n",
67  ulOutBufLen);
68  ok_wstr(L"", Name);
69 
70  // NhGetInterfaceNameFromGuid will throw exception if pOutBufLen is NULL
71  SetLastError(0xbeeffeed);
72  Error = 0xbeeffeed;
74  ApiReturn = ERROR_SUCCESS;
75  StartSeh()
76  ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, NULL, par1, par2);
77  Error = GetLastError();
79 
80  ok(ApiReturn == ERROR_INVALID_PARAMETER,
81  "ApiReturn returned %ld, expected ERROR_INVALID_PARAMETER\n",
82  ApiReturn);
83  ok(Error == 0xbeeffeed,
84  "GetLastError() returned %ld, expected 0xbeeffeed\n",
85  Error);
86  ok(ulOutBufLen > 0,
87  "ulOutBufLen is %ld, expected > 0\n",
88  ulOutBufLen);
89  ok_wstr(L"", Name);
90 
91  // Test correct values
92  SetLastError(0xbeeffeed);
94  ulOutBufLen = sizeof(Name);
95  ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
96  Error = GetLastError();
97 
98  ok(ApiReturn == ERROR_SUCCESS,
99  "ApiReturn returned %ld, expected ERROR_SUCCESS\n",
100  ApiReturn);
101  ok(Error == 0xbeeffeed,
102  "GetLastError() returned %ld, expected 0xbeeffeed\n",
103  Error);
104  ok(ulOutBufLen > 0,
105  "ulOutBufLen is %ld, expected > 0\n",
106  ulOutBufLen);
107  Error = wcslen(Name);
108  ok(Error > 0,
109  "wcslen(Name) is %ld, expected > 0\n",
110  Error);
111  if (Error > 0)
112  trace("Adapter name: \"%S\"\n", Name);
113 
114  // Test correct values, but with new unique GUID
115  SetLastError(0xbeeffeed);
117  ulOutBufLen = sizeof(Name);
118  ApiReturn = pNhGetInterfaceNameFromGuid((PVOID)&UniqueGUID, &Name, &ulOutBufLen, par1, par2);
119  Error = GetLastError();
120 
121  ok(ApiReturn == ERROR_NOT_FOUND,
122  "ApiReturn returned %ld, expected ERROR_NOT_FOUND\n",
123  ApiReturn);
125  "GetLastError() returned %ld, expected ERROR_PATH_NOT_FOUND\n",
126  Error);
127  ok(ulOutBufLen == sizeof(Name),
128  "ulOutBufLen is %ld, expected = sizeof(Name)\n",
129  ulOutBufLen);
130  ok_wstr(L"", Name);
131 
132  // Test correct values, but with small length
133  SetLastError(0xbeeffeed);
135  ulOutBufLen = 0;
136  ApiReturn = pNhGetInterfaceNameFromGuid(&AdapterGUID, &Name, &ulOutBufLen, par1, par2);
137  Error = GetLastError();
138 
139  ok(ApiReturn == ERROR_INSUFFICIENT_BUFFER,
140  "ApiReturn returned %ld, expected ERROR_INSUFFICIENT_BUFFER\n",
141  ApiReturn);
142  ok(Error == 0xbeeffeed,
143  "GetLastError() returned %ld, expected 0xbeeffeed\n",
144  Error);
145  ok(ulOutBufLen == MAX_INTERFACE_NAME_LEN * 2,
146  "ulOutBufLen is %ld, expected = MAX_INTERFACE_NAME_LEN * 2\n",
147  ulOutBufLen);
148  ok_wstr(L"", Name);
149 }
#define ERROR_INVALID_PARAMETER
Definition: compat.h:91
#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:1059
#define ZeroMemory
Definition: winbase.h:1642
Definition: movable.cpp:7
#define StartSeh()
Definition: _sntprintf.h:16
struct NameRec_ * Name
Definition: cdprocs.h:464
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:417
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
#define ok(value,...)
Definition: atltest.h:57
#define ERROR_NOT_FOUND
Definition: winerror.h:690
Definition: name.c:36
unsigned int ULONG
Definition: retypes.h:1
#define ERROR_PATH_NOT_FOUND
Definition: winerror.h:106
return STATUS_SUCCESS
Definition: btrfs.c:2938
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.