ReactOS 0.4.15-dev-8339-g4028de8
GetExtendedTcpTable.c File Reference
#include <apitest.h>
#include <iphlpapi.h>
#include <winsock2.h>
Include dependency graph for GetExtendedTcpTable.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

static DWORD GetExtendedTcpTableWithAlloc (PVOID *TcpTable, BOOL Order, DWORD Family, TCP_TABLE_CLASS Class)
 
 START_TEST (GetExtendedTcpTable)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetExtendedTcpTable.c.

Function Documentation

◆ GetExtendedTcpTableWithAlloc()

static DWORD GetExtendedTcpTableWithAlloc ( PVOID TcpTable,
BOOL  Order,
DWORD  Family,
TCP_TABLE_CLASS  Class 
)
static

Definition at line 14 of file GetExtendedTcpTable.c.

15{
16 DWORD ret;
17 DWORD Size = 0;
18
19 *TcpTable = NULL;
20
21 ret = GetExtendedTcpTable(*TcpTable, &Size, Order, Family, Class, 0);
23 {
24 *TcpTable = HeapAlloc(GetProcessHeap(), 0, Size);
25 if (*TcpTable == NULL)
26 {
27 return ERROR_OUTOFMEMORY;
28 }
29
30 ret = GetExtendedTcpTable(*TcpTable, &Size, Order, Family, Class, 0);
31 if (ret != NO_ERROR)
32 {
33 HeapFree(GetProcessHeap(), 0, *TcpTable);
34 *TcpTable = NULL;
35 }
36 }
37
38 return ret;
39}
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define NULL
Definition: types.h:112
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
unsigned long DWORD
Definition: ntddk_ex.h:95
DWORD WINAPI GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved)
static int Family
Definition: ping.c:62
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( GetExtendedTcpTable  )

Definition at line 41 of file GetExtendedTcpTable.c.

