ReactOS 0.4.16-dev-329-g9223134
TcpIp_user.c File Reference
#include <kmt_test.h>
#include <winsock2.h>
#include "tcpip.h"
Include dependency graph for TcpIp_user.c:

Go to the source code of this file.

Functions

static DWORD LoadTcpIpTestDriver (void)
 
static void UnloadTcpIpTestDriver (void)
 
 START_TEST (TcpIpTdi)
 
static DWORD WINAPI AcceptProc (_In_ LPVOID Parameter)
 
 START_TEST (TcpIpConnect)
 

Function Documentation

◆ AcceptProc()

static DWORD WINAPI AcceptProc ( _In_ LPVOID  Parameter)
static

Definition at line 55 of file TcpIp_user.c.

57{
58 WORD WinsockVersion;
59 WSADATA WsaData;
60 int Error;
61 SOCKET ListenSocket, AcceptSocket;
62 struct sockaddr_in ListenAddress, AcceptAddress;
63 int AcceptAddressLength;
64 HANDLE ReadyToConnectEvent = (HANDLE)Parameter;
65
66 /* Initialize winsock */
67 WinsockVersion = MAKEWORD(2, 0);
68 Error = WSAStartup(WinsockVersion, &WsaData);
69 ok_eq_int(Error, 0);
70
71 ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
72 ok(ListenSocket != INVALID_SOCKET, "socket failed\n");
73
74 ZeroMemory(&ListenAddress, sizeof(ListenAddress));
75 ListenAddress.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
76 ListenAddress.sin_port = htons(TEST_CONNECT_SERVER_PORT);
77 ListenAddress.sin_family = AF_INET;
78
79 Error = bind(ListenSocket, (struct sockaddr*)&ListenAddress, sizeof(ListenAddress));
80 ok_eq_int(Error, 0);
81
82 Error = listen(ListenSocket, 1);
83 ok_eq_int(Error, 0);
84
85 SetEvent(ReadyToConnectEvent);
86
87 AcceptAddressLength = sizeof(AcceptAddress);
88 AcceptSocket = accept(ListenSocket, (struct sockaddr*)&AcceptAddress, &AcceptAddressLength);
89 ok(AcceptSocket != INVALID_SOCKET, "accept failed\n");
90 ok_eq_long(AcceptAddressLength, sizeof(AcceptAddress));
91 ok_eq_hex(AcceptAddress.sin_addr.S_un.S_addr, inet_addr("127.0.0.1"));
92 ok_eq_hex(AcceptAddress.sin_port, htons(TEST_CONNECT_CLIENT_PORT));
93
94 return 0;
95}
ULONG WSAAPI inet_addr(IN CONST CHAR FAR *cp)
Definition: addrconv.c:71
#define ok_eq_hex(value, expected)
Definition: apitest.h:77
#define ok_eq_long(value, expected)
Definition: apitest.h:62
#define ok_eq_int(value, expected)
Definition: apitest.h:60
#define ok(value,...)
Definition: atltest.h:57
BOOL Error
Definition: chkdsk.c:66
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define IPPROTO_TCP
Definition: ip.h:196
#define SOCK_STREAM
Definition: tcpip.h:118
#define AF_INET
Definition: tcpip.h:117
unsigned short WORD
Definition: ntddk_ex.h:93
#define htons(x)
Definition: module.h:215
#define TEST_CONNECT_SERVER_PORT
Definition: tcpip.h:6
#define TEST_CONNECT_CLIENT_PORT
Definition: tcpip.h:7
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 accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define MAKEWORD(a, b)
Definition: typedefs.h:248
PVOID HANDLE
Definition: typedefs.h:73
#define ZeroMemory
Definition: winbase.h:1737
#define INVALID_SOCKET
Definition: winsock.h:332
UINT_PTR SOCKET
Definition: winsock.h:47
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _In_opt_ PWSK_SOCKET AcceptSocket
Definition: wsk.h:173
_Inout_opt_ PVOID Parameter
Definition: rtltypes.h:336

Referenced by START_TEST().

◆ LoadTcpIpTestDriver()

static DWORD LoadTcpIpTestDriver ( void  )
static

Definition at line 15 of file TcpIp_user.c.

16{
18
19 /* Start the special-purpose driver */
22 if (Error)
23 return Error;
24
25 return ERROR_SUCCESS;
26}
#define ERROR_SUCCESS
Definition: deptool.c:10
#define FALSE
Definition: types.h:117
unsigned long DWORD
Definition: ntddk_ex.h:95
#define L(x)
Definition: ntvdm.h:50
DWORD KmtLoadAndOpenDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning)
Definition: support.c:213

Referenced by START_TEST().

◆ START_TEST() [1/2]

START_TEST ( TcpIpConnect  )

Definition at line 97 of file TcpIp_user.c.

98{
99 HANDLE AcceptThread;
100 HANDLE ReadyToConnectEvent;
101 DWORD Error;
102
103 ReadyToConnectEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
104 ok(ReadyToConnectEvent != NULL, "CreateEvent failed\n");
105
106 AcceptThread = CreateThread(NULL, 0, AcceptProc, (PVOID)ReadyToConnectEvent, 0, NULL);
107 ok(AcceptThread != NULL, "CreateThread failed\n");
108
109 WaitForSingleObject(ReadyToConnectEvent, INFINITE);
110
112
115
116 Error = WaitForSingleObject(AcceptThread, 10 * 1000);
117 ok(Error == WAIT_OBJECT_0, "AcceptThread timed out\n");
118
120
121 WSACleanup();
122}
static void UnloadTcpIpTestDriver(void)
Definition: TcpIp_user.c:30
static DWORD LoadTcpIpTestDriver(void)
Definition: TcpIp_user.c:15
static DWORD WINAPI AcceptProc(_In_ LPVOID Parameter)
Definition: TcpIp_user.c:55
#define ok_eq_ulong(value, expected)
Definition: apitest.h:63
#define NULL
Definition: types.h:112
#define TRUE
Definition: types.h:120
HANDLE WINAPI DECLSPEC_HOTPATCH CreateThread(IN LPSECURITY_ATTRIBUTES lpThreadAttributes, IN DWORD dwStackSize, IN LPTHREAD_START_ROUTINE lpStartAddress, IN LPVOID lpParameter, IN DWORD dwCreationFlags, OUT LPDWORD lpThreadId)
Definition: thread.c:137
#define INFINITE
Definition: serial.h:102
#define IOCTL_TEST_CONNECT
Definition: tcpip.h:3
DWORD KmtSendToDriver(IN DWORD ControlCode)
Definition: support.c:259
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define CreateEvent
Definition: winbase.h:3773
#define WAIT_OBJECT_0
Definition: winbase.h:432
int PASCAL FAR WSACleanup(void)
Definition: startup.c:60

◆ START_TEST() [2/2]

START_TEST ( TcpIpTdi  )

Definition at line 37 of file TcpIp_user.c.

38{
40
42 ok_eq_int(Error, 0);
43 if (Error)
44 return;
45
48
50}
#define IOCTL_TEST_TDI
Definition: tcpip.h:2

◆ UnloadTcpIpTestDriver()

static void UnloadTcpIpTestDriver ( void  )
static

Definition at line 30 of file TcpIp_user.c.

31{
32 /* Stop the driver. */
35}
VOID KmtCloseDriver(VOID)
Definition: support.c:236
VOID KmtUnloadDriver(VOID)
Definition: support.c:167

Referenced by START_TEST().