ReactOS  0.4.15-dev-1384-g878186b
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 void 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 46 of file TcpIp_user.c.

48 {
49  WORD WinsockVersion;
50  WSADATA WsaData;
51  int Error;
52  SOCKET ListenSocket, AcceptSocket;
53  struct sockaddr_in ListenAddress, AcceptAddress;
54  int AcceptAddressLength;
55  HANDLE ReadyToConnectEvent = (HANDLE)Parameter;
56 
57  /* Initialize winsock */
58  WinsockVersion = MAKEWORD(2, 0);
59  Error = WSAStartup(WinsockVersion, &WsaData);
60  ok_eq_int(Error, 0);
61 
62  ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
63  ok(ListenSocket != INVALID_SOCKET, "socket failed\n");
64 
65  ZeroMemory(&ListenAddress, sizeof(ListenAddress));
66  ListenAddress.sin_addr.S_un.S_addr = inet_addr("127.0.0.1");
67  ListenAddress.sin_port = htons(TEST_CONNECT_SERVER_PORT);
68  ListenAddress.sin_family = AF_INET;
69 
70  Error = bind(ListenSocket, (struct sockaddr*)&ListenAddress, sizeof(ListenAddress));
71  ok_eq_int(Error, 0);
72 
73  Error = listen(ListenSocket, 1);
74  ok_eq_int(Error, 0);
75 
76  SetEvent(ReadyToConnectEvent);
77 
78  AcceptAddressLength = sizeof(AcceptAddress);
79  AcceptSocket = accept(ListenSocket, (struct sockaddr*)&AcceptAddress, &AcceptAddressLength);
80  ok(AcceptSocket != INVALID_SOCKET, "accept failed\n");
81  ok_eq_long(AcceptAddressLength, sizeof(AcceptAddress));
82  ok_eq_hex(AcceptAddress.sin_addr.S_un.S_addr, inet_addr("127.0.0.1"));
83  ok_eq_hex(AcceptAddress.sin_port, htons(TEST_CONNECT_CLIENT_PORT));
84 
85  return 0;
86 }
SOCKET WSAAPI socket(IN INT af, IN INT type, IN INT protocol)
Definition: socklife.c:143
#define inet_addr(cp)
Definition: inet.h:98
#define MAKEWORD(a, b)
Definition: typedefs.h:248
#define ok_eq_int(value, expected)
Definition: kmt_test.h:238
INT WSAAPI bind(IN SOCKET s, IN CONST struct sockaddr *name, IN INT namelen)
Definition: socklife.c:36
BOOL WINAPI DECLSPEC_HOTPATCH SetEvent(IN HANDLE hEvent)
Definition: synch.c:733
#define ZeroMemory
Definition: winbase.h:1648
_In_ PVOID Parameter
Definition: ldrtypes.h:241
#define TEST_CONNECT_CLIENT_PORT
Definition: tcpip.h:7
INT WINAPI WSAStartup(IN WORD wVersionRequested, OUT LPWSADATA lpWSAData)
Definition: startup.c:113
#define INVALID_SOCKET
Definition: winsock.h:332
unsigned short WORD
Definition: ntddk_ex.h:93
PVOID HANDLE
Definition: typedefs.h:73
BOOL Error
Definition: chkdsk.c:66
SOCKET WSAAPI accept(IN SOCKET s, OUT LPSOCKADDR addr, OUT INT FAR *addrlen)
Definition: socklife.c:23
#define TEST_CONNECT_SERVER_PORT
Definition: tcpip.h:6
#define ok(value,...)
Definition: atltest.h:57
INT WSAAPI listen(IN SOCKET s, IN INT backlog)
Definition: sockctrl.c:123
#define AF_INET
Definition: tcpip.h:117
UINT_PTR SOCKET
Definition: winsock.h:47
#define ok_eq_hex(value, expected)
#define SOCK_STREAM
Definition: tcpip.h:118
_Must_inspect_result_ _In_ ULONG _In_ PSOCKADDR _In_ PSOCKADDR _In_opt_ PWSK_SOCKET AcceptSocket
Definition: wsk.h:170
#define htons(x)
Definition: module.h:213
#define ok_eq_long(value, expected)
Definition: kmt_test.h:240

Referenced by START_TEST().

◆ LoadTcpIpTestDriver()

static void LoadTcpIpTestDriver ( void  )
static

Definition at line 15 of file TcpIp_user.c.

16 {
17  /* Start the special-purpose driver */
18  KmtLoadDriver(L"TcpIp", FALSE);
19  KmtOpenDriver();
20 }
#define FALSE
Definition: types.h:117
static const WCHAR L[]
Definition: oid.c:1250
VOID KmtLoadDriver(IN PCWSTR ServiceName, IN BOOLEAN RestartIfRunning)
Definition: support.c:128
VOID KmtOpenDriver(VOID)
Definition: support.c:181

Referenced by START_TEST().

◆ START_TEST() [1/2]

START_TEST ( TcpIpTdi  )

Definition at line 31 of file TcpIp_user.c.

32 {
33  DWORD Error;
34 
36 
39 
41 }
#define ok_eq_ulong(value, expected)
#define IOCTL_TEST_TDI
Definition: tcpip.h:2
#define ERROR_SUCCESS
Definition: deptool.c:10
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
static void UnloadTcpIpTestDriver(void)
Definition: TcpIp_user.c:24
DWORD KmtSendToDriver(IN DWORD ControlCode)
Definition: support.c:231
static void LoadTcpIpTestDriver(void)
Definition: TcpIp_user.c:15

◆ START_TEST() [2/2]

START_TEST ( TcpIpConnect  )

Definition at line 88 of file TcpIp_user.c.

89 {
90  HANDLE AcceptThread;
91  HANDLE ReadyToConnectEvent;
92  DWORD Error;
93 
94  ReadyToConnectEvent = CreateEvent(NULL, TRUE, FALSE, NULL);
95  ok(ReadyToConnectEvent != NULL, "CreateEvent failed\n");
96 
97  AcceptThread = CreateThread(NULL, 0, AcceptProc, (PVOID)ReadyToConnectEvent, 0, NULL);
98  ok(AcceptThread != NULL, "CreateThread failed\n");
99 
100  WaitForSingleObject(ReadyToConnectEvent, INFINITE);
101 
103 
106 
107  WaitForSingleObject(AcceptThread, INFINITE);
108 
110 
111  WSACleanup();
112 }
#define CreateEvent
Definition: winbase.h:3588
#define ok_eq_ulong(value, expected)
#define ERROR_SUCCESS
Definition: deptool.c:10
#define TRUE
Definition: types.h:120
INT WSAAPI WSACleanup(VOID)
Definition: startup.c:60
DWORD WINAPI WaitForSingleObject(IN HANDLE hHandle, IN DWORD dwMilliseconds)
Definition: synch.c:82
#define FALSE
Definition: types.h:117
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:136
static DWORD WINAPI AcceptProc(_In_ LPVOID Parameter)
Definition: TcpIp_user.c:46
unsigned long DWORD
Definition: ntddk_ex.h:95
BOOL Error
Definition: chkdsk.c:66
static void UnloadTcpIpTestDriver(void)
Definition: TcpIp_user.c:24
DWORD KmtSendToDriver(IN DWORD ControlCode)
Definition: support.c:231
#define ok(value,...)
Definition: atltest.h:57
#define NULL
Definition: types.h:112
#define INFINITE
Definition: serial.h:102
#define IOCTL_TEST_CONNECT
Definition: tcpip.h:3
static void LoadTcpIpTestDriver(void)
Definition: TcpIp_user.c:15

◆ UnloadTcpIpTestDriver()

static void UnloadTcpIpTestDriver ( void  )
static

Definition at line 24 of file TcpIp_user.c.

25 {
26  /* Stop the driver. */
29 }
VOID KmtCloseDriver(VOID)
Definition: support.c:207
VOID KmtUnloadDriver(VOID)
Definition: support.c:156

Referenced by START_TEST().