[TCPIP_DRVTEST]
[reactos.git] / rostests / drivers / tcpip / InterfaceInfo.c
1 /*
2 * PROJECT: ReactOS kernel-mode tests
3 * LICENSE: GPLv2+ - See COPYING in the top level directory
4 * PURPOSE: User mode part of the TcpIp.sys test suite
5 * PROGRAMMER: Jérôme Gardou <jerome.gardou@reactos.org>
6 */
7
8 #include <apitest.h>
9
10 #include <ipexport.h>
11 #include <winioctl.h>
12 #include <tcpioctl.h>
13 #include <tcpip_undoc.h>
14
15 START_TEST(InterfaceInfo)
16 {
17 IP_INTERFACE_INFO* pInterfaceInfo;
18 IP_INTERFACE_INFO InterfaceInfo;
19 HANDLE FileHandle;
20 DWORD BufferSize;
21 BOOL Result;
22 ULONG i;
23
24 /* Open a control channel file for TCP */
25 FileHandle = CreateFileW(
26 L"\\\\.\\Tcp",
27 FILE_READ_DATA | FILE_WRITE_DATA,
28 FILE_SHARE_READ | FILE_SHARE_WRITE,
29 NULL,
30 OPEN_EXISTING,
31 FILE_FLAG_OVERLAPPED,
32 NULL);
33 ok(FileHandle != INVALID_HANDLE_VALUE, "CreateFile failed, GLE %lu\n", GetLastError());
34
35 /* Try the IOCTL */
36 BufferSize = 0;
37 pInterfaceInfo = &InterfaceInfo;
38 Result = DeviceIoControl(
39 FileHandle,
40 IOCTL_IP_INTERFACE_INFO,
41 NULL,
42 0,
43 pInterfaceInfo,
44 sizeof(InterfaceInfo),
45 &BufferSize,
46 NULL);
47 ok(!Result, "DeviceIoControl succeeded.\n");
48 ok_long(GetLastError(), ERROR_INVALID_FUNCTION);
49 ok_long(BufferSize, 0);
50
51 CloseHandle(FileHandle);
52
53 /* This IOCTL only works with \Device\Ip */
54 FileHandle = CreateFileW(
55 L"\\\\.\\Ip",
56 FILE_READ_DATA | FILE_WRITE_DATA,
57 FILE_SHARE_READ | FILE_SHARE_WRITE,
58 NULL,
59 OPEN_EXISTING,
60 FILE_FLAG_OVERLAPPED,
61 NULL);
62 ok(FileHandle != INVALID_HANDLE_VALUE, "CreateFile failed, GLE %lu\n", GetLastError());
63
64 /* Get the buffer size. */
65 BufferSize = 0;
66 pInterfaceInfo = &InterfaceInfo;
67 Result = DeviceIoControl(
68 FileHandle,
69 IOCTL_IP_INTERFACE_INFO,
70 NULL,
71 0,
72 pInterfaceInfo,
73 sizeof(InterfaceInfo),
74 &BufferSize,
75 NULL);
76 ok(Result, "DeviceIoControl failed.\n");
77 ok(BufferSize != 0, "Buffer size is zero.\n");
78 trace("Buffer size is %lu.\n", BufferSize);
79
80 if (BufferSize > sizeof(InterfaceInfo))
81 {
82 pInterfaceInfo = HeapAlloc(GetProcessHeap(), 0, BufferSize);
83 ok(pInterfaceInfo != NULL, "HeapAlloc failed.\n");
84
85 /* Send IOCTL to fill the buffer in. */
86 Result = DeviceIoControl(
87 FileHandle,
88 IOCTL_IP_INTERFACE_INFO,
89 NULL,
90 0,
91 pInterfaceInfo,
92 BufferSize,
93 &BufferSize,
94 NULL);
95 ok(Result, "DeviceIoControl failed.\n");
96 }
97
98 /* Nothing much to test. Just print out the adapters we got */
99 trace("We got %ld adapters.\n", pInterfaceInfo->NumAdapters);
100 for (i = 0; i < pInterfaceInfo->NumAdapters; i++)
101 {
102 trace("\tIndex %lu, name %S\n", pInterfaceInfo->Adapter[i].Index, pInterfaceInfo->Adapter[i].Name);
103 }
104
105 if (pInterfaceInfo != &InterfaceInfo)
106 HeapFree(GetProcessHeap(), 0, pInterfaceInfo);
107 CloseHandle(FileHandle);
108 }