42{
43 WSADATA wsaData;
46 PMIB_TCPTABLE TcpTable;
47 PMIB_TCPTABLE_OWNER_PID TcpTableOwner;
48 PMIB_TCPTABLE_OWNER_MODULE TcpTableOwnerMod;
49 DWORD i;
51 FILETIME Creation;
52 LARGE_INTEGER CreationTime;
54
55 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
56 {
57 skip("Failed to init WS2\n");
58 return;
59 }
60
61 GetSystemTimeAsFileTime(&Creation);
62 CreationTime.LowPart = Creation.dwLowDateTime;
63 CreationTime.HighPart = Creation.dwHighDateTime;
64
66 if (sock == INVALID_SOCKET)
67 {
68 skip("Cannot create socket\n");
69 goto quit;
70 }
71
72 ZeroMemory(&server, sizeof(SOCKADDR_IN));
73 server.sin_family = AF_INET;
74 server.sin_addr.s_addr = htonl(INADDR_ANY);
75 server.sin_port = htons(9876);
76
77 if (bind(sock, (SOCKADDR*)&server, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
78 {
79 skip("Cannot bind socket\n");
80 goto quit2;
81 }
82
84 {
85 skip("Cannot listen on socket\n");
86 goto quit2;
87 }
88
90 {
91 ok(TcpTable->dwNumEntries > 0, "No TCP connections?!\n");
92
93 Found = FALSE;
94 for (i = 0; i < TcpTable->dwNumEntries; ++i)
95 {
96 if (TcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN &&
97 TcpTable->table[i].dwLocalAddr == 0 &&
98 TcpTable->table[i].dwLocalPort == htons(9876) &&
99 TcpTable->table[i].dwRemoteAddr == 0)
100 {
101 Found = TRUE;
102 break;
103 }
104 }
105 ok(Found, "Our socket wasn't found!\n");
106
107 HeapFree(GetProcessHeap(), 0, TcpTable);
108 }
109 else
110 {
111 skip("GetExtendedTcpTableWithAlloc failure\n");
112 }
113
115 {
116 Found = FALSE;
117 for (i = 0; i < TcpTable->dwNumEntries; ++i)
118 {
119 if (TcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN &&
120 TcpTable->table[i].dwLocalAddr == 0 &&
121 TcpTable->table[i].dwLocalPort == htons(9876) &&
122 TcpTable->table[i].dwRemoteAddr == 0)
123 {
124 Found = TRUE;
125 break;
126 }
127 }
128 ok(Found == FALSE, "Our socket was found!\n");
129
130 HeapFree(GetProcessHeap(), 0, TcpTable);
131 }
132 else
133 {
134 skip("GetExtendedTcpTableWithAlloc failure\n");
135 }
136
138 {
139 ok(TcpTable->dwNumEntries > 0, "No TCP connections?!\n");
140
141 Found = FALSE;
142 for (i = 0; i < TcpTable->dwNumEntries; ++i)
143 {
144 if (TcpTable->table[i].dwState == MIB_TCP_STATE_LISTEN &&
145 TcpTable->table[i].dwLocalAddr == 0 &&
146 TcpTable->table[i].dwLocalPort == htons(9876) &&
147 TcpTable->table[i].dwRemoteAddr == 0)
148 {
149 Found = TRUE;
150 break;
151 }
152 }
153 ok(Found, "Our socket wasn't found!\n");
154
155 HeapFree(GetProcessHeap(), 0, TcpTable);
156 }
157 else
158 {
159 skip("GetExtendedTcpTableWithAlloc failure\n");
160 }
161
163 {
164 ok(TcpTableOwner->dwNumEntries > 0, "No TCP connections?!\n");
165
166 Found = FALSE;
167 for (i = 0; i < TcpTableOwner->dwNumEntries; ++i)
168 {
169 if (TcpTableOwner->table[i].dwState == MIB_TCP_STATE_LISTEN &&
170 TcpTableOwner->table[i].dwLocalAddr == 0 &&
171 TcpTableOwner->table[i].dwLocalPort == htons(9876) &&
172 TcpTableOwner->table[i].dwRemoteAddr == 0)
173 {
174 Found = TRUE;
175 break;
176 }
177 }
178
179 if (!Found)
180 {
181 skip("Our socket wasn't found!\n");
182 }
183 else
184 {
185 ok(TcpTableOwner->table[i].dwOwningPid == Pid, "Invalid owner\n");
186 }
187
188 HeapFree(GetProcessHeap(), 0, TcpTableOwner);
189 }
190 else
191 {
192 skip("GetExtendedTcpTableWithAlloc failure\n");
193 }
194
196 {
197 Found = FALSE;
198 for (i = 0; i < TcpTableOwner->dwNumEntries; ++i)
199 {
200 if (TcpTableOwner->table[i].dwState == MIB_TCP_STATE_LISTEN &&
201 TcpTableOwner->table[i].dwLocalAddr == 0 &&
202 TcpTableOwner->table[i].dwLocalPort == htons(9876) &&
203 TcpTableOwner->table[i].dwRemoteAddr == 0)
204 {
205 Found = TRUE;
206 break;
207 }
208 }
209 ok(Found == FALSE, "Our socket was found!\n");
210
211 HeapFree(GetProcessHeap(), 0, TcpTableOwner);
212 }
213 else
214 {
215 skip("GetExtendedTcpTableWithAlloc failure\n");
216 }
217
219 {
220 ok(TcpTableOwner->dwNumEntries > 0, "No TCP connections?!\n");
221
222 Found = FALSE;
223 for (i = 0; i < TcpTableOwner->dwNumEntries; ++i)
224 {
225 if (TcpTableOwner->table[i].dwState == MIB_TCP_STATE_LISTEN &&
226 TcpTableOwner->table[i].dwLocalAddr == 0 &&
227 TcpTableOwner->table[i].dwLocalPort == htons(9876) &&
228 TcpTableOwner->table[i].dwRemoteAddr == 0)
229 {
230 Found = TRUE;
231 break;
232 }
233 }
234
235 if (!Found)
236 {
237 skip("Our socket wasn't found!\n");
238 }
239 else
240 {
241 ok(TcpTableOwner->table[i].dwOwningPid == Pid, "Invalid owner\n");
242 }
243
244 HeapFree(GetProcessHeap(), 0, TcpTableOwner);
245 }
246 else
247 {
248 skip("GetExtendedTcpTableWithAlloc failure\n");
249 }
250
252 {
253 ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n");
254
255 Found = FALSE;
256 for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
257 {
258 if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
259 TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
260 TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
261 TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
262 {
263 Found = TRUE;
264 break;
265 }
266 }
267
268 if (!Found)
269 {
270 skip("Our socket wasn't found!\n");
271 }
272 else
273 {
274 ok(TcpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid owner\n");
275
276 ok(TcpTableOwnerMod->table[i].liCreateTimestamp.QuadPart >= CreationTime.QuadPart, "Invalid time\n");
277 ok(TcpTableOwnerMod->table[i].liCreateTimestamp.QuadPart <= CreationTime.QuadPart + 60000000000LL, "Invalid time\n");
278 }
279
280 HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
281 }
282 else
283 {
284 skip("GetExtendedTcpTableWithAlloc failure\n");
285 }
286
288 {
289 Found = FALSE;
290 for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
291 {
292 if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
293 TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
294 TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
295 TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
296 {
297 Found = TRUE;
298 break;
299 }
300 }
301 ok(Found == FALSE, "Our socket was found!\n");
302
303 HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
304 }
305 else
306 {
307 skip("GetExtendedTcpTableWithAlloc failure\n");
308 }
309
311 {
312 ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n");
313
314 Found = FALSE;
315 for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
316 {
317 if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
318 TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
319 TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
320 TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
321 {
322 Found = TRUE;
323 break;
324 }
325 }
326
327 if (!Found)
328 {
329 skip("Our socket wasn't found!\n");
330 }
331 else
332 {
333 ok(TcpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid owner\n");
334
335 ok(TcpTableOwnerMod->table[i].liCreateTimestamp.QuadPart >= CreationTime.QuadPart, "Invalid time\n");
336 ok(TcpTableOwnerMod->table[i].liCreateTimestamp.QuadPart <= CreationTime.QuadPart + 60000000000LL, "Invalid time\n");
337 }
338
339 HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
340 }
341 else
342 {
343 skip("GetExtendedTcpTableWithAlloc failure\n");
344 }
345
346quit2:
348quit:
349 WSACleanup();
350}
static DWORD GetExtendedTcpTableWithAlloc(PVOID *TcpTable, BOOL Order, DWORD Family, TCP_TABLE_CLASS Class)
unsigned char BOOLEAN
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
return Found
Definition: dirsup.c:1270
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
GLsizei GLenum const GLvoid GLsizei GLenum GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLint GLint GLint GLshort GLshort GLshort GLubyte GLubyte GLubyte GLuint GLuint GLuint GLushort GLushort GLushort GLbyte GLbyte GLbyte GLbyte GLdouble GLdouble GLdouble GLdouble GLfloat GLfloat GLfloat GLfloat GLint GLint GLint GLint GLshort GLshort GLshort GLshort GLubyte GLubyte GLubyte GLubyte GLuint GLuint GLuint GLuint GLushort GLushort GLushort GLushort GLboolean const GLdouble const GLfloat const GLint const GLshort const GLbyte const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLdouble const GLfloat const GLfloat const GLint const GLint const GLshort const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort const GLdouble const GLfloat const GLint const GLshort GLenum GLenum GLenum GLfloat GLenum GLint GLenum GLenum GLenum GLfloat GLenum GLenum GLint GLenum GLfloat GLenum GLint GLint GLushort GLenum GLenum GLfloat GLenum GLenum GLint GLfloat const GLubyte GLenum GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLint GLint GLsizei GLsizei GLint GLenum GLenum const GLvoid GLenum GLenum const GLfloat GLenum GLenum const GLint GLenum GLenum const GLdouble GLenum GLenum const GLfloat GLenum GLenum const GLint GLsizei GLuint GLfloat GLuint GLbitfield GLfloat GLint GLuint GLboolean GLenum GLfloat GLenum GLbitfield GLenum GLfloat GLfloat GLint GLint const GLfloat GLenum GLfloat GLfloat GLint GLint GLfloat GLfloat GLint GLint const GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat GLint GLfloat GLfloat const GLdouble const GLfloat const GLdouble const GLfloat GLint i
Definition: glfuncs.h:248
@ TCP_TABLE_OWNER_MODULE_CONNECTIONS
Definition: iprtrmib.h:37
@ TCP_TABLE_BASIC_CONNECTIONS
Definition: iprtrmib.h:31
@ TCP_TABLE_BASIC_LISTENER
Definition: iprtrmib.h:30
@ TCP_TABLE_OWNER_MODULE_ALL
Definition: iprtrmib.h:38
@ TCP_TABLE_OWNER_PID_LISTENER
Definition: iprtrmib.h:33
@ TCP_TABLE_BASIC_ALL
Definition: iprtrmib.h:32
@ TCP_TABLE_OWNER_PID_ALL
Definition: iprtrmib.h:35
@ TCP_TABLE_OWNER_PID_CONNECTIONS
Definition: iprtrmib.h:34
@ TCP_TABLE_OWNER_MODULE_LISTENER
Definition: iprtrmib.h:36
#define INADDR_ANY
Definition: inet.h:53
#define htons(x)
Definition: module.h:215
#define htonl(x)
Definition: module.h:214
#define closesocket
Definition: ncftp.h:477
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
DWORD dwHighDateTime
Definition: mapidefs.h:66
DWORD dwLowDateTime
Definition: mapidefs.h:65
Definition: tcpcore.h:1455
@ MIB_TCP_STATE_LISTEN
Definition: tcpmib.h:29
#define MAKEWORD(a, b)
Definition: typedefs.h:248
LONGLONG QuadPart
Definition: typedefs.h:114
ULONG LowPart
Definition: typedefs.h:106
static rfbScreenInfoPtr server
Definition: vnc.c:74
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define SOMAXCONN
Definition: winsock.h:399
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCKET_ERROR
Definition: winsock.h:333