move network tools
[reactos.git] / reactos / services / tcpsvcs / daytime.c
1 /*
2 * ReactOS Services
3 * Copyright (C) 2005 ReactOS Team
4 *
5 * LICENCE: GPL - See COPYING in the top level directory
6 * PROJECT: ReactOS simple TCP/IP services
7 * FILE: apps/utils/net/tcpsvcs/daytime.c
8 * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
9 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
10 * REVISIONS:
11 * GM 04/10/05 Created
12 *
13 */
14
15 #include "tcpsvcs.h"
16
17 DWORD WINAPI DaytimeHandler(VOID* Sock_)
18 {
19 struct tm *newtime;
20 time_t aclock;
21 TCHAR *pszTime;
22 DWORD RetVal = 0;
23 SOCKET Sock = (SOCKET)Sock_;
24
25 time(&aclock);
26 newtime = localtime(&aclock);
27 pszTime = _tasctime(newtime);
28
29 SendTime(Sock, pszTime);
30
31 LogEvent(_T("DayTime: Shutting connection down...\n"), 0, FALSE);
32 if (ShutdownConnection(Sock, FALSE))
33 LogEvent(_T("DayTime: Connection is down.\n"), 0, FALSE);
34 else
35 {
36 LogEvent(_T("DayTime: Connection shutdown failed\n"), 0, FALSE);
37 RetVal = 1;
38 }
39
40 LogEvent(_T("DayTime: Terminating thread\n"), 0, FALSE);
41 ExitThread(RetVal);
42 }
43
44
45 BOOL SendTime(SOCKET Sock, TCHAR *time)
46 {
47 INT StringSize = (INT)_tcsclen(time);
48 INT RetVal = send(Sock, time, sizeof(TCHAR) * StringSize, 0);
49
50 if (RetVal == SOCKET_ERROR)
51 return FALSE;
52
53 LogEvent(_T("DayTime: Connection closed by peer.\n"), 0, FALSE);
54 return TRUE;
55 }