ReactOS  0.4.12-dev-43-g63b00d8
tnetwork.cpp
Go to the documentation of this file.
1 //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
6 //
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.
11 //
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.
16 //
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.
20 //
21 //I.Ioannou
22 //roryt@hol.gr
23 //
25 
27 //
28 // Module: tnetwork.cpp
29 //
30 // Contents: telnet network module
31 //
32 // Product: telnet
33 //
34 // Revisions: March 18, 1999 Paul Brannan (pbranna@clemson.edu)
35 //
37 
38 #include "precomp.h"
39 
41  socket = s;
43  local_echo = line_mode = 1;
44 }
45 
46 void TNetwork::SetPipe(HANDLE pIn, HANDLE pOut) {
47  pipeIn = pIn;
48  pipeOut = pOut;
50  local_echo = line_mode = 0;
51 }
52 
53 int TNetwork::WriteString(const char *str, const int length) {
54  switch(net_type) {
55  case TN_NETSOCKET:
56  return send(socket, str, length, 0);
57  case TN_NETPIPE:
58  {
59  DWORD dwWritten;
60  if(!WriteFile(pipeOut, str, length, &dwWritten, (LPOVERLAPPED)NULL)) return -1;
61  return dwWritten;
62  }
63  }
64  return 0;
65 }
66 
67 int TNetwork::ReadString (char *str, const int length) {
68  switch(net_type) {
69  case TN_NETSOCKET:
70  return recv(socket, str, length, 0);
71  case TN_NETPIPE:
72  {
73  DWORD dwRead;
74  if(!ReadFile(pipeIn, str, length, &dwRead, (LPOVERLAPPED)NULL)) return -1;
75  return dwRead;
76  }
77  }
78  return 0;
79 }
80 
81 void TNetwork::do_naws(int width, int height) {
82  if(!naws_func) return;
83  char buf[100];
84  int len = (*naws_func)(buf, width, height);
85  WriteString(buf, len);
86 }
87 
89  local_address = new char[strlen(buf) + 1];
90  strcpy(local_address, buf);
91 }
92 
GLint GLint GLsizei width
Definition: gl.h:1546
HANDLE pipeIn
Definition: tnetwork.h:18
NetworkType net_type
Definition: tnetwork.h:17
void SetPipe(HANDLE pIn, HANDLE pOut)
Definition: tnetwork.cpp:46
ACPI_SIZE strlen(const char *String)
Definition: utclib.c:269
GLenum GLuint GLenum GLsizei const GLchar * buf
Definition: glext.h:7751
void SetLocalAddress(char *buf)
Definition: tnetwork.cpp:88
const WCHAR * str
smooth NULL
Definition: ftsmooth.c:416
HANDLE pipeOut
Definition: tnetwork.h:18
SOCKET socket
Definition: tnetwork.h:14
BOOL WINAPI WriteFile(IN HANDLE hFile, IN LPCVOID lpBuffer, IN DWORD nNumberOfBytesToWrite OPTIONAL, OUT LPDWORD lpNumberOfBytesWritten OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:24
BOOL local_echo
Definition: tnetwork.h:15
void SetSocket(SOCKET s)
Definition: tnetwork.cpp:40
int WriteString(const char *str, const int length)
Definition: tnetwork.cpp:53
BOOL line_mode
Definition: tnetwork.h:16
GLenum GLuint GLenum GLsizei length
Definition: glext.h:5579
INT WSAAPI send(IN SOCKET s, IN CONST CHAR FAR *buf, IN INT len, IN INT flags)
Definition: send.c:23
char * local_address
Definition: tnetwork.h:20
unsigned long DWORD
Definition: ntddk_ex.h:95
int ReadString(char *str, const int length)
Definition: tnetwork.cpp:67
GLenum GLsizei len
Definition: glext.h:6722
GLdouble s
Definition: gl.h:2039
GLint GLint GLsizei GLsizei height
Definition: gl.h:1546
Naws_func_t naws_func
Definition: tnetwork.h:19
void do_naws(int width, int height)
Definition: tnetwork.cpp:81
char * strcpy(char *DstString, const char *SrcString)
Definition: utclib.c:388
UINT_PTR SOCKET
Definition: winsock.h:47
BOOL WINAPI ReadFile(IN HANDLE hFile, IN LPVOID lpBuffer, IN DWORD nNumberOfBytesToRead, OUT LPDWORD lpNumberOfBytesRead OPTIONAL, IN LPOVERLAPPED lpOverlapped OPTIONAL)
Definition: rw.c:123
INT WSAAPI recv(IN SOCKET s, OUT CHAR FAR *buf, IN INT len, IN INT flags)
Definition: recv.c:23