ReactOS 0.4.15-dev-8135-g1bc6c90
GetOwnerModuleFromTcpEntry.c File Reference
#include <apitest.h>
#include <iphlpapi.h>
#include <winsock2.h>
Include dependency graph for GetOwnerModuleFromTcpEntry.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 (GetOwnerModuleFromTcpEntry)
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 10 of file GetOwnerModuleFromTcpEntry.c.

Function Documentation

◆ GetExtendedTcpTableWithAlloc()

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

Definition at line 14 of file GetOwnerModuleFromTcpEntry.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 ( GetOwnerModuleFromTcpEntry  )

Definition at line 41 of file GetOwnerModuleFromTcpEntry.c.

42{
43 WSADATA wsaData;
46 PMIB_TCPTABLE_OWNER_MODULE TcpTableOwnerMod;
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 skip("Cannot listen on socket\n");
84 goto quit2;
85 }
86
88 {
89 ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n");
90
91 Found = FALSE;
92 for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
93 {
94 if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
95 TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
96 TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
97 TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
98 {
99 Found = TRUE;
100 break;
101 }
102 }
103
104 if (!Found)
105 {
106 skip("Our socket wasn't found!\n");
107 }
108 else
109 {
110 DWORD Size = 0;
112
113 ok(TcpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid owner\n");
114
115 ok(TcpTableOwnerMod->table[i].liCreateTimestamp.QuadPart >= CreationTime.QuadPart, "Invalid time\n");
116 ok(TcpTableOwnerMod->table[i].liCreateTimestamp.QuadPart <= CreationTime.QuadPart + 60000000000LL, "Invalid time\n");
117
118 if (GetOwnerModuleFromTcpEntry(&TcpTableOwnerMod->table[i], TCPIP_OWNER_MODULE_INFO_BASIC, BasicInfo, &Size) == ERROR_INSUFFICIENT_BUFFER)
119 {
121 ok(BasicInfo != NULL, "HeapAlloc failed\n");
122
123 if (GetOwnerModuleFromTcpEntry(&TcpTableOwnerMod->table[i], TCPIP_OWNER_MODULE_INFO_BASIC, BasicInfo, &Size) == ERROR_SUCCESS)
124 {
125 WCHAR CurrentModule[MAX_PATH];
127
128 if (GetModuleFileNameW(NULL, CurrentModule, MAX_PATH) != 0)
129 {
130 FileName = wcsrchr(CurrentModule, L'\\');
131 ++FileName;
132
133 ok(_wcsicmp(CurrentModule, BasicInfo->pModulePath) == 0, "Mismatching names (%S, %S)\n", CurrentModule, BasicInfo->pModulePath);
134 ok(_wcsicmp(FileName, BasicInfo->pModuleName) == 0, "Mismatching names (%S, %S)\n", FileName, BasicInfo->pModuleName);
135 }
136 else
137 {
138 skip("GetModuleFileNameW failed\n");
139 }
140 }
141 else
142 {
143 skip("GetOwnerModuleFromTcpEntry failed\n");
144 }
145 }
146 else
147 {
148 skip("GetOwnerModuleFromTcpEntry failed\n");
149 }
150 }
151
152 HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
153 }
154 else
155 {
156 skip("GetExtendedTcpTableWithAlloc failure\n");
157 }
158
159quit2:
161quit:
162 WSACleanup();
163}
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
#define wcsrchr
Definition: compat.h:16
#define MAX_PATH
Definition: compat.h:34
#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 SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
struct _FileName FileName
Definition: fatprocs.h:896
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 GetOwnerModuleFromTcpEntry(PMIB_TCPROW_OWNER_MODULE pTcpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize)
@ TCPIP_OWNER_MODULE_INFO_BASIC
Definition: iprtrmib.h:51
@ 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
#define L(x)
Definition: ntvdm.h:50
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
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
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
#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
__wchar_t WCHAR
Definition: xmlstorage.h:180