ReactOS  0.4.14-dev-845-g8381e29
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
static int Family
Definition: ping.c:62
smooth NULL
Definition: ftsmooth.c:416
#define GetProcessHeap()
Definition: compat.h:403
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 GetExtendedTcpTable(PVOID pTcpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, TCP_TABLE_CLASS TableClass, ULONG Reserved)
#define HeapFree(x, y, z)
Definition: compat.h:402
#define ERROR_OUTOFMEMORY
Definition: deptool.c:13
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( GetOwnerModuleFromTcpEntry  )

Definition at line 41 of file GetOwnerModuleFromTcpEntry.c.

42 {
43  WSADATA wsaData;
44  SOCKET sock;
46  PMIB_TCPTABLE_OWNER_MODULE TcpTableOwnerMod;
47  DWORD i;
48  BOOLEAN Found;
49  FILETIME Creation;
50  LARGE_INTEGER CreationTime;
51  DWORD Pid = GetCurrentProcessId();
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  {
126  PWSTR FileName;
127 
129  {
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 
159 quit2:
160  closesocket(sock);
161 quit:
162  WSACleanup();
163 }
#define SOCKET_ERROR
Definition: winsock.h:333
DWORD WINAPI GetModuleFileNameW(HINSTANCE hModule, LPWSTR lpFilename, DWORD nSize)
Definition: loader.c:609
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 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
uint16_t * PWSTR
Definition: typedefs.h:54
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:1642
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
#define SOMAXCONN
Definition: winsock.h:399
DWORD WINAPI GetOwnerModuleFromTcpEntry(PMIB_TCPROW_OWNER_MODULE pTcpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize)
unsigned char BOOLEAN
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
smooth NULL
Definition: ftsmooth.c:416
static DWORD GetExtendedTcpTableWithAlloc(PVOID *TcpTable, BOOL Order, DWORD Family, TCP_TABLE_CLASS Class)
_Check_return_ _CRTIMP _CONST_RETURN wchar_t *__cdecl wcsrchr(_In_z_ const wchar_t *_Str, _In_ wchar_t _Ch)
return Found
Definition: dirsup.c:1270
PLOADER_MODULE CurrentModule
Definition: mboot.c:66
#define GetProcessHeap()
Definition: compat.h:403
PVOID WINAPI HeapAlloc(HANDLE, DWORD, SIZE_T)
#define INVALID_SOCKET
Definition: winsock.h:332
__wchar_t WCHAR
Definition: xmlstorage.h:180
#define MAX_PATH
Definition: compat.h:26
unsigned long DWORD
Definition: ntddk_ex.h:95
static const WCHAR L[]
Definition: oid.c:1250
ULONG LowPart
Definition: typedefs.h:104
IN PVOID IN PVOID IN USHORT IN USHORT Size
Definition: pci.h:359
struct _FileName FileName
Definition: fatprocs.h:884
#define ok(value,...)
Definition: atltest.h:57
#define HEAP_ZERO_MEMORY
Definition: compat.h:123
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
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 SOCK_STREAM
Definition: tcpip.h:118
#define htons(x)
Definition: module.h:213
#define HeapFree(x, y, z)
Definition: compat.h:402
_Check_return_ _CRTIMP int __cdecl _wcsicmp(_In_z_ const wchar_t *_Str1, _In_z_ const wchar_t *_Str2)
DWORD dwLowDateTime
Definition: mapidefs.h:65
DWORD WINAPI GetCurrentProcessId(VOID)
Definition: proc.c:1158
LONGLONG QuadPart
Definition: typedefs.h:112
#define ERROR_INSUFFICIENT_BUFFER
Definition: dderror.h:10