ReactOS  0.4.14-dev-317-g96040ec
GetExtendedUdpTable.c File Reference
#include <apitest.h>
#include <iphlpapi.h>
#include <winsock2.h>
Include dependency graph for GetExtendedUdpTable.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

static DWORD GetExtendedUdpTableWithAlloc (PVOID *UdpTable, BOOL Order, DWORD Family, UDP_TABLE_CLASS Class)
 
 START_TEST (GetExtendedUdpTable)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetExtendedUdpTable.c.

Function Documentation

◆ GetExtendedUdpTableWithAlloc()

static DWORD GetExtendedUdpTableWithAlloc ( PVOID UdpTable,
BOOL  Order,
DWORD  Family,
UDP_TABLE_CLASS  Class 
)
static

Definition at line 14 of file GetExtendedUdpTable.c.

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 }
#define NO_ERROR
Definition: dderror.h:5
static int Family
Definition: ping.c:62
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:395
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
unsigned long DWORD
Definition: ntddk_ex.h:95
int ret
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)
#define HeapFree(x, y, z)
Definition: compat.h:394
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( GetExtendedUdpTable  )

Definition at line 41 of file GetExtendedUdpTable.c.

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 TRUE
Definition: types.h:120
#define LL
Definition: tui.h:85
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 closesocket
#define MAKEWORD(a, b)
Definition: typedefs.h:247
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
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
#define INADDR_ANY
Definition: StrAddr.c:4
#define ZeroMemory
Definition: winbase.h:1642
static DWORD GetExtendedUdpTableWithAlloc(PVOID *UdpTable, BOOL Order, DWORD Family, UDP_TABLE_CLASS Class)
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
unsigned char BOOLEAN
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
return Found
Definition: dirsup.c:1270
#define GetProcessHeap()
Definition: compat.h:395
#define INVALID_SOCKET
Definition: winsock.h:332
unsigned long DWORD
Definition: ntddk_ex.h:95
ULONG LowPart
Definition: typedefs.h:104
#define ok(value,...)
Definition: atltest.h:57
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:394
DWORD dwLowDateTime
Definition: mapidefs.h:65
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
LONGLONG QuadPart
Definition: typedefs.h:112