ReactOS 0.4.16-dev-320-g3bd9ddc
GetOwnerModuleFromUdpEntry.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 owner 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_OWNER_MODULE UdpTableOwnerMod;
47 DWORD i;
49 FILETIME Creation;
50 LARGE_INTEGER CreationTime;
52
53 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
54 {
55 skip("Failed to init WS2\n");
56 return;
57 }
58
59 GetSystemTimeAsFileTime(&Creation);
60 CreationTime.LowPart = Creation.dwLowDateTime;
61 CreationTime.HighPart = Creation.dwHighDateTime;
62
64 if (sock == INVALID_SOCKET)
65 {
66 skip("Cannot create socket\n");
67 goto quit;
68 }
69
70 ZeroMemory(&server, sizeof(SOCKADDR_IN));
71 server.sin_family = AF_INET;
72 server.sin_addr.s_addr = htonl(INADDR_ANY);
73 server.sin_port = htons(9876);
74
75 if (bind(sock, (SOCKADDR*)&server, sizeof(SOCKADDR_IN)) == SOCKET_ERROR)
76 {
77 skip("Cannot bind socket\n");
78 goto quit2;
79 }
80
82 {
83 ok(UdpTableOwnerMod->dwNumEntries > 0, "No UDP connections?!\n");
84
85 Found = FALSE;
86 for (i = 0; i < UdpTableOwnerMod->dwNumEntries; ++i)
87 {
88 if (UdpTableOwnerMod->table[i].dwLocalAddr == 0 &&
89 UdpTableOwnerMod->table[i].dwLocalPort == htons(9876))
90 {
91 Found = TRUE;
92 break;
93 }
94 }
95
96 if (!Found)
97 {
98 skip("Our socket wasn't found!\n");
99 }
100 else
101 {
102 DWORD Size = 0;
104
105 ok(UdpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid owner\n");
106
107 ok(UdpTableOwnerMod->table[i].liCreateTimestamp.QuadPart >= CreationTime.QuadPart, "Invalid time\n");
108 ok(UdpTableOwnerMod->table[i].liCreateTimestamp.QuadPart <= CreationTime.QuadPart + 60000000000LL, "Invalid time\n");
109
111 {
113 ok(BasicInfo != NULL, "HeapAlloc failed\n");
114
115 if (GetOwnerModuleFromUdpEntry(&UdpTableOwnerMod->table[i], TCPIP_OWNER_MODULE_INFO_BASIC, BasicInfo, &Size) == ERROR_SUCCESS)
116 {
117 WCHAR CurrentModule[MAX_PATH];
119
120 if (GetModuleFileNameW(NULL, CurrentModule, MAX_PATH) != 0)
121 {
122 FileName = wcsrchr(CurrentModule, L'\\');
123 ++FileName;
124
125 ok(_wcsicmp(CurrentModule, BasicInfo->pModulePath) == 0, "Mismatching names (%S, %S)\n", CurrentModule, BasicInfo->pModulePath);
126 ok(_wcsicmp(FileName, BasicInfo->pModuleName) == 0, "Mismatching names (%S, %S)\n", FileName, BasicInfo->pModuleName);
127 }
128 else
129 {
130 skip("GetModuleFileNameW failed\n");
131 }
132 }
133 else
134 {
135 skip("GetOwnerModuleFromTcpEntry failed\n");
136 }
137 }
138 else
139 {
140 skip("GetOwnerModuleFromTcpEntry failed\n");
141 }
142 }
143
144 HeapFree(GetProcessHeap(), 0, UdpTableOwnerMod);
145 }
146 else
147 {
148 skip("GetExtendedUdpTableWithAlloc failure\n");
149 }
150
151quit2:
153quit:
154 WSACleanup();
155}
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 wcsrchr
Definition: compat.h:16
#define HeapAlloc
Definition: compat.h:733
#define MAX_PATH
Definition: compat.h:34
#define HeapFree(x, y, z)
Definition: compat.h:735
#define HEAP_ZERO_MEMORY
Definition: compat.h:134
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:600
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
struct _FileName FileName
Definition: fatprocs.h:897
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)
DWORD WINAPI GetOwnerModuleFromUdpEntry(PMIB_UDPROW_OWNER_MODULE pUdpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize)
@ TCPIP_OWNER_MODULE_INFO_BASIC
Definition: iprtrmib.h:51
enum _UDP_TABLE_CLASS UDP_TABLE_CLASS
@ UDP_TABLE_OWNER_MODULE
Definition: iprtrmib.h:45
#define INADDR_ANY
Definition: inet.h:80
#define htons(x)
Definition: module.h:215
#define htonl(x)
Definition: module.h:214
#define closesocket
Definition: ncftp.h:477
#define L(x)
Definition: ntvdm.h:50
static int Family
Definition: ping.c:62
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
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
MIB_UDPROW_OWNER_MODULE table[1]
Definition: udpmib.h:71
Definition: tcpcore.h:1455
uint16_t * PWSTR
Definition: typedefs.h:56
#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:1737
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
__wchar_t WCHAR
Definition: xmlstorage.h:180