ReactOS 0.4.15-dev-8127-g6338913
ServiceNetwork.c File Reference
#include "precomp.h"
#include "svchlp.h"
#include <iphlpapi.h>
#include <winsock2.h>
Include dependency graph for ServiceNetwork.c:

Go to the source code of this file.

Macros

#define WIN32_NO_STATUS
 

Functions

static void report_service_status (DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
 
static VOID WINAPI service_handler (DWORD ctrl)
 
static DWORD GetExtendedTcpTableWithAlloc (PVOID *TcpTable, BOOL Order, DWORD Family, TCP_TABLE_CLASS Class)
 
static DWORD GetExtendedUdpTableWithAlloc (PVOID *UdpTable, BOOL Order, DWORD Family, UDP_TABLE_CLASS Class)
 
static void test_tcp (LPWSTR svc_name, DWORD service_tag)
 
static void test_udp (LPWSTR svc_name, DWORD service_tag)
 
static void WINAPI service_main (DWORD dwArgc, LPWSTR *lpszArgv)
 
static BOOL start_service (PCSTR service_nameA, PCWSTR service_nameW)
 
static void my_test_server (PCSTR service_nameA, PCWSTR service_nameW, void *param)
 
 START_TEST (ServiceNetwork)
 

Variables

static SERVICE_STATUS_HANDLE status_handle
 

Macro Definition Documentation

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 12 of file ServiceNetwork.c.

Function Documentation

◆ GetExtendedTcpTableWithAlloc()

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

Definition at line 70 of file ServiceNetwork.c.

71{
72 DWORD ret;
73 DWORD Size = 0;
74
75 *TcpTable = NULL;
76
77 ret = GetExtendedTcpTable(*TcpTable, &Size, Order, Family, Class, 0);
79 {
80 *TcpTable = HeapAlloc(GetProcessHeap(), 0, Size);
81 if (*TcpTable == NULL)
82 {
83 return ERROR_OUTOFMEMORY;
84 }
85
86 ret = GetExtendedTcpTable(*TcpTable, &Size, Order, Family, Class, 0);
87 if (ret != NO_ERROR)
88 {
89 HeapFree(GetProcessHeap(), 0, *TcpTable);
90 *TcpTable = NULL;
91 }
92 }
93
94 return ret;
95}
#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 test_tcp().

◆ GetExtendedUdpTableWithAlloc()

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

Definition at line 97 of file ServiceNetwork.c.

98{
99 DWORD ret;
100 DWORD Size = 0;
101
102 *UdpTable = NULL;
103
104 ret = GetExtendedUdpTable(*UdpTable, &Size, Order, Family, Class, 0);
106 {
107 *UdpTable = HeapAlloc(GetProcessHeap(), 0, Size);
108 if (*UdpTable == NULL)
109 {
110 return ERROR_OUTOFMEMORY;
111 }
112
113 ret = GetExtendedUdpTable(*UdpTable, &Size, Order, Family, Class, 0);
114 if (ret != NO_ERROR)
115 {
116 HeapFree(GetProcessHeap(), 0, *UdpTable);
117 *UdpTable = NULL;
118 }
119 }
120
121 return ret;
122}
DWORD WINAPI GetExtendedUdpTable(PVOID pUdpTable, PDWORD pdwSize, BOOL bOrder, ULONG ulAf, UDP_TABLE_CLASS TableClass, ULONG Reserved)

Referenced by test_udp().

◆ my_test_server()

static void my_test_server ( PCSTR  service_nameA,
PCWSTR  service_nameW,
void param 
)
static

Definition at line 319 of file ServiceNetwork.c.

322{
323 BOOL res;
324 SC_HANDLE hSC = NULL;
325 SC_HANDLE hService = NULL;
327
328 /* Open the SCM */
330 if (!hSC)
331 {
332 skip("OpenSCManagerW failed with error %lu!\n", GetLastError());
333 return;
334 }
335
336 /* First create ourselves as a service running in the default LocalSystem account */
337 hService = register_service_exW(hSC, L"ServiceNetwork", service_nameW, NULL,
342 NULL, NULL, NULL,
343 NULL, NULL);
344 if (!hService)
345 {
346 skip("CreateServiceW failed with error %lu!\n", GetLastError());
347 goto Cleanup;
348 }
349
350 /* Start it */
351 if (!StartServiceW(hService, 0, NULL))
352 {
353 skip("StartServiceW failed with error %lu!\n", GetLastError());
354 goto Cleanup;
355 }
356
357 /* Wait for the service to stop by itself */
358 do
359 {
360 Sleep(100);
364 ok(res, "QueryServiceStatus failed: %lu\n", GetLastError());
365 ok(ServiceStatus.dwCurrentState == SERVICE_STOPPED, "ServiceStatus.dwCurrentState = %lx\n", ServiceStatus.dwCurrentState);
366
367 /* Be sure the service is really stopped */
372 {
373 skip("ControlService failed with error %lu!\n", GetLastError());
374 goto Cleanup;
375 }
376
377#if 0
378 trace("Service stopped. Going to restart it...\n");
379
380 /* Now change the service configuration to make it start under the NetworkService account */
381 if (!ChangeServiceConfigW(hService,
385 NULL, NULL, NULL, NULL,
386 L"NT AUTHORITY\\NetworkService", L"",
387 NULL))
388 {
389 skip("ChangeServiceConfigW failed with error %lu!\n", GetLastError());
390 goto Cleanup;
391 }
392
393 /* Start it */
394 if (!StartServiceW(hService, 0, NULL))
395 {
396 skip("StartServiceW failed with error %lu!\n", GetLastError());
397 goto Cleanup;
398 }
399
400 /* Wait for the service to stop by itself */
401 do
402 {
403 Sleep(100);
407 ok(res, "QueryServiceStatus failed: %lu\n", GetLastError());
408 ok(ServiceStatus.dwCurrentState == SERVICE_STOPPED, "ServiceStatus.dwCurrentState = %lx\n", ServiceStatus.dwCurrentState);
409
410 /* Be sure the service is really stopped */
415 {
416 skip("ControlService failed with error %lu!\n", GetLastError());
417 goto Cleanup;
418 }
419#endif
420
421Cleanup:
422 if (hService)
423 {
424 res = DeleteService(hService);
425 ok(res, "DeleteService failed: %lu\n", GetLastError());
426 CloseServiceHandle(hService);
427 }
428
429 if (hSC)
431}
static WCHAR service_nameW[100]
Definition: ServiceArgs.c:16
#define trace
Definition: atltest.h:70
#define ok(value,...)
Definition: atltest.h:57
#define skip(...)
Definition: atltest.h:64
static SERVICE_STATUS ServiceStatus
Definition: browser.c:22
static const WCHAR Cleanup[]
Definition: register.c:80
unsigned int BOOL
Definition: ntddk_ex.h:94
GLuint res
Definition: glext.h:9613
#define L(x)
Definition: ntvdm.h:50
BOOL WINAPI QueryServiceStatus(SC_HANDLE hService, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:2845
BOOL WINAPI DeleteService(SC_HANDLE hService)
Definition: scm.c:921
SC_HANDLE WINAPI OpenSCManagerW(LPCWSTR lpMachineName, LPCWSTR lpDatabaseName, DWORD dwDesiredAccess)
Definition: scm.c:2068
BOOL WINAPI ControlService(SC_HANDLE hService, DWORD dwControl, LPSERVICE_STATUS lpServiceStatus)
Definition: scm.c:622
BOOL WINAPI ChangeServiceConfigW(SC_HANDLE hService, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpBinaryPathName, LPCWSTR lpLoadOrderGroup, LPDWORD lpdwTagId, LPCWSTR lpDependencies, LPCWSTR lpServiceStartName, LPCWSTR lpPassword, LPCWSTR lpDisplayName)
Definition: scm.c:482
BOOL WINAPI StartServiceW(SC_HANDLE hService, DWORD dwNumServiceArgs, LPCWSTR *lpServiceArgVectors)
Definition: scm.c:2980
BOOL WINAPI CloseServiceHandle(SC_HANDLE hSCObject)
Definition: scm.c:580
DWORD dwCurrentState
Definition: winsvc.h:100
SC_HANDLE register_service_exW(SC_HANDLE scm_handle, PCWSTR test_name, PCWSTR service_name, PCWSTR extra_args OPTIONAL, DWORD dwDesiredAccess, DWORD dwServiceType, DWORD dwStartType, DWORD dwErrorControl, LPCWSTR lpLoadOrderGroup OPTIONAL, LPDWORD lpdwTagId OPTIONAL, LPCWSTR lpDependencies OPTIONAL, LPCWSTR lpServiceStartName OPTIONAL, LPCWSTR lpPassword OPTIONAL)
Definition: svchlp.c:142
VOID WINAPI DECLSPEC_HOTPATCH Sleep(IN DWORD dwMilliseconds)
Definition: synch.c:790
#define ZeroMemory
Definition: winbase.h:1712
DWORD WINAPI GetLastError(void)
Definition: except.c:1042
#define ERROR_SERVICE_NOT_ACTIVE
Definition: winerror.h:613
#define SERVICE_STOPPED
Definition: winsvc.h:21
#define SERVICE_ALL_ACCESS
Definition: winsvc.h:62
#define SERVICE_NO_CHANGE
Definition: winsvc.h:20
#define SERVICE_STOP_PENDING
Definition: winsvc.h:23
#define SERVICE_CONTROL_STOP
Definition: winsvc.h:36
#define SC_MANAGER_ALL_ACCESS
Definition: winsvc.h:13
#define SERVICE_DEMAND_START
Definition: cmtypes.h:978
#define SERVICE_INTERACTIVE_PROCESS
Definition: cmtypes.h:967
#define SERVICE_WIN32_OWN_PROCESS
Definition: cmtypes.h:962
#define SERVICE_ERROR_IGNORE
Definition: cmtypes.h:981

Referenced by START_TEST().

◆ report_service_status()

static void report_service_status ( DWORD  dwCurrentState,
DWORD  dwWin32ExitCode,
DWORD  dwWaitHint 
)
static

Definition at line 21 of file ServiceNetwork.c.

24{
25 BOOL res;
27
28 status.dwServiceType = SERVICE_WIN32_OWN_PROCESS;
29 status.dwCurrentState = dwCurrentState;
30 status.dwWin32ExitCode = dwWin32ExitCode;
31 status.dwWaitHint = dwWaitHint;
32
33 status.dwServiceSpecificExitCode = 0;
34 status.dwCheckPoint = 0;
35
36 if ( (dwCurrentState == SERVICE_START_PENDING) ||
37 (dwCurrentState == SERVICE_STOP_PENDING) ||
38 (dwCurrentState == SERVICE_STOPPED) )
39 {
40 status.dwControlsAccepted = 0;
41 }
42 else
43 {
45 }
46
47#if 0
48 if ( (dwCurrentState == SERVICE_RUNNING) || (dwCurrentState == SERVICE_STOPPED) )
49 status.dwCheckPoint = 0;
50 else
51 status.dwCheckPoint = dwCheckPoint++;
52#endif
53
55 service_ok(res, "SetServiceStatus(%d) failed: %lu\n", dwCurrentState, GetLastError());
56}
static void service_ok(int cnd, const char *msg,...)
Definition: ServiceArgs.c:46
static SERVICE_STATUS_HANDLE status_handle
BOOL WINAPI SetServiceStatus(SERVICE_STATUS_HANDLE hServiceStatus, LPSERVICE_STATUS lpServiceStatus)
Definition: sctrl.c:997
Definition: ps.c:97
#define SERVICE_ACCEPT_STOP
Definition: winsvc.h:28
#define SERVICE_START_PENDING
Definition: winsvc.h:22
#define SERVICE_RUNNING
Definition: winsvc.h:24
#define SERVICE_ACCEPT_SHUTDOWN
Definition: winsvc.h:30

Referenced by service_handler(), and service_main().

◆ service_handler()

static VOID WINAPI service_handler ( DWORD  ctrl)
static

Definition at line 58 of file ServiceNetwork.c.

59{
60 switch(ctrl)
61 {
65 default:
67 }
68}
static void report_service_status(DWORD dwCurrentState, DWORD dwWin32ExitCode, DWORD dwWaitHint)
#define ctrl
Definition: input.c:1756
#define SERVICE_CONTROL_SHUTDOWN
Definition: winsvc.h:40

Referenced by service_main().

◆ service_main()

static void WINAPI service_main ( DWORD  dwArgc,
LPWSTR lpszArgv 
)
static

Definition at line 264 of file ServiceNetwork.c.

265{
266 // SERVICE_STATUS_HANDLE status_handle;
267 PTEB Teb;
268 WSADATA wsaData;
269
271
272 /* Register our service for control (lpszArgv[0] holds the service name) */
274 service_ok(status_handle != NULL, "RegisterServiceCtrlHandler failed: %lu\n", GetLastError());
275 if (!status_handle)
276 return;
277
278 /* Report SERVICE_RUNNING status */
280
281 /* Check our tag is not 0 */
282 Teb = NtCurrentTeb();
283 service_ok(Teb->SubProcessTag != 0, "SubProcessTag is not defined!\n");
284
285 if (WSAStartup(MAKEWORD(2, 2), &wsaData) != 0)
286 {
287 skip("Failed to init WS2\n");
288 goto quit;
289 }
290
291 test_tcp(lpszArgv[0], PtrToUlong(Teb->SubProcessTag));
292 test_udp(lpszArgv[0], PtrToUlong(Teb->SubProcessTag));
293
294 WSACleanup();
295quit:
296 /* Work is done */
298}
static VOID WINAPI service_handler(DWORD ctrl)
static void test_udp(LPWSTR svc_name, DWORD service_tag)
static void test_tcp(LPWSTR svc_name, DWORD service_tag)
void quit(int argc, const char *argv[])
Definition: cmds.c:1606
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define PtrToUlong(u)
Definition: config.h:107
#define NtCurrentTeb
#define UNREFERENCED_PARAMETER(P)
Definition: ntbasedef.h:317
SERVICE_STATUS_HANDLE WINAPI RegisterServiceCtrlHandlerW(LPCWSTR lpServiceName, LPHANDLER_FUNCTION lpHandlerProc)
Definition: sctrl.c:742
Definition: compat.h:836
#define MAKEWORD(a, b)
Definition: typedefs.h:248
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60

Referenced by start_service().

◆ start_service()

static BOOL start_service ( PCSTR  service_nameA,
PCWSTR  service_nameW 
)
static

Definition at line 300 of file ServiceNetwork.c.

301{
302 BOOL res;
303
304 SERVICE_TABLE_ENTRYW servtbl[] =
305 {
307 { NULL, NULL }
308 };
309
311 service_ok(res, "StartServiceCtrlDispatcherW failed: %lu\n", GetLastError());
312 return res;
313}
static void WINAPI service_main(DWORD dwArgc, LPWSTR *lpszArgv)
BOOL WINAPI StartServiceCtrlDispatcherW(const SERVICE_TABLE_ENTRYW *lpServiceStartTable)
Definition: sctrl.c:1134
uint16_t * PWSTR
Definition: typedefs.h:56

Referenced by START_TEST().

◆ START_TEST()

START_TEST ( ServiceNetwork  )

Definition at line 433 of file ServiceNetwork.c.

434{
435 int argc;
436 char** argv;
437
438 /* Check whether this test is started as a separated service process */
440 if (argc >= 3)
441 {
443 return;
444 }
445
446 /* We are started as the real test */
448 // trace("Returned from test_runner\n");
449}
static void test_runner(BOOLEAN unicode, PCWSTR extra_args, int service_argc, void *service_argv)
Definition: ServiceArgs.c:334
static void service_process(BOOLEAN unicode)
Definition: ServiceArgs.c:188
static int argc
Definition: ServiceArgs.c:12
static BOOL start_service(PCSTR service_nameA, PCWSTR service_nameW)
static void my_test_server(PCSTR service_nameA, PCWSTR service_nameW, void *param)
#define argv
Definition: mplay32.c:18
int winetest_get_mainargs(char ***pargv)

◆ test_tcp()

static void test_tcp ( LPWSTR  svc_name,
DWORD  service_tag 
)
static

Definition at line 125 of file ServiceNetwork.c.

126{
127 SOCKET sock;
129 PMIB_TCPTABLE_OWNER_MODULE TcpTableOwnerMod;
130 DWORD i, ret;
133
135 service_ok(sock != INVALID_SOCKET, "Socket creation failed!\n");
136
137 ZeroMemory(&server, sizeof(SOCKADDR_IN));
138 server.sin_family = AF_INET;
139 server.sin_addr.s_addr = htonl(INADDR_ANY);
140 server.sin_port = htons(9876);
141
142 ret = bind(sock, (SOCKADDR*)&server, sizeof(SOCKADDR_IN));
143 service_ok(ret != SOCKET_ERROR, "binding failed\n");
144
146 service_ok(ret != SOCKET_ERROR, "listening failed\n");
147
149 service_ok(ret == ERROR_SUCCESS, "GetExtendedTcpTableWithAlloc failed: %x\n", ret);
150 if (ret == ERROR_SUCCESS)
151 {
152 service_ok(TcpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n");
153
154 Found = FALSE;
155 for (i = 0; i < TcpTableOwnerMod->dwNumEntries; ++i)
156 {
157 if (TcpTableOwnerMod->table[i].dwState == MIB_TCP_STATE_LISTEN &&
158 TcpTableOwnerMod->table[i].dwLocalAddr == 0 &&
159 TcpTableOwnerMod->table[i].dwLocalPort == htons(9876) &&
160 TcpTableOwnerMod->table[i].dwRemoteAddr == 0)
161 {
162 Found = TRUE;
163 break;
164 }
165 }
166
167 service_ok(Found, "Our socket wasn't found!\n");
168 if (Found)
169 {
170 DWORD Size = 0;
172
173 service_ok(TcpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid owner\n");
174 service_ok((DWORD)(TcpTableOwnerMod->table[i].OwningModuleInfo[0]) == service_tag, "Invalid tag: %x - %x\n", (DWORD)TcpTableOwnerMod->table[i].OwningModuleInfo[0], service_tag);
175
176 ret = GetOwnerModuleFromTcpEntry(&TcpTableOwnerMod->table[i], TCPIP_OWNER_MODULE_INFO_BASIC, BasicInfo, &Size);
177 service_ok(ret == ERROR_INSUFFICIENT_BUFFER, "GetOwnerModuleFromTcpEntry failed with: %x\n", ret);
179 {
181 service_ok(BasicInfo != NULL, "HeapAlloc failed\n");
182
183 ret = GetOwnerModuleFromTcpEntry(&TcpTableOwnerMod->table[i], TCPIP_OWNER_MODULE_INFO_BASIC, BasicInfo, &Size);
184 service_ok(ret == ERROR_SUCCESS, "GetOwnerModuleFromTcpEntry failed with: %x\n", ret);
185 service_ok(_wcsicmp(svc_name, BasicInfo->pModulePath) == 0, "Mismatching names (%S, %S)\n", svc_name, BasicInfo->pModulePath);
186 service_ok(_wcsicmp(svc_name, BasicInfo->pModuleName) == 0, "Mismatching names (%S, %S)\n", svc_name, BasicInfo->pModuleName);
187 }
188 }
189
190 HeapFree(GetProcessHeap(), 0, TcpTableOwnerMod);
191 }
192
194}
unsigned char BOOLEAN
static DWORD GetExtendedTcpTableWithAlloc(PVOID *TcpTable, BOOL Order, DWORD Family, TCP_TABLE_CLASS Class)
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 HEAP_ZERO_MEMORY
Definition: compat.h:134
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
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
_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
ULONGLONG OwningModuleInfo[TCPIP_OWNING_MODULE_SIZE]
Definition: tcpmib.h:127
MIB_TCPROW_OWNER_MODULE table[1]
Definition: tcpmib.h:133
Definition: tcpcore.h:1455
@ MIB_TCP_STATE_LISTEN
Definition: tcpmib.h:29
static rfbScreenInfoPtr server
Definition: vnc.c:74
DWORD WINAPI GetCurrentProcessId(void)
Definition: proc.c:1158
#define SOMAXCONN
Definition: winsock.h:399
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
#define SOCKET_ERROR
Definition: winsock.h:333

Referenced by service_main().

◆ test_udp()

static void test_udp ( LPWSTR  svc_name,
DWORD  service_tag 
)
static

Definition at line 197 of file ServiceNetwork.c.

198{
199 SOCKET sock;
201 PMIB_UDPTABLE_OWNER_MODULE UdpTableOwnerMod;
202 DWORD i, ret;
205
207 service_ok(sock != INVALID_SOCKET, "Socket creation failed!\n");
208
209 ZeroMemory(&server, sizeof(SOCKADDR_IN));
210 server.sin_family = AF_INET;
211 server.sin_addr.s_addr = htonl(INADDR_ANY);
212 server.sin_port = htons(9876);
213
214 ret = bind(sock, (SOCKADDR*)&server, sizeof(SOCKADDR_IN));
215 service_ok(ret != SOCKET_ERROR, "binding failed\n");
216
218 service_ok(ret == ERROR_SUCCESS, "GetExtendedUdpTableWithAlloc failed: %x\n", ret);
219 if (ret == ERROR_SUCCESS)
220 {
221 service_ok(UdpTableOwnerMod->dwNumEntries > 0, "No TCP connections?!\n");
222
223 Found = FALSE;
224 for (i = 0; i < UdpTableOwnerMod->dwNumEntries; ++i)
225 {
226 if (UdpTableOwnerMod->table[i].dwLocalAddr == 0 &&
227 UdpTableOwnerMod->table[i].dwLocalPort == htons(9876))
228 {
229 Found = TRUE;
230 break;
231 }
232 }
233
234 service_ok(Found, "Our socket wasn't found!\n");
235 if (Found)
236 {
237 DWORD Size = 0;
239
240 service_ok(UdpTableOwnerMod->table[i].dwOwningPid == Pid, "Invalid owner\n");
241 service_ok((DWORD)(UdpTableOwnerMod->table[i].OwningModuleInfo[0]) == service_tag, "Invalid tag: %x - %x\n", (DWORD)UdpTableOwnerMod->table[i].OwningModuleInfo[0], service_tag);
242
243 ret = GetOwnerModuleFromUdpEntry(&UdpTableOwnerMod->table[i], TCPIP_OWNER_MODULE_INFO_BASIC, BasicInfo, &Size);
244 service_ok(ret == ERROR_INSUFFICIENT_BUFFER, "GetOwnerModuleFromUdpEntry failed with: %x\n", ret);
246 {
248 service_ok(BasicInfo != NULL, "HeapAlloc failed\n");
249
250 ret = GetOwnerModuleFromUdpEntry(&UdpTableOwnerMod->table[i], TCPIP_OWNER_MODULE_INFO_BASIC, BasicInfo, &Size);
251 service_ok(ret == ERROR_SUCCESS, "GetOwnerModuleFromUdpEntry failed with: %x\n", ret);
252 service_ok(_wcsicmp(svc_name, BasicInfo->pModulePath) == 0, "Mismatching names (%S, %S)\n", svc_name, BasicInfo->pModulePath);
253 service_ok(_wcsicmp(svc_name, BasicInfo->pModuleName) == 0, "Mismatching names (%S, %S)\n", svc_name, BasicInfo->pModuleName);
254 }
255 }
256
257 HeapFree(GetProcessHeap(), 0, UdpTableOwnerMod);
258 }
259
261}
static DWORD GetExtendedUdpTableWithAlloc(PVOID *UdpTable, BOOL Order, DWORD Family, UDP_TABLE_CLASS Class)
#define IPPROTO_UDP
Definition: ip.h:197
DWORD WINAPI GetOwnerModuleFromUdpEntry(PMIB_UDPROW_OWNER_MODULE pUdpEntry, TCPIP_OWNER_MODULE_INFO_CLASS Class, PVOID Buffer, PDWORD pdwSize)
@ UDP_TABLE_OWNER_MODULE
Definition: iprtrmib.h:45
ULONGLONG OwningModuleInfo[TCPIP_OWNING_MODULE_SIZE]
Definition: udpmib.h:65
MIB_UDPROW_OWNER_MODULE table[1]
Definition: udpmib.h:71
#define SOCK_DGRAM
Definition: winsock.h:336

Referenced by service_main().

Variable Documentation

◆ status_handle

SERVICE_STATUS_HANDLE status_handle
static

Definition at line 18 of file ServiceNetwork.c.

Referenced by report_service_status(), and service_main().