ReactOS  0.4.15-dev-1068-g467feb9
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;
44  SOCKET sock;
46  PMIB_UDPTABLE UdpTable;
47  PMIB_UDPTABLE_OWNER_PID UdpTableOwner;
48  PMIB_UDPTABLE_OWNER_MODULE UdpTableOwnerMod;
49  DWORD i;
50  BOOLEAN Found;
51  FILETIME Creation;
52  LARGE_INTEGER CreationTime;
53  DWORD Pid = GetCurrentProcessId();
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 
171 quit2:
172  closesocket(sock);
173 quit:
174  WSACleanup();
175 }
#define SOCKET_ERROR
Definition: winsock.h:333
VOID WINAPI GetSystemTimeAsFileTime(OUT PFILETIME lpFileTime)
Definition: time.c:128
#define LL
Definition: tui.h:84
static rfbScreenInfoPtr server
Definition: vnc.c:74
static SOCKET sock
Definition: syslog.c:45
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define ERROR_SUCCESS
Definition: deptool.c:10
#define htonl(x)
Definition: module.h:212
#define MAKEWORD(a, b)
Definition: typedefs.h:248
#define TRUE
Definition: types.h:120
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
#define closesocket
Definition: precomp.h:57
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
#define INADDR_ANY
Definition: StrAddr.c:4
#define ZeroMemory
Definition: winbase.h:1648
static DWORD GetExtendedUdpTableWithAlloc(PVOID *UdpTable, BOOL Order, DWORD Family, UDP_TABLE_CLASS Class)
#define NO_ERROR
Definition: dderror.h:5
DWORD dwHighDateTime
Definition: mapidefs.h:66
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
static int Family
Definition: ping.c:62
#define FALSE
Definition: types.h:117
unsigned int BOOL
Definition: ntddk_ex.h:94
START_TEST(GetExtendedUdpTable)
unsigned char BOOLEAN
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
enum _UDP_TABLE_CLASS UDP_TABLE_CLASS
return Found
Definition: dirsup.c:1270
#define GetProcessHeap()
Definition: compat.h:484
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define INVALID_SOCKET
Definition: winsock.h:332
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
ULONG LowPart
Definition: typedefs.h:106
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:361
#define ok(value,...)
Definition: atltest.h:57
DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
Definition: tcpcore.h:1455
#define skip(...)
Definition: atltest.h:64
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
#define htons(x)
Definition: module.h:213
#define SOCK_DGRAM
Definition: winsock.h:336
#define HeapFree(x, y, z)
Definition: compat.h:483
DWORD dwLowDateTime
Definition: mapidefs.h:65
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
LONGLONG QuadPart
Definition: typedefs.h:114
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10