ReactOS 0.4.15-dev-7704-gc07eb9f
GetExtendedUdpTable.c
Go to the documentation of this file.
1/*
2 * PROJECT: ReactOS API Tests
3 * LICENSE: GPL-2.0+ (https://spdx.org/licenses/GPL-2.0+)
4 * PURPOSE: Tests for UDP connections enumeration functions
5 * COPYRIGHT: Copyright 2018 Pierre Schweitzer
6 */
7
8#include <apitest.h>
9
10#define WIN32_NO_STATUS
11#include <iphlpapi.h>
12#include <winsock2.h>
13
15{
16 DWORD ret;
17 DWORD Size = 0;
18
19 *UdpTable = NULL;
20
21 ret = GetExtendedUdpTable(*UdpTable, &Size, Order, Family, Class, 0);
23 {
24 *UdpTable = HeapAlloc(GetProcessHeap(), 0, Size);
25 if (*UdpTable == NULL)
26 {
27 return ERROR_OUTOFMEMORY;
28 }
29
30 ret = GetExtendedUdpTable(*UdpTable, &Size, Order, Family, Class, 0);
31 if (ret != NO_ERROR)
32 {
33 HeapFree(GetProcessHeap(), 0, *UdpTable);
34 *UdpTable = NULL;
35 }
36 }
37
38 return ret;
39}
40
42{
43 WSADATA wsaData;
46 PMIB_UDPTABLE UdpTable;
47 PMIB_UDPTABLE_OWNER_PID UdpTableOwner;
48 PMIB_UDPTABLE_OWNER_MODULE UdpTableOwnerMod;
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 ok(UdpTable->dwNumEntries > 0, "No UDP connections?!\n");
86
87 Found = FALSE;
88 for (i = 0; i < UdpTable->dwNumEntries; ++i)
89 {
90 if (UdpTable->table[i].dwLocalAddr == 0 &&
91 UdpTable->table[i].dwLocalPort == htons(9876))
92 {
93 Found = TRUE;
94 break;
95 }
96 }
97 ok(Found, "Our socket wasn't found!\n");
98
99 HeapFree(GetProcessHeap(), 0, UdpTable);
100 }
101 else
102 {
103 skip("GetExtendedUdpTableWithAlloc failure\n");
104 }
105
107 {
108 ok(UdpTableOwner->dwNumEntries > 0, "No UDP connections?!\n");
109
110 Found = FALSE;
111 for (i = 0; i < UdpTableOwner->dwNumEntries; ++i)
112 {
113 if (UdpTableOwner->table[i].dwLocalAddr == 0 &&
114 UdpTableOwner->table[i].dwLocalPort == htons(9876))
115 {
116 Found = TRUE;
117 break;
118 }
119 }
120
121 if (!Found)
122 {
123 skip("Our socket wasn't found!\n");
124 }
125 else
126 {
127 ok(UdpTableOwner->table[i].dwOwningPid == Pid, "Invalid owner\n");
128 }
129
130 HeapFree(GetProcessHeap(), 0, UdpTableOwner);
131 }
132 else
133 {
134 skip("GetExtendedUdpTableWithAlloc failure\n");
135 }
136
138 {
139 ok(UdpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n");
140
141 Found = FALSE;
142 for (i = 0; i < UdpTableOwnerMod->dwNumEntries; ++i)
143 {
144 if (UdpTableOwnerMod->table[i].dwLocalAddr == 0 &&
145 UdpTableOwnerMod->table[i].dwLocalPort == htons(9876))
146 {
147 Found = TRUE;
148 break;
149 }
150 }
151
152 if (!Found)
153 {
154 skip("Our socket wasn't found!\n");
155 }
156 else
157 {
158 ok(UdpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid owner\n");
159
160 ok(UdpTableOwnerMod->table[i].liCreateTimestamp.QuadPart >= CreationTime.QuadPart, "Invalid time\n");
161 ok(UdpTableOwnerMod->table[i].liCreateTimestamp.QuadPart <= CreationTime.QuadPart + 60000000000LL, "Invalid time\n");
162 }
163
164 HeapFree(GetProcessHeap(), 0, UdpTableOwnerMod);
165 }
166 else
167 {
168 skip("GetExtendedUdpTableWithAlloc failure\n");
169 }
170
171quit2:
173quit:
174 WSACleanup();
175}
static DWORD GetExtendedUdpTableWithAlloc(PVOID *UdpTable, BOOL Order, DWORD Family, UDP_TABLE_CLASS Class)
unsigned char BOOLEAN
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
#define START_TEST(x)
Definition: atltest.h:75
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
return Found
Definition: dirsup.c:1270
#define NO_ERROR
Definition: dderror.h:5
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_SUCCESS
Definition: deptool.c:10
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
#define FALSE
Definition: types.h:117
#define GetProcessHeap()
Definition: compat.h:736
#define HeapAlloc
Definition: compat.h:733
#define HeapFree(x, y, z)
Definition: compat.h:735
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define IPPROTO_UDP
Definition: ip.h:197
#define AF_INET
Definition: tcpip.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
unsigned long DWORD
Definition: ntddk_ex.h:95
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
DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
enum _UDP_TABLE_CLASS UDP_TABLE_CLASS
@ UDP_TABLE_BASIC
Definition: iprtrmib.h:43
@ UDP_TABLE_OWNER_MODULE
Definition: iprtrmib.h:45
@ UDP_TABLE_OWNER_PID
Definition: iprtrmib.h:44
#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
static int Family
Definition: ping.c:62
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
LARGE_INTEGER liCreateTimestamp
Definition: udpmib.h:56
DWORD dwLocalAddr
Definition: udpmib.h:28
DWORD dwLocalPort
Definition: udpmib.h:29
MIB_UDPROW_OWNER_MODULE table[1]
Definition: udpmib.h:71
MIB_UDPROW_OWNER_PID table[1]
Definition: udpmib.h:48
DWORD dwNumEntries
Definition: udpmib.h:34
MIB_UDPROW table[1]
Definition: udpmib.h:35
Definition: tcpcore.h:1455
#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
int ret
_Must_inspect_result_ _In_ WDFDEVICE _In_ PWDF_DEVICE_PROPERTY_DATA _In_ DEVPROPTYPE _In_ ULONG Size
Definition: wdfdevice.h:4533
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60
#define INVALID_SOCKET
Definition: winsock.h:332
#define SOCK_DGRAM
Definition: winsock.h:336
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCKET_ERROR
Definition: winsock.h:333