2006-02-16 23:23:37 +00:00
|
|
|
/*
|
|
|
|
* PROJECT: ReactOS simple TCP/IP services
|
2006-02-19 16:33:14 +00:00
|
|
|
* LICENSE: GPL - See COPYING in the top level directory
|
|
|
|
* FILE: /base/services/tcpsvcs/daytime.c
|
2008-04-02 16:54:55 +00:00
|
|
|
* PURPOSE: Sends the current date and time to the client
|
|
|
|
* COPYRIGHT: Copyright 2005 - 2008 Ged Murphy <gedmurphy@reactos.org>
|
2006-02-16 23:23:37 +00:00
|
|
|
*
|
|
|
|
*/
|
|
|
|
|
|
|
|
#include "tcpsvcs.h"
|
|
|
|
|
2008-04-02 16:54:55 +00:00
|
|
|
static BOOL
|
|
|
|
SendTime(SOCKET sock, CHAR *time)
|
2007-07-09 23:13:09 +00:00
|
|
|
{
|
2008-04-02 16:54:55 +00:00
|
|
|
DWORD stringSize = strlen(time) + 1;
|
|
|
|
if (send(sock, time, stringSize, 0) == SOCKET_ERROR)
|
|
|
|
{
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"DayTime: Error sending data", WSAGetLastError(), 0, LOG_ERROR);
|
2007-07-09 23:13:09 +00:00
|
|
|
return FALSE;
|
2008-04-02 16:54:55 +00:00
|
|
|
}
|
2007-07-09 23:13:09 +00:00
|
|
|
|
|
|
|
return TRUE;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2008-04-02 16:54:55 +00:00
|
|
|
DWORD WINAPI
|
|
|
|
DaytimeHandler(VOID* Sock_)
|
2006-02-16 23:23:37 +00:00
|
|
|
{
|
2008-04-02 16:54:55 +00:00
|
|
|
struct tm *localTime;
|
2006-02-16 23:23:37 +00:00
|
|
|
time_t aclock;
|
2006-02-19 16:33:14 +00:00
|
|
|
CHAR *pszTime;
|
2008-04-02 16:54:55 +00:00
|
|
|
DWORD retVal = 0;
|
2006-02-16 23:23:37 +00:00
|
|
|
SOCKET Sock = (SOCKET)Sock_;
|
2006-02-19 16:33:14 +00:00
|
|
|
|
2006-02-16 23:23:37 +00:00
|
|
|
time(&aclock);
|
2008-04-02 16:54:55 +00:00
|
|
|
localTime = localtime(&aclock);
|
|
|
|
if (localTime)
|
|
|
|
{
|
|
|
|
pszTime = asctime(localTime);
|
|
|
|
if (!SendTime(Sock, pszTime))
|
|
|
|
retVal = 1;
|
|
|
|
}
|
2006-02-16 23:23:37 +00:00
|
|
|
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"DayTime: Shutting connection down", 0, 0, LOG_FILE);
|
2006-02-16 23:23:37 +00:00
|
|
|
if (ShutdownConnection(Sock, FALSE))
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"DayTime: Connection is down", 0, 0, LOG_FILE);
|
2006-02-16 23:23:37 +00:00
|
|
|
else
|
|
|
|
{
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"DayTime: Connection shutdown failed", 0, 0, LOG_FILE);
|
2008-04-02 16:54:55 +00:00
|
|
|
retVal = 1;
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|
2006-02-19 16:33:14 +00:00
|
|
|
|
2008-09-01 12:51:49 +00:00
|
|
|
LogEvent(L"DayTime: Terminating thread", 0, 0, LOG_FILE);
|
2008-04-02 16:54:55 +00:00
|
|
|
ExitThread(retVal);
|
2006-02-16 23:23:37 +00:00
|
|
|
}
|