ReactOS  0.4.13-dev-257-gfabbd7c
chargen.c File Reference
#include "tcpsvcs.h"
Include dependency graph for chargen.c:

Go to the source code of this file.

Macros

#define ASCII_START   32
 
#define ASCII_END   126
 
#define NUM_CHARS   ASCII_END - ASCII_START + 1
 
#define LINESIZE   74
 

Functions

static BOOL SendLine (SOCKET sock, LPSTR lpLine)
 
static BOOL GenerateChars (SOCKET sock)
 
DWORD WINAPI ChargenHandler (VOID *sock_)
 

Macro Definition Documentation

◆ ASCII_END

#define ASCII_END   126

Definition at line 14 of file chargen.c.

◆ ASCII_START

#define ASCII_START   32

Definition at line 13 of file chargen.c.

◆ LINESIZE

#define LINESIZE   74

Definition at line 18 of file chargen.c.

◆ NUM_CHARS

#define NUM_CHARS   ASCII_END - ASCII_START + 1

Definition at line 15 of file chargen.c.

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 }
int32_t INT
Definition: typedefs.h:56
VOID WINAPI ExitThread(IN DWORD uExitCode)
Definition: thread.c:326
BOOL ShutdownConnection(SOCKET sock, BOOL bRec)
Definition: skelserver.c:126
static BOOL GenerateChars(SOCKET sock)
Definition: chargen.c:51
static const WCHAR L[]
Definition: oid.c:1250
VOID LogEvent(LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
Definition: log.c:196
Definition: tcpcore.h:1455
UINT_PTR SOCKET
Definition: winsock.h:47

◆ GenerateChars()

static BOOL GenerateChars ( SOCKET  sock)
static

Definition at line 51 of file chargen.c.

52 {
53  CHAR chars[NUM_CHARS];
55  INT charIndex;
56  INT loopIndex;
57  INT i;
58 
59  /* fill the array with printable characters */
60  for (charIndex = 0, i = ASCII_START; i <= ASCII_END; charIndex++, i++)
61  chars[charIndex] = (CHAR)i;
62 
63  loopIndex = 0;
64  while (!bShutdown)
65  {
66  /* reset the loop when we hit the last char */
67  if (loopIndex == NUM_CHARS)
68  loopIndex = 0;
69 
70  /* fill a line array to send */
71  charIndex = loopIndex;
72  for (i=0; i < LINESIZE - 2; i++)
73  {
74  line[i] = chars[charIndex];
75 
76  /* if we hit the end char, reset it */
77  if (chars[charIndex] == chars[NUM_CHARS - 1])
78  charIndex = 0;
79  else
80  charIndex++;
81  }
82  line[LINESIZE - 2] = '\r';
83  line[LINESIZE - 1] = '\n';
84 
85  if (!SendLine(sock, line))
86  break;
87 
88  /* start printing from next char in the array */
89  loopIndex++;
90  }
91 
92  return TRUE;
93 }
volatile BOOL bShutdown
Definition: tcpsvcs.c:16
#define TRUE
Definition: types.h:120
#define ASCII_START
Definition: chargen.c:13
char CHAR
Definition: xmlstorage.h:175
#define NUM_CHARS
Definition: chargen.c:15
int32_t INT
Definition: typedefs.h:56
#define ASCII_END
Definition: chargen.c:14
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
static BOOL SendLine(SOCKET sock, LPSTR lpLine)
Definition: chargen.c:21
Definition: parser.c:48
#define LINESIZE
Definition: chargen.c:18
Definition: tcpcore.h:1455

Referenced by ChargenHandler().

◆ SendLine()

static BOOL SendLine ( SOCKET  sock,
LPSTR  lpLine 
)
static

Definition at line 21 of file chargen.c.

22 {
23  BOOL bRet = FALSE;
24 
25  /*FIXME: need to establish if peer closes connection, not just report a socket error */
26  INT retVal = send(sock, lpLine, LINESIZE, 0);
27  if (retVal > 0)
28  {
29  if (retVal == LINESIZE)
30  {
31  bRet = TRUE;
32  }
33  else
34  {
35  LogEvent(L"Chargen: Not sent enough bytes", 0, 0, LOG_FILE);
36  }
37  }
38  else if (retVal == SOCKET_ERROR)
39  {
40  LogEvent(L"Chargen: Socket error\n", WSAGetLastError(), 0, LOG_ERROR);
41  }
42  else
43  {
44  LogEvent(L"Chargen: unknown error\n", WSAGetLastError(), 0, LOG_ERROR);
45  }
46 
47  return bRet;
48 }
#define SOCKET_ERROR
Definition: winsock.h:333
#define TRUE
Definition: types.h:120
int32_t INT
Definition: typedefs.h:56
unsigned int BOOL
Definition: ntddk_ex.h:94
#define LOG_ERROR
Definition: tcpsvcs.h:16
INT WSAAPI WSAGetLastError(VOID)
Definition: dllmain.c:112
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
static const WCHAR L[]
Definition: oid.c:1250
VOID LogEvent(LPCWSTR lpMsg, DWORD errNum, DWORD exitCode, UINT flags)
Definition: log.c:196
#define LINESIZE
Definition: chargen.c:18
Definition: tcpcore.h:1455

Referenced by GenerateChars().