📄 telnet.h
字号:
/* * telnet.h * * TELNET Socket class. * * Portable Windows Library * * Copyright (c) 1993-1998 Equivalence Pty. Ltd. * * The contents of this file are subject to the Mozilla Public License * Version 1.0 (the "License"); you may not use this file except in * compliance with the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" * basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See * the License for the specific language governing rights and limitations * under the License. * * The Original Code is Portable Windows Library. * * The Initial Developer of the Original Code is Equivalence Pty. Ltd. * * Portions are Copyright (C) 1993 Free Software Foundation, Inc. * All Rights Reserved. * * Contributor(s): ______________________________________. * * $Log: telnet.h,v $ * Revision 1.21 1999/03/09 08:01:47 robertj * Changed comments for doc++ support (more to come). * * Revision 1.20 1999/02/16 08:07:10 robertj * MSVC 6.0 compatibility changes. * * Revision 1.19 1998/11/30 02:50:56 robertj * New directory structure * * Revision 1.18 1998/09/23 06:20:04 robertj * Added open source copyright license. * * Revision 1.17 1996/08/08 10:08:54 robertj * Directory structure changes for common files. * * Revision 1.16 1995/06/17 11:13:32 robertj * Documentation update. * * Revision 1.15 1995/06/17 00:47:38 robertj * Changed overloaded Open() calls to 3 separate function names. * More logical design of port numbers and service names. * * Revision 1.14 1995/06/04 12:46:26 robertj * Slight redesign of port numbers on sockets. * * Revision 1.13 1995/04/25 11:12:30 robertj * Fixed functions hiding ancestor virtuals. * * Revision 1.12 1995/04/01 08:32:10 robertj * Finally got a working TELNET. * * Revision 1.11 1995/03/18 06:27:50 robertj * Rewrite of telnet socket protocol according to RFC1143. * * Revision 1.10 1995/03/14 12:42:47 robertj * Updated documentation to use HTML codes. * * Revision 1.9 1995/02/21 11:25:33 robertj * Further implementation of telnet socket, feature complete now. * * Revision 1.8 1995/01/03 09:36:23 robertj * Documentation. * * Revision 1.7 1995/01/01 01:07:33 robertj * More implementation. * * Revision 1.6 1994/11/28 12:38:59 robertj * Added DONT and WONT states. * * Revision 1.5 1994/08/23 11:32:52 robertj * Oops * * Revision 1.4 1994/08/22 00:46:48 robertj * Added pragma fro GNU C++ compiler. * * Revision 1.3 1994/08/21 23:43:02 robertj * Changed type of socket port number for better portability. * * Revision 1.2 1994/07/25 03:36:03 robertj * Added sockets to common, normalising to same comment standard. * */#ifndef _PTELNETSOCKET#define _PTELNETSOCKET#ifdef __GNUC__#pragma interface#endif#include <ptlib/sockets.h>/** A TCP/IP socket for the TELNET high level protocol. */class PTelnetSocket : public PTCPSocket{ PCLASSINFO(PTelnetSocket, PTCPSocket) public: PTelnetSocket(); // Create an unopened TELNET socket. PTelnetSocket( const PString & address // Address of remote machine to connect to. ); // Create an opened TELNET socket. // Overrides from class PChannel /** Low level read from the channel. This function may block until the requested number of characters were read or the read timeout was reached. The GetLastReadCount() function returns the actual number of bytes read. The GetErrorCode() function should be consulted after Read() returns FALSE to determine what caused the failure. The TELNET channel intercepts and escapes commands in the data stream to implement the TELNET protocol. @return TRUE indicates that at least one character was read from the channel. FALSE means no bytes were read due to timeout or some other I/O error. */ BOOL Read( void * buf, // Pointer to a block of memory to receive the read bytes. PINDEX len // Maximum number of bytes to read into the buffer. ); /** Low level write to the channel. This function will block until the requested number of characters are written or the write timeout is reached. The GetLastWriteCount() function returns the actual number of bytes written. The GetErrorCode() function should be consulted after Write() returns FALSE to determine what caused the failure. The TELNET channel intercepts and escapes commands in the data stream to implement the TELNET protocol. Returns TRUE if at least len bytes were written to the channel. */ BOOL Write( const void * buf, // Pointer to a block of memory to write. PINDEX len // Number of bytes to write. ); /** Connect a socket to a remote host on the specified port number. This is typically used by the client or initiator of a communications channel. This connects to a "listening" socket at the other end of the communications channel. The port number as defined by the object instance construction or the <A>PIPSocket::SetPort()</A> function. @return TRUE if the channel was successfully connected to the remote host. */ virtual BOOL Connect( const PString & address // Address of remote machine to connect to. ); /** Open a socket to a remote host on the specified port number. This is an "accepting" socket. When a "listening" socket has a pending connection to make, this will accept a connection made by the "connecting" socket created to establish a link. The port that the socket uses is the one used in the <A>Listen()</A> command of the <CODE>socket</CODE> parameter. Note that this function will block until a remote system connects to the port number specified in the "listening" socket. @return TRUE if the channel was successfully opened. */ virtual BOOL Accept( PSocket & socket // Listening socket making the connection. ); /** This is callback function called by the system whenever out of band data from the TCP/IP stream is received. A descendent class may interpret this data according to the semantics of the high level protocol. The TELNET socket uses this for sychronisation. */ virtual void OnOutOfBand( const void * buf, // Data to be received as URGENT TCP data. PINDEX len // Number of bytes pointed to by <CODE>buf</CODE>. ); // New functions enum Command { IAC = 255, // Interpret As Command - escape character. DONT = 254, // You are not to use option. DO = 253, // Request to use option. WONT = 252, // Refuse use of option. WILL = 251, // Accept the use of option. SB = 250, // Subnegotiation begin. GoAhead = 249, // Function GA, you may reverse the line. EraseLine = 248, // Function EL, erase the current line. EraseChar = 247, // Function EC, erase the current character. AreYouThere = 246, // Function AYT, are you there? AbortOutput = 245, // Function AO, abort output stream. InterruptProcess = 244, // Function IP, interrupt process, permanently. Break = 243, // NVT character break. DataMark = 242, // Marker for connection cleaning. NOP = 241, // No operation. SE = 240, // Subnegotiation end. EndOfReccord = 239, // End of record for transparent mode. AbortProcess = 238, // Abort the entire process SuspendProcess= 237, // Suspend the process. EndOfFile = 236 // End of file marker. }; // Defined telnet commands codes /** Send an escaped IAC command. The <CODE>opt</CODE> parameters meaning depends on the command being sent: <DL> <DT>DO, DONT, WILL, WONT <DD><CODE>opt</CODE> is Options code. <DT>AbortOutput <DD>TRUE is flush buffer. <DT>InterruptProcess, Break, AbortProcess, SuspendProcess <DD>TRUE is synchronise. </DL> Synchronises the TELNET streams, inserts the data mark into outgoing data stream and sends an out of band data to the remote to flush all data in the stream up until the syncronisation command. @return TRUE if the command was successfully sent. */ BOOL SendCommand( Command cmd, // Command code to send int opt = 0 // Option for command code. ); enum Options { TransmitBinary = 0, // Assume binary 8 bit data is transferred. EchoOption = 1, // Automatically echo characters sent. ReconnectOption = 2, // Prepare to reconnect SuppressGoAhead = 3, // Do not use the GA protocol. MessageSizeOption = 4, // Negatiate approximate message size StatusOption = 5, // Status packets are understood. TimingMark = 6, // Marker for synchronisation. RCTEOption = 7, // Remote controlled transmission and echo. OutputLineWidth = 8, // Negotiate about output line width. OutputPageSize = 9, // Negotiate about output page size. CRDisposition = 10, // Negotiate about CR disposition. HorizontalTabsStops = 11, // Negotiate about horizontal tabstops.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -