ReactOS 0.4.15-dev-5667-ged97270
tcpsvcs.h File Reference
#include <stdarg.h>
#include <windef.h>
#include <winbase.h>
#include <winsock2.h>
#include <tchar.h>
#include <strsafe.h>
Include dependency graph for tcpsvcs.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  _Services
 

Macros

#define WIN32_NO_STATUS
 
#define _INC_WINDOWS
 
#define LOG_FILE   1
 
#define LOG_EVENTLOG   2
 
#define LOG_ERROR   4
 
#define LOG_ALL   (LOG_FILE | LOG_EVENTLOG | LOG_ERROR)
 
#define ECHO_PORT   7
 
#define DISCARD_PORT   9
 
#define DAYTIME_PORT   13
 
#define QOTD_PORT   17
 
#define CHARGEN_PORT   19
 
#define NUM_SERVICES   5
 
#define CS_TIMEOUT   1000
 

Typedefs

typedef struct _Services SERVICES
 
typedef struct _ServicesPSERVICES
 

Functions

BOOL InitLogging (VOID)
 
VOID UninitLogging (VOID)
 
VOID LogEvent (LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
 
DWORD WINAPI StartServer (LPVOID lpParam)
 
BOOL ShutdownConnection (SOCKET Sock, BOOL bRec)
 
DWORD WINAPI ChargenHandler (VOID *sock_)
 
DWORD WINAPI DaytimeHandler (VOID *sock_)
 
DWORD WINAPI EchoHandler (VOID *sock_)
 
DWORD WINAPI DiscardHandler (VOID *sock_)
 
DWORD WINAPI QotdHandler (VOID *sock_)
 

Variables

volatile BOOL bShutdown
 
volatile BOOL bPause
 

Macro Definition Documentation

◆ _INC_WINDOWS

#define _INC_WINDOWS

Definition at line 9 of file tcpsvcs.h.

◆ CHARGEN_PORT

#define CHARGEN_PORT   19

Definition at line 24 of file tcpsvcs.h.

◆ CS_TIMEOUT

#define CS_TIMEOUT   1000

Definition at line 27 of file tcpsvcs.h.

◆ DAYTIME_PORT

#define DAYTIME_PORT   13

Definition at line 22 of file tcpsvcs.h.

◆ DISCARD_PORT

#define DISCARD_PORT   9

Definition at line 21 of file tcpsvcs.h.

◆ ECHO_PORT

#define ECHO_PORT   7

Definition at line 20 of file tcpsvcs.h.

◆ LOG_ALL

#define LOG_ALL   (LOG_FILE | LOG_EVENTLOG | LOG_ERROR)

Definition at line 17 of file tcpsvcs.h.

◆ LOG_ERROR

#define LOG_ERROR   4

Definition at line 16 of file tcpsvcs.h.

◆ LOG_EVENTLOG

#define LOG_EVENTLOG   2

Definition at line 15 of file tcpsvcs.h.

◆ LOG_FILE

#define LOG_FILE   1

Definition at line 14 of file tcpsvcs.h.

◆ NUM_SERVICES

#define NUM_SERVICES   5

Definition at line 26 of file tcpsvcs.h.

◆ QOTD_PORT

#define QOTD_PORT   17

Definition at line 23 of file tcpsvcs.h.

◆ WIN32_NO_STATUS

#define WIN32_NO_STATUS

Definition at line 6 of file tcpsvcs.h.

Typedef Documentation

◆ PSERVICES

◆ SERVICES

Function Documentation

◆ ChargenHandler()

DWORD WINAPI ChargenHandler ( VOID sock_)

Definition at line 96 of file chargen.c.

97{
98 INT retVal = 0;
99 SOCKET sock = (SOCKET)sock_;
100
101 if (!GenerateChars(sock))
102 {
103 LogEvent(L"Chargen: Char generation failed", 0, 0, LOG_FILE);
104 retVal = 1;
105 }
106
107 LogEvent(L"Chargen: Shutting connection down...", 0, 0, LOG_FILE);
109 {
110 LogEvent(L"Chargen: Connection is down", 0, 0, LOG_FILE);
111 }
112 else
113 {
114 LogEvent(L"Chargen: Connection shutdown failed", 0, 0, LOG_FILE);
115 retVal = 1;
116 }
117
118 LogEvent(L"Chargen: Terminating thread", 0, 0, LOG_FILE);
119 ExitThread(retVal);
120}
VOID LogEvent(LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
Definition: log.c:196
static BOOL GenerateChars(SOCKET sock)
Definition: chargen.c:51
#define FALSE
Definition: types.h:117
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:365
#define L(x)
Definition: ntvdm.h:50
BOOL ShutdownConnection(SOCKET sock, BOOL bRec)
Definition: skelserver.c:126
Definition: tcpcore.h:1455
int32_t INT
Definition: typedefs.h:58
UINT_PTR SOCKET
Definition: winsock.h:47

◆ DaytimeHandler()

DWORD WINAPI DaytimeHandler ( VOID sock_)

Definition at line 29 of file daytime.c.

30{
31 struct tm *localTime;
32 time_t aclock;
33 CHAR *pszTime;
34 DWORD retVal = 0;
35 SOCKET Sock = (SOCKET)Sock_;
36
37 time(&aclock);
38 localTime = localtime(&aclock);
39 if (localTime)
40 {
41 pszTime = asctime(localTime);
42 if (!SendTime(Sock, pszTime))
43 retVal = 1;
44 }
45
46 LogEvent(L"DayTime: Shutting connection down", 0, 0, LOG_FILE);
47 if (ShutdownConnection(Sock, FALSE))
48 LogEvent(L"DayTime: Connection is down", 0, 0, LOG_FILE);
49 else
50 {
51 LogEvent(L"DayTime: Connection shutdown failed", 0, 0, LOG_FILE);
52 retVal = 1;
53 }
54
55 LogEvent(L"DayTime: Terminating thread", 0, 0, LOG_FILE);
56 ExitThread(retVal);
57}
static BOOL SendTime(SOCKET sock, CHAR *time)
Definition: daytime.c:15
__kernel_time_t time_t
Definition: linux.h:252
unsigned long DWORD
Definition: ntddk_ex.h:95
__u16 time
Definition: mkdosfs.c:8
_Check_return_ _CRTIMP char *__cdecl asctime(_In_ const struct tm *_Tm)
_CRTIMP struct tm *__cdecl localtime(const time_t *_Time)
Definition: time.h:416
Definition: time.h:68
char CHAR
Definition: xmlstorage.h:175

◆ DiscardHandler()

DWORD WINAPI DiscardHandler ( VOID sock_)

Definition at line 44 of file discard.c.

45{
46 DWORD retVal = 0;
47 SOCKET sock = (SOCKET)sock_;
48
50 {
51 LogEvent(L"Discard: ReceiveIncomingPackets failed", 0, 0, LOG_FILE);
52 retVal = 1;
53 }
54
55 LogEvent(L"Discard: Shutting connection down", 0, 0, LOG_FILE);
57 {
58 LogEvent(L"Discard: Connection is down.", 0, 0, LOG_FILE);
59 }
60 else
61 {
62 LogEvent(L"Discard: Connection shutdown failed", 0, 0, LOG_FILE);
63 retVal = 1;
64 }
65
66 LogEvent(L"Discard: Terminating thread", 0, 0, LOG_FILE);
67 ExitThread(retVal);
68}
static BOOL ReceiveIncomingPackets(SOCKET sock)
Definition: discard.c:15
#define TRUE
Definition: types.h:120

◆ EchoHandler()

DWORD WINAPI EchoHandler ( VOID sock_)

Definition at line 69 of file echo.c.

70{
71 DWORD retVal = 0;
72 SOCKET sock = (SOCKET)sock_;
73
75 {
76 LogEvent(L"Echo: EchoIncomingPackets failed", 0, 0, LOG_FILE);
77 retVal = 1;
78 }
79
80 LogEvent(L"Echo: Shutting connection down", 0, 0, LOG_FILE);
81
83 {
84 LogEvent(L"Echo: Connection is down", 0, 0, LOG_FILE);
85 }
86 else
87 {
88 LogEvent(L"Echo: Connection shutdown failed", 0, 0, LOG_FILE);
89 retVal = 1;
90 }
91
92 LogEvent(L"Echo: Terminating thread", 0, 0, LOG_FILE);
93 ExitThread(retVal);
94}
static BOOL EchoIncomingPackets(SOCKET sock)
Definition: echo.c:15

◆ InitLogging()

BOOL InitLogging ( VOID  )

◆ LogEvent()

VOID LogEvent ( LPCWSTR  lpMsg,
DWORD  errNum,
DWORD  exitCode,
UINT  flags 
)

Definition at line 196 of file log.c.

200{
201#ifdef DEBUG
202 if (flags & LOG_FILE || flags & LOG_ERROR)
203 LogToFile(lpMsg, errNum, exitCode, flags);
204#endif
205 if (flags & LOG_EVENTLOG)
206 LogToEventLog(lpMsg, errNum, exitCode, flags);
207}
static VOID LogToFile(LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
Definition: log.c:67
static VOID LogToEventLog(LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
Definition: log.c:23
GLbitfield flags
Definition: glext.h:7161
#define LOG_EVENTLOG
Definition: tcpsvcs.h:15
#define LOG_ERROR
Definition: tcpsvcs.h:16

Referenced by _tmain(), AcceptConnections(), ChargenHandler(), CreateServers(), CreateServiceThread(), DaytimeHandler(), DiscardHandler(), EchoHandler(), EchoIncomingPackets(), QotdHandler(), ReceiveIncomingPackets(), RetrieveQuote(), SendLine(), SendTime(), ServerCtrlHandler(), ServiceMain(), SetUpListener(), ShutdownConnection(), StartServer(), and UpdateStatus().

◆ QotdHandler()

DWORD WINAPI QotdHandler ( VOID sock_)

Definition at line 135 of file qotd.c.

136{
137 SOCKET sock = (SOCKET)sock_;
138 DWORD retVal = 0;
139
140 if (!RetrieveQuote(sock))
141 {
142 LogEvent(L"QOTD: Error retrieving quote", 0, 0, LOG_FILE);
143 retVal = 1;
144 }
145
146 LogEvent(L"QOTD: Shutting connection down", 0, 0, LOG_FILE);
148 {
149 LogEvent(L"QOTD: Connection is down", 0, 0, LOG_FILE);
150 }
151 else
152 {
153 LogEvent(L"QOTD: Connection shutdown failed", 0, 0, LOG_FILE);
154 LogEvent(L"QOTD: Terminating thread", 0, 0, LOG_FILE);
155 retVal = 1;
156 }
157
158 LogEvent(L"QOTD: Terminating thread", 0, 0, LOG_FILE);
159 ExitThread(retVal);
160}
static BOOL RetrieveQuote(SOCKET sock)
Definition: qotd.c:27

◆ ShutdownConnection()

BOOL ShutdownConnection ( SOCKET  Sock,
BOOL  bRec 
)

Definition at line 126 of file skelserver.c.

128{
129 WCHAR logBuf[256];
130
131 /* Disallow any further data sends. This will tell the other side
132 that we want to go away now. If we skip this step, we don't
133 shut the connection down nicely. */
135 {
136 LogEvent(L"Error in shutdown()", WSAGetLastError(), 0, LOG_ERROR);
137 return FALSE;
138 }
139
140 /* Receive any extra data still sitting on the socket
141 before we close it */
142 if (bRec)
143 {
144 CHAR readBuffer[BUF];
145 INT ret;
146
147 do
148 {
149 ret = recv(sock, readBuffer, BUF, 0);
150 if (ret >= 0)
151 {
152 swprintf(logBuf, L"FYI, received %d unexpected bytes during shutdown", ret);
153 LogEvent(logBuf, 0, 0, LOG_FILE);
154 }
155 } while (ret > 0);
156 }
157
159
160 return TRUE;
161}
#define swprintf
Definition: precomp.h:40
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23
#define closesocket
Definition: ncftp.h:477
#define BUF
Definition: skelserver.c:12
INT WSAAPI shutdown(IN SOCKET s, IN INT how)
Definition: sockctrl.c:506
Definition: jssnprintf.c:29
int ret
int PASCAL FAR WSAGetLastError(void)
Definition: dllmain.c:112
#define SOCKET_ERROR
Definition: winsock.h:333
#define SD_SEND
Definition: winsock.h:55
__wchar_t WCHAR
Definition: xmlstorage.h:180

Referenced by ChargenHandler(), DaytimeHandler(), DiscardHandler(), EchoHandler(), and QotdHandler().

◆ StartServer()

DWORD WINAPI StartServer ( LPVOID  lpParam)

Definition at line 165 of file skelserver.c.

166{
167 SOCKET listeningSocket;
168 PSERVICES pServices;
169 TCHAR logBuf[256];
170
171 pServices = (PSERVICES)lpParam;
172
173 swprintf(logBuf, L"Starting %s server", pServices->lpName);
174 LogEvent(logBuf, 0, 0, LOG_FILE);
175
176 if (!bShutdown)
177 {
178 listeningSocket = SetUpListener(htons(pServices->Port));
179 if (!bShutdown && listeningSocket != INVALID_SOCKET)
180 {
181 swprintf(logBuf,
182 L"%s is waiting for connections on port %d",
183 pServices->lpName,
184 pServices->Port);
185 LogEvent(logBuf, 0, 0, LOG_FILE);
186
187 AcceptConnections(listeningSocket, pServices->lpService, pServices->lpName);
188 }
189 else
190 {
191 LogEvent(L"Socket error when setting up listener", 0, 0, LOG_FILE);
192 }
193 }
194
195 swprintf(logBuf, L"Exiting %s thread", pServices->lpName);
196 LogEvent(logBuf, 0, 0, LOG_FILE);
197 ExitThread(0);
198}
#define htons(x)
Definition: module.h:213
static SOCKET SetUpListener(USHORT Port)
Definition: skelserver.c:15
static VOID AcceptConnections(SOCKET listeningSocket, LPTHREAD_START_ROUTINE lpService, LPWSTR lpName)
Definition: skelserver.c:55
USHORT Port
Definition: tcpsvcs.h:33
LPWSTR lpName
Definition: tcpsvcs.h:34
LPTHREAD_START_ROUTINE lpService
Definition: tcpsvcs.h:35
volatile BOOL bShutdown
Definition: tcpsvcs.c:16
struct _Services * PSERVICES
#define INVALID_SOCKET
Definition: winsock.h:332
char TCHAR
Definition: xmlstorage.h:189

Referenced by CreateServers(), and DECLARE_INTERFACE_().

◆ UninitLogging()

VOID UninitLogging ( VOID  )

Variable Documentation

◆ bPause

volatile BOOL bPause
extern

Definition at line 17 of file tcpsvcs.c.

◆ bShutdown