3 * Copyright (C) 2005 ReactOS Team
5 * LICENCE: GPL - See COPYING in the top level directory
6 * PROJECT: ReactOS simple TCP/IP services
7 * FILE: apps/utils/net/tcpsvcs/qotd.c
8 * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
9 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
24 LPCTSTR FilePath
= "C:\\ReactOS\\system32\\drivers\\etc\\quotes";
26 DWORD WINAPI
QotdHandler(VOID
* Sock_
)
31 TCHAR Quote
[NUMQUOTES
][BUFSIZ
]; // need to set this dynamically
36 _tprintf(_T("Opening quotes file\n"));
37 if ((fp
= _tfopen(FilePath
, "r")) == NULL
)
39 _tprintf(_T("Error opening file: %lu\n"), GetLastError());
40 _tprintf(_T("Terminating qotd thread\n"));
44 while (_fgetts(Quote
[i
], QBUFSIZ
, fp
) != NULL
)
47 _tprintf(_T("Closing quotes file\n"));
50 /* randomise the quote */
51 srand((unsigned int) time(0));
52 QuoteToPrint
= rand() % NUMQUOTES
;
54 if (!SendQuote(Sock
, Quote
[QuoteToPrint
]))
56 _tprintf(_T("Error sending data. Error: %x\n"), WSAGetLastError());
59 _tprintf(_T("Shutting connection down...\n"));
60 if (ShutdownConnection(Sock
, FALSE
))
61 _tprintf(_T("Connection is down.\n"));
64 _tprintf(_T("Connection shutdown failed\n"));
65 _tprintf(_T("Terminating qotd thread\n"));
69 _tprintf(_T("Terminating qotd thread\n"));
76 BOOL
SendQuote(SOCKET Sock
, TCHAR
* Quote
)
81 StringSize
= strlen(Quote
);
82 RetVal
= send(Sock
, Quote
, sizeof(TCHAR
) * StringSize
, 0);
84 if (RetVal
== SOCKET_ERROR
)
87 _tprintf(("Connection closed by peer.\n"));