📄 rfbproto.h
字号:
/*
* Copyright (C) 2000-2006 Constantin Kaplinsky. All Rights Reserved.
* Copyright (C) 2000 Tridia Corporation. All Rights Reserved.
* Copyright (C) 1999 AT&T Laboratories Cambridge. All Rights Reserved.
*
* This is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This software is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this software; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
* USA.
*/
/*
* rfbproto.h - header file for the RFB protocol, versions 3.3, 3.7 and 3.7t,
* 3.8 and 3.8t ("t" suffix denotes TightVNC protocol extensions enabled)
*
* Uses types CARD<n> for an n-bit unsigned integer, INT<n> for an n-bit signed
* integer (for n = 8, 16 and 32).
*
* All multiple byte integers are in big endian (network) order (most
* significant byte first). Unless noted otherwise there is no special
* alignment of protocol structures.
*
*
* Once the initial handshaking is done, all messages start with a type byte,
* (usually) followed by message-specific data. The order of definitions in
* this file is as follows:
*
* (1) Structures used in several types of message.
* (2) Structures used in the initial handshaking.
* (3) Message types.
* (4) Encoding types.
* (5) For each message type, the form of the data following the type byte.
* Sometimes this is defined by a single structure but the more complex
* messages have to be explained by comments.
*/
/*****************************************************************************
*
* Structures used in several messages
*
*****************************************************************************/
/*-----------------------------------------------------------------------------
* Structure used to specify a rectangle. This structure is a multiple of 4
* bytes so that it can be interspersed with 32-bit pixel data without
* affecting alignment.
*/
typedef struct _rfbRectangle {
CARD16 x;
CARD16 y;
CARD16 w;
CARD16 h;
} rfbRectangle;
#define sz_rfbRectangle 8
/*-----------------------------------------------------------------------------
* Structure used to specify pixel format.
*/
typedef struct _rfbPixelFormat {
CARD8 bitsPerPixel; /* 8,16,32 only */
CARD8 depth; /* 8 to 32 */
CARD8 bigEndian; /* True if multi-byte pixels are interpreted
as big endian, or if single-bit-per-pixel
has most significant bit of the byte
corresponding to first (leftmost) pixel. Of
course this is meaningless for 8 bits/pix */
CARD8 trueColour; /* If false then we need a "colour map" to
convert pixels to RGB. If true, xxxMax and
xxxShift specify bits used for red, green
and blue */
/* the following fields are only meaningful if trueColour is true */
CARD16 redMax; /* maximum red value (= 2^n - 1 where n is the
number of bits used for red). Note this
value is always in big endian order. */
CARD16 greenMax; /* similar for green */
CARD16 blueMax; /* and blue */
CARD8 redShift; /* number of shifts needed to get the red
value in a pixel to the least significant
bit. To find the red value from a given
pixel, do the following:
1) Swap pixel value according to bigEndian
(e.g. if bigEndian is false and host byte
order is big endian, then swap).
2) Shift right by redShift.
3) AND with redMax (in host byte order).
4) You now have the red value between 0 and
redMax. */
CARD8 greenShift; /* similar for green */
CARD8 blueShift; /* and blue */
CARD8 pad1;
CARD16 pad2;
} rfbPixelFormat;
#define sz_rfbPixelFormat 16
/*-----------------------------------------------------------------------------
* Structure used to describe protocol options such as tunneling methods,
* authentication schemes and message types (protocol versions 3.7t, 3.8t).
*/
typedef struct _rfbCapabilityInfo {
CARD32 code; /* numeric identifier */
CARD8 vendorSignature[4]; /* vendor identification */
CARD8 nameSignature[8]; /* abbreviated option name */
} rfbCapabilityInfo;
#define sz_rfbCapabilityInfoVendor 4
#define sz_rfbCapabilityInfoName 8
#define sz_rfbCapabilityInfo 16
/*
* Vendors known by TightVNC: standard VNC/RealVNC, TridiaVNC, and TightVNC.
*/
#define rfbStandardVendor "STDV"
#define rfbTridiaVncVendor "TRDV"
#define rfbTightVncVendor "TGHT"
/*****************************************************************************
*
* Initial handshaking messages
*
*****************************************************************************/
/*-----------------------------------------------------------------------------
* Protocol Version
*
* The server always sends 12 bytes to start which identifies the latest RFB
* protocol version number which it supports. These bytes are interpreted
* as a string of 12 ASCII characters in the format "RFB xxx.yyy\n" where
* xxx and yyy are the major and minor version numbers (e.g. for version 3.8
* this is "RFB 003.008\n").
*
* The client then replies with a similar 12-byte message giving the version
* number of the protocol which should actually be used (which may be different
* to that quoted by the server).
*
* It is intended that both clients and servers may provide some level of
* backwards compatibility by this mechanism. Servers in particular should
* attempt to provide backwards compatibility, and even forwards compatibility
* to some extent. For example if a client demands version 3.1 of the
* protocol, a 3.0 server can probably assume that by ignoring requests for
* encoding types it doesn't understand, everything will still work OK. This
* will probably not be the case for changes in the major version number.
*
* The format string below can be used in sprintf or sscanf to generate or
* decode the version string respectively.
*/
#define rfbProtocolVersionFormat "RFB %03d.%03d\n"
typedef char rfbProtocolVersionMsg[13]; /* allow extra byte for null */
#define sz_rfbProtocolVersionMsg 12
/*
* Negotiation of the security type (protocol versions 3.7, 3.8)
*
* Once the protocol version has been decided, the server either sends a list
* of supported security types, or informs the client about an error (when the
* number of security types is 0). Security type rfbSecTypeTight is used to
* enable TightVNC-specific protocol extensions. The value rfbSecTypeVncAuth
* stands for classic VNC authentication.
*
* The client selects a particular security type from the list provided by the
* server.
*/
#define rfbSecTypeInvalid 0
#define rfbSecTypeNone 1
#define rfbSecTypeVncAuth 2
#define rfbSecTypeTight 16
/*-----------------------------------------------------------------------------
* Negotiation of Tunneling Capabilities (protocol versions 3.7t, 3.8t)
*
* If the chosen security type is rfbSecTypeTight, the server sends a list of
* supported tunneling methods ("tunneling" refers to any additional layer of
* data transformation, such as encryption or external compression.)
*
* nTunnelTypes specifies the number of following rfbCapabilityInfo structures
* that list all supported tunneling methods in the order of preference.
*
* NOTE: If nTunnelTypes is 0, that tells the client that no tunneling can be
* used, and the client should not send a response requesting a tunneling
* method.
*/
typedef struct _rfbTunnelingCapsMsg {
CARD32 nTunnelTypes;
/* followed by nTunnelTypes * rfbCapabilityInfo structures */
} rfbTunnelingCapsMsg;
#define sz_rfbTunnelingCapsMsg 4
/*-----------------------------------------------------------------------------
* Tunneling Method Request (protocol versions 3.7t, 3.8t)
*
* If the list of tunneling capabilities sent by the server was not empty, the
* client should reply with a 32-bit code specifying a particular tunneling
* method. The following code should be used for no tunneling.
*/
#define rfbNoTunneling 0
#define sig_rfbNoTunneling "NOTUNNEL"
/*-----------------------------------------------------------------------------
* Negotiation of Authentication Capabilities (protocol versions 3.7t, 3.8t)
*
* After setting up tunneling, the server sends a list of supported
* authentication schemes.
*
* nAuthTypes specifies the number of following rfbCapabilityInfo structures
* that list all supported authentication schemes in the order of preference.
*
* NOTE: If nAuthTypes is 0, that tells the client that no authentication is
* necessary, and the client should not send a response requesting an
* authentication scheme.
*/
typedef struct _rfbAuthenticationCapsMsg {
CARD32 nAuthTypes;
/* followed by nAuthTypes * rfbCapabilityInfo structures */
} rfbAuthenticationCapsMsg;
#define sz_rfbAuthenticationCapsMsg 4
/*-----------------------------------------------------------------------------
* Authentication Scheme Request (protocol versions 3.7t, 3.8t)
*
* If the list of authentication capabilities sent by the server was not empty,
* the client should reply with a 32-bit code specifying a particular
* authentication scheme. The following codes are supported.
*/
/* Standard authentication methods. */
#define rfbAuthNone 1
#define rfbAuthVNC 2
#define sig_rfbAuthNone "NOAUTH__"
#define sig_rfbAuthVNC "VNCAUTH_"
/* These two are not used in the mainstream version. */
#define rfbAuthUnixLogin 129
#define rfbAuthExternal 130
#define sig_rfbAuthUnixLogin "ULGNAUTH"
#define sig_rfbAuthExternal "XTRNAUTH"
/*-----------------------------------------------------------------------------
* Authentication result codes (all protocol versions, but rfbAuthTooMany is
* not used in protocol versions above 3.3)
*
* In the protocol version 3.8 and above, rfbAuthFailed is followed by a text
* string describing the reason of failure. The text string is preceded with a
* 32-bit counter of bytes in the string.
*/
#define rfbAuthOK 0
#define rfbAuthFailed 1
#define rfbAuthTooMany 2
/*-----------------------------------------------------------------------------
* Client Initialisation Message
*
* Once the client and server are sure that they're happy to talk to one
* another, the client sends an initialisation message. At present this
* message only consists of a boolean indicating whether the server should try
* to share the desktop by leaving other clients connected, or give exclusive
* access to this client by disconnecting all other clients.
*/
typedef struct _rfbClientInitMsg {
CARD8 shared;
} rfbClientInitMsg;
#define sz_rfbClientInitMsg 1
/*-----------------------------------------------------------------------------
* Server Initialisation Message
*
* After the client initialisation message, the server sends one of its own.
* This tells the client the width and height of the server's framebuffer,
* its pixel format and the name associated with the desktop.
*/
typedef struct _rfbServerInitMsg {
CARD16 framebufferWidth;
CARD16 framebufferHeight;
rfbPixelFormat format; /* the server's preferred pixel format */
CARD32 nameLength;
/* followed by char name[nameLength] */
} rfbServerInitMsg;
#define sz_rfbServerInitMsg (8 + sz_rfbPixelFormat)
/*-----------------------------------------------------------------------------
* Server Interaction Capabilities Message (protocol versions 3.7t, 3.8t)
*
* If TightVNC protocol extensions are enabled, the server informs the client
* what message types it supports in addition to ones defined in the standard
* RFB protocol.
* Also, the server sends the list of all supported encodings (note that it's
* not necessary to advertise the "raw" encoding sinse it MUST be supported in
* RFB 3.x protocols).
*
* This data immediately follows the server initialisation message.
*/
typedef struct _rfbInteractionCapsMsg {
CARD16 nServerMessageTypes;
CARD16 nClientMessageTypes;
CARD16 nEncodingTypes;
CARD16 pad; /* reserved, must be 0 */
/* followed by nServerMessageTypes * rfbCapabilityInfo structures */
/* followed by nClientMessageTypes * rfbCapabilityInfo structures */
} rfbInteractionCapsMsg;
#define sz_rfbInteractionCapsMsg 8
/*
* Following the server initialisation message it's up to the client to send
* whichever protocol messages it wants. Typically it will send a
* SetPixelFormat message and a SetEncodings message, followed by a
* FramebufferUpdateRequest. From then on the server will send
* FramebufferUpdate messages in response to the client's
* FramebufferUpdateRequest messages. The client should send
* FramebufferUpdateRequest messages with incremental set to true when it has
* finished processing one FramebufferUpdate and is ready to process another.
* With a fast client, the rate at which FramebufferUpdateRequests are sent
* should be regulated to avoid hogging the network.
*/
/*****************************************************************************
*
* Message types
*
*****************************************************************************/
/* server -> client */
#define rfbFramebufferUpdate 0
#define rfbSetColourMapEntries 1
#define rfbBell 2
#define rfbServerCutText 3
#define rfbFileListData 130
#define rfbFileDownloadData 131
#define rfbFileUploadCancel 132
#define rfbFileDownloadFailed 133
/* signatures for non-standard messages */
#define sig_rfbFileListData "FTS_LSDT"
#define sig_rfbFileDownloadData "FTS_DNDT"
#define sig_rfbFileUploadCancel "FTS_UPCN"
#define sig_rfbFileDownloadFailed "FTS_DNFL"
/* client -> server */
#define rfbSetPixelFormat 0
#define rfbFixColourMapEntries 1 /* not currently supported */
#define rfbSetEncodings 2
#define rfbFramebufferUpdateRequest 3
#define rfbKeyEvent 4
#define rfbPointerEvent 5
#define rfbClientCutText 6
#define rfbFileListRequest 130
#define rfbFileDownloadRequest 131
#define rfbFileUploadRequest 132
#define rfbFileUploadData 133
#define rfbFileDownloadCancel 134
#define rfbFileUploadFailed 135
#define rfbFileCreateDirRequest 136
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -