/*
- * ReactOS Services
- * Copyright (C) 2005 ReactOS Team
- *
- * LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
- * FILE: apps/utils/net/tcpsvcs/chargen.c
- * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
- * REVISIONS:
- * GM 04/10/05 Created
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: /base/services/tcpsvcs/chargen.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
LogEvent(_T("Chargen: Connection shutdown failed\n"), 0, FALSE);
RetVal = 1;
}
-
+
LogEvent(_T("Chargen: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
charIndex++;
}
- Line[LINESIZ - 2] = L'\r';
- Line[LINESIZ - 1] = L'\n';
+ Line[LINESIZ - 2] = '\r';
+ Line[LINESIZ - 1] = '\n';
if (! SendLine(Sock, Line))
break;
/* increment loop index to start printing from next char in ring */
loopIndex++;
}
-
+
if (bShutDown)
return FALSE;
else
return TRUE;
}
-BOOL SendLine(SOCKET Sock, TCHAR* Line)
+BOOL SendLine(SOCKET Sock, char* Line)
{
INT RetVal;
INT SentBytes;
/*
- * ReactOS Services
- * Copyright (C) 2005 ReactOS Team
- *
- * LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
- * FILE: apps/utils/net/tcpsvcs/daytime.c
- * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
- * REVISIONS:
- * GM 04/10/05 Created
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: /base/services/tcpsvcs/daytime.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
{
struct tm *newtime;
time_t aclock;
- TCHAR *pszTime;
+ CHAR *pszTime;
DWORD RetVal = 0;
SOCKET Sock = (SOCKET)Sock_;
-
+
time(&aclock);
newtime = localtime(&aclock);
- pszTime = _tasctime(newtime);
-
+ pszTime = asctime(newtime);
+
SendTime(Sock, pszTime);
LogEvent(_T("DayTime: Shutting connection down...\n"), 0, FALSE);
LogEvent(_T("DayTime: Connection shutdown failed\n"), 0, FALSE);
RetVal = 1;
}
-
+
LogEvent(_T("DayTime: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
}
-BOOL SendTime(SOCKET Sock, TCHAR *time)
+BOOL SendTime(SOCKET Sock, CHAR *time)
{
- INT StringSize = (INT)_tcsclen(time);
- INT RetVal = send(Sock, time, sizeof(TCHAR) * StringSize, 0);
-
+ INT StringSize = (INT)strlen(time);
+ INT RetVal = send(Sock, time, sizeof(CHAR) * StringSize, 0);
+
if (RetVal == SOCKET_ERROR)
return FALSE;
/*\r
- * ReactOS Services\r
- * Copyright (C) 2005 ReactOS Team\r
- *\r
- * LICENCE: GPL - See COPYING in the top level directory\r
* PROJECT: ReactOS simple TCP/IP services\r
- * FILE: apps/utils/net/tcpsvcs/discard.c\r
- * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services\r
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)\r
- * REVISIONS:\r
- * GM 04/10/05 Created\r
+ * LICENSE: GPL - See COPYING in the top level directory\r
+ * FILE: /base/services/tcpsvcs/discard.c\r
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services\r
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>\r
*\r
*/\r
\r
LogEvent(_T("Discard: Connection shutdown failed\n"), 0, FALSE);\r
RetVal = 1;\r
}\r
- \r
+\r
LogEvent(_T("Discard: Terminating thread\n"), 0, FALSE);\r
ExitThread(RetVal);\r
}\r
\r
BOOL RecieveIncomingPackets(SOCKET Sock)\r
{\r
- TCHAR ReadBuffer[BUF];\r
+ char ReadBuffer[BUF];\r
TCHAR buf[256];\r
INT ReadBytes;\r
\r
}\r
else if (ReadBytes == SOCKET_ERROR)\r
{\r
- _stprintf(buf, ("Socket Error: %d\n"), WSAGetLastError());\r
+ _stprintf(buf, _T("Socket Error: %d\n"), WSAGetLastError());\r
LogEvent(buf, 0, TRUE);\r
return FALSE;\r
}\r
/*
- * ReactOS Services
- * Copyright (C) 2005 ReactOS Team
- *
- * LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
- * FILE: apps/utils/net/tcpsvcs/echo.c
- * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
- * REVISIONS:
- * GM 04/10/05 Created
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: /base/services/tcpsvcs/echo.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
}
LogEvent(_T("Echo: Shutting connection down...\n"), 0, FALSE);
-
+
if (ShutdownConnection(Sock, TRUE))
LogEvent(_T("Echo: Connection is down\n"), 0, FALSE);
else
LogEvent(_T("Echo: Connection shutdown failed\n"), 0, FALSE);
RetVal = 1;
}
-
+
LogEvent(_T("Echo: Terminating thread\n"), 0, FALSE);
ExitThread(RetVal);
}
BOOL EchoIncomingPackets(SOCKET Sock)
{
- TCHAR ReadBuffer[BUF];
+ char ReadBuffer[BUF];
TCHAR buf[256]; // temp for holding LogEvent text
INT Temp;
INT ReadBytes;
/*
- * ReactOS Services
- * Copyright (C) 2005 ReactOS Team
- *
- * LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
- * FILE: apps/utils/net/tcpsvcs/qotd.c
- * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
- * REVISIONS:
- * GM 04/10/05 Created
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: /base/services/tcpsvcs/qotd.c
+ * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include "tcpsvcs.h"
-#define QBUFSIZ 160
+#define QBUFSIZ 60
-LPCTSTR FilePath = _T("\\drivers\\etc\\quotes");
+LPCTSTR FilePath = _T("\\drivers\\etc\\quotes"); /* 19 chars */
DWORD WINAPI QotdHandler(VOID* Sock_)
{
FILE *fp;
SOCKET Sock;
- TCHAR Sys[MAX_PATH];
- TCHAR Quote[60][BUFSIZ]; // need to set this dynamically
+ TCHAR Sys[MAX_PATH + 20];
+ char Quote[QBUFSIZ][BUFSIZ]; // need to set this dynamically
INT QuoteToPrint;
INT NumQuotes;
LogEvent(_T("QOTD: Getting system path failed.\n"), 0, TRUE);
ExitThread(1);
}
-
- _tcscat(Sys, FilePath);
+
+ _tcsncat(Sys, FilePath, _tcslen(FilePath));
LogEvent(_T("QOTD: Opening quotes file\n"), 0, FALSE);
- if ((fp = _tfopen(Sys, "r")) == NULL)
+ if ((fp = _tfopen(Sys, _T("r"))) == NULL)
{
- TCHAR buf[256];
+ TCHAR buf[320];
- _stprintf(buf, _T("QOTD: Error opening quote file : %s\n"), Sys);
+ _sntprintf(buf, 320, _T("QOTD: Error opening quote file : %s\n"), Sys);
LogEvent(buf, 0, TRUE);
LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE);
ExitThread(1);
/* read all quotes in the file into an array */
NumQuotes = 0;
- while (_fgetts(Quote[NumQuotes], QBUFSIZ, fp) != NULL)
+ while ((fgets(Quote[NumQuotes], QBUFSIZ, fp) != NULL) &&
+ (NumQuotes != QBUFSIZ))
NumQuotes++;
LogEvent(_T("QOTD: Closing quotes file\n"), 0, FALSE);
LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE);
ExitThread(1);
}
-
+
LogEvent(_T("QOTD: Terminating thread\n"), 0, FALSE);
ExitThread(0);
- //return Retval;
}
-BOOL SendQuote(SOCKET Sock, TCHAR* Quote)
+BOOL SendQuote(SOCKET Sock, char* Quote)
{
INT StringSize;
INT RetVal;
- StringSize = (INT)_tcsclen(Quote);
- RetVal = send(Sock, Quote, sizeof(TCHAR) * StringSize, 0);
+ StringSize = (INT)strlen(Quote);
+ RetVal = send(Sock, Quote, sizeof(char) * StringSize, 0);
if (RetVal == SOCKET_ERROR)
return FALSE;
/*
- * ReactOS Services
- * Copyright (C) 2005 ReactOS Team
- *
- * LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
- * FILE: apps/utils/net/tcpsvcs/skelserver.c
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: /base/services/tcpsvcs/skelserver.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
- * REVISIONS:
- * GM 04/10/05 Created
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
ListeningSocket = SetUpListener(htons(pServices->Port));
if (ListeningSocket == INVALID_SOCKET)
{
- LogEvent("Socket error when setting up listener\n", 0, TRUE);
+ LogEvent(_T("Socket error when setting up listener\n"), 0, TRUE);
return 3;
}
}
WaitForSingleObject(hThread, INFINITE);
-
+
CloseHandle(hThread);
}
else
/*
- * ReactOS Services
- * Copyright (C) 2005 ReactOS Team
- *
- * LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
- * FILE: apps/utils/net/tcpsvcs/tcpsvcs.c
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: /base/services/tcpsvcs/tcpsvcs.c
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
- * REVISIONS:
- * GM 04/10/05 Created
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
/*
BOOL bShutDown = FALSE;
BOOL bPause = FALSE;
-LPCTSTR LogFileName = "\\tcpsvcs_log.log";
+LPCTSTR LogFileName = _T("\\tcpsvcs_log.log");
LPTSTR ServiceName = _T("Simp Tcp");
//LPTSTR DisplayName = _T("Simple TCP/IP Services");
VOID WINAPI
ServiceMain(DWORD argc, LPTSTR argv[])
{
- TCHAR LogFilePath[MAX_PATH];
+ TCHAR LogFilePath[MAX_PATH + 17];
if(! GetSystemDirectory(LogFilePath, MAX_PATH))
return;
- _tcscat(LogFilePath, LogFileName);
+ _tcsncat(LogFilePath, LogFileName, 17);
- hLogFile = fopen(LogFilePath, _T("a+"));
+ hLogFile = _tfopen(LogFilePath, _T("a+"));
if (hLogFile == NULL)
{
- TCHAR buf[50];
+ TCHAR buf[300];
- _stprintf(buf, _T("Could not open log file: %s\n"), LogFilePath);
+ _sntprintf(buf, 300, _T("Could not open log file: %s\n"), LogFilePath);
MessageBox(NULL, buf, NULL, MB_OK);
return;
}
UpdateStatus (SERVICE_STOPPED, 0);
LogEvent(_T("Service status set to SERVICE_STOPPED\n"), 0, FALSE);
LogEvent(_T("Leaving ServiceMain\n"), 0, FALSE);
-
+
fclose(hLogFile);
return;
{
CloseHandle(hThread[i]);
}
-
+
LogEvent(_T("Detaching Winsock2...\n"), 0, FALSE);
WSACleanup();
-
+
return 0;
}
{
DWORD eMsgLen, ErrNum = GetLastError ();
LPTSTR lpvSysMsg;
- TCHAR MessageBuffer[512];
+ TCHAR MessageBuffer[1024];
ErrNum, MAKELANGID (LANG_NEUTRAL, SUBLANG_DEFAULT),
(LPTSTR)&lpvSysMsg, 0, NULL);
- _stprintf(MessageBuffer, _T("%s %s ErrNum = %lu. ExitCode = %d."),
+ _sntprintf(MessageBuffer, 1024, _T("%s %s ErrNum = %lu. ExitCode = %d."),
UserMessage, lpvSysMsg, ErrNum, ExitCode);
HeapFree(GetProcessHeap (), 0, lpvSysMsg);
}
else
{
- _stprintf(MessageBuffer, _T("%s"), UserMessage);
+ _sntprintf(MessageBuffer, 1024, _T("%s"), UserMessage);
}
- fputs (MessageBuffer, hLogFile);
+ _fputts(MessageBuffer, hLogFile);
if (ExitCode != 0)
ExitProcess(ExitCode);
/*
- * ReactOS Services
- * Copyright (C) 2005 ReactOS Team
- *
- * LICENCE: GPL - See COPYING in the top level directory
* PROJECT: ReactOS simple TCP/IP services
- * FILE: apps/utils/net/tcpsvcs/tcpsvcs.h
+ * LICENSE: GPL - See COPYING in the top level directory
+ * FILE: /base/services/tcpsvcs/tcpsvcs.h
* PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
- * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
- * REVISIONS:
- * GM 04/10/05 Created
+ * COPYRIGHT: Copyright 2005 - 2006 Ged Murphy <gedmurphy@gmail.com>
*
*/
#include <tchar.h>
#include <time.h>
-#define UNICODE
-#define _UNICODE
-
/* default port numbers */
#define ECHO_PORT 7
#define DISCARD_PORT 9
/* chargen functions */
DWORD WINAPI ChargenHandler(VOID* Sock_);
BOOL GenerateChars(SOCKET Sock);
-BOOL SendLine(SOCKET Sock, TCHAR* Line);
+BOOL SendLine(SOCKET Sock, char* Line);
/* daytime functions */
DWORD WINAPI DaytimeHandler(VOID* Sock_);
-BOOL SendTime(SOCKET Sock, TCHAR *time);
+BOOL SendTime(SOCKET Sock, char *time);
/* echo functions */
DWORD WINAPI EchoHandler(VOID* Sock_);
/* qotd functions */
DWORD WINAPI QotdHandler(VOID* Sock_);
-BOOL SendQuote(SOCKET Sock, TCHAR* Quote);
+BOOL SendQuote(SOCKET Sock, char* Quote);
-<module name="tcpsvcs" type="win32cui" installbase="system32" installname="tcpsvcs.exe">
+<?xml version="1.0"?>
+<rbuild xmlns:xi="http://www.w3.org/2001/XInclude">
+ <module name="tcpsvcs" type="win32cui" installbase="system32" installname="tcpsvcs.exe">
<include base="arp">.</include>
<define name="__USE_W32API" />
<library>kernel32</library>
<file>chargen.c</file>
<file>tcpsvcs.rc</file>
<pch>tcpsvcs.h</pch>
-</module>
+ </module>
+</rbuild>