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/discard.c
8 * PURPOSE: Provide CharGen, Daytime, Discard, Echo, and Qotd services
9 * PROGRAMMERS: Ged Murphy (gedmurphy@gmail.com)
17 DWORD WINAPI
DiscardHandler(VOID
* Sock_
)
20 SOCKET Sock
= (SOCKET
)Sock_
;
22 if (!RecieveIncomingPackets(Sock
))
24 LogEvent(_T("Discard: RecieveIncomingPackets failed\n"), 0, FALSE
);
28 LogEvent(_T("Discard: Shutting connection down...\n"), 0, FALSE
);
29 if (ShutdownConnection(Sock
, TRUE
))
30 LogEvent(_T("Discard: Connection is down.\n"), 0, FALSE
);
33 LogEvent(_T("Discard: Connection shutdown failed\n"), 0, FALSE
);
37 LogEvent(_T("Discard: Terminating thread\n"), 0, FALSE
);
43 BOOL
RecieveIncomingPackets(SOCKET Sock
)
45 TCHAR ReadBuffer
[BUF
];
46 TCHAR temp
[512]; // temp for holding LogEvent text
51 ReadBytes
= recv(Sock
, ReadBuffer
, BUF
, 0);
54 _stprintf(temp
, _T("Received %d bytes from client\n"), ReadBytes
);
55 LogEvent(temp
, 0, FALSE
);
57 else if (ReadBytes
== SOCKET_ERROR
)
59 _stprintf(temp
, ("Socket Error: %d\n"), WSAGetLastError());
60 LogEvent(temp
, 0, TRUE
);
63 } while (ReadBytes
> 0);
65 LogEvent(_T("Discard: Connection closed by peer.\n"), 0, FALSE
);