64eed9be35872133a73d8212a875c28586c90d12
1 ///////////////////////////////////////////////////////////////////////////////
2 //Telnet Win32 : an ANSI telnet client.
3 //Copyright (C) 1998-2000 Paul Brannan
4 //Copyright (C) 1998 I.Ioannou
5 //Copyright (C) 1997 Brad Johnson
7 //This program is free software; you can redistribute it and/or
8 //modify it under the terms of the GNU General Public License
9 //as published by the Free Software Foundation; either version 2
10 //of the License, or (at your option) any later version.
12 //This program is distributed in the hope that it will be useful,
13 //but WITHOUT ANY WARRANTY; without even the implied warranty of
14 //MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 //GNU General Public License for more details.
17 //You should have received a copy of the GNU General Public License
18 //along with this program; if not, write to the Free Software
19 //Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
24 ///////////////////////////////////////////////////////////////////////////
26 ///////////////////////////////////////////////////////////////////////////////
28 // Module: tnetwork.cpp
30 // Contents: telnet network module
34 // Revisions: March 18, 1999 Paul Brannan (pbranna@clemson.edu)
36 ///////////////////////////////////////////////////////////////////////////////
40 void TNetwork::SetSocket(SOCKET s
) {
42 net_type
= TN_NETSOCKET
;
43 local_echo
= line_mode
= 1;
46 void TNetwork::SetPipe(HANDLE pIn
, HANDLE pOut
) {
49 net_type
= TN_NETPIPE
;
50 local_echo
= line_mode
= 0;
53 int TNetwork::WriteString(const char *str
, const int length
) {
56 return send(socket
, str
, length
, 0);
60 if(!WriteFile(pipeOut
, str
, length
, &dwWritten
, (LPOVERLAPPED
)NULL
)) return -1;
67 int TNetwork::ReadString (char *str
, const int length
) {
70 return recv(socket
, str
, length
, 0);
74 if(!ReadFile(pipeIn
, str
, length
, &dwRead
, (LPOVERLAPPED
)NULL
)) return -1;
81 void TNetwork::do_naws(int width
, int height
) {
82 if(!naws_func
) return;
84 int len
= (*naws_func
)(buf
, width
, height
);
85 WriteString(buf
, len
);
88 void TNetwork::SetLocalAddress(char *buf
) {
89 local_address
= new char[strlen(buf
) + 1];
90 strcpy(local_address
, buf
);