36 #define WIN32_LEAN_AND_MEAN
38 #pragma warning(disable:4996)
42 #if defined(ANDROID) || defined(LIBVNCSERVER_HAVE_ANDROID)
43 #include <arpa/inet.h>
44 #include <sys/select.h>
50 #if LIBVNCSERVER_HAVE_SYS_TIME_H
53 #if LIBVNCSERVER_HAVE_UNISTD_H
60 #ifdef LIBVNCSERVER_HAVE_SASL
61 #include <sasl/sasl.h>
64 #define rfbClientSwap16IfLE(s) \
65 (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
67 #define rfbClientSwap32IfLE(l) \
68 (*(char *)&client->endianTest ? ((((l) >> 24) & 0x000000ff) | \
69 (((l) & 0x00ff0000) >> 8) | \
70 (((l) & 0x0000ff00) << 8) | \
71 (((l) & 0x000000ff) << 24)) : (l))
73 #define rfbClientSwap64IfLE(l) \
74 (*(char *)&client->endianTest ? ((((l) >> 56 ) & 0x00000000000000ffULL) | \
75 (((l) & 0x00ff000000000000ULL) >> 40) | \
76 (((l) & 0x0000ff0000000000ULL) >> 24) | \
77 (((l) & 0x000000ff00000000ULL) >> 8) | \
78 (((l) & 0x00000000ff000000ULL) << 8) | \
79 (((l) & 0x0000000000ff0000ULL) << 24) | \
80 (((l) & 0x000000000000ff00ULL) << 40) | \
81 (((l) & 0x00000000000000ffULL) << 56)) : (l))
83 #define FLASH_PORT_OFFSET 5400
84 #define LISTEN_PORT_OFFSET 5500
85 #define TUNNEL_PORT_OFFSET 5500
86 #define SERVER_PORT_OFFSET 5900
88 #define DEFAULT_CONNECT_TIMEOUT 60
89 #define DEFAULT_READ_TIMEOUT 0
91 #define DEFAULT_SSH_CMD "/usr/bin/ssh"
92 #define DEFAULT_TUNNEL_CMD \
93 (DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
94 #define DEFAULT_VIA_CMD \
95 (DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")
97 #if(defined __cplusplus)
142 typedef union _rfbCredential
161 #define rfbCredentialTypeX509 1
162 #define rfbCredentialTypeUser 2
167 #define rfbX509CrlVerifyNone 0
168 #define rfbX509CrlVerifyClient 1
169 #define rfbX509CrlVerifyAll 2
216 typedef char* (*GetPasswordProc)(
struct _rfbClient*
client);
229 typedef void (*
GotCopyRectProc)(
struct _rfbClient*
client,
int src_x,
int src_y,
int w,
int h,
int dest_x,
int dest_y);
236 #ifdef LIBVNCSERVER_HAVE_SASL
237 typedef char* (*GetUserProc)(
struct _rfbClient*
client);
238 typedef char* (*GetSASLMechanismProc)(
struct _rfbClient*
client,
char* mechlist);
241 typedef struct _rfbClient {
264 #define RFB_BUFFER_SIZE (640*480)
277 #define RFB_BUF_SIZE 8192
296 #ifdef LIBVNCSERVER_HAVE_LIBZ
297 z_stream decompStream;
302 #ifdef LIBVNCSERVER_HAVE_LIBZ
308 #define ZLIB_BUFFER_SIZE 30000
309 char zlib_buffer[ZLIB_BUFFER_SIZE];
312 z_stream zlibStream[4];
317 int rectWidth, rectColors;
318 char tightPalette[256*4];
319 uint8_t tightPrevRow[2048*3*
sizeof(uint16_t)];
321 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
325 struct jpeg_source_mgr* jpegSrcManager;
327 size_t jpegBufferLen;
441 #ifdef LIBVNCSERVER_HAVE_SASL
442 sasl_conn_t *saslconn;
443 const char *saslDecoded;
444 unsigned int saslDecodedLength;
445 unsigned int saslDecodedOffset;
446 sasl_secret_t *saslSecret;
450 GetSASLMechanismProc GetSASLMechanism;
455 #ifdef LIBVNCSERVER_HAVE_LIBZ
456 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
545 int x,
int y,
int w,
int h,
679 typedef struct _rfbClientProtocolExtension {
687 struct _rfbClientProtocolExtension*
next;
833 #if(defined __cplusplus)
void(* GotCursorShapeProc)(struct _rfbClient *client, int xhot, int yhot, int width, int height, int bytesPerPixel)
Called when a cursor shape update was received from the server.
rfbBool SendClientCutText(rfbClient *client, char *str, int len)
Places a string on the server's clipboard.
rfbSocket ConnectClientToTcpAddr6(const char *hostname, int port)
Tries to connect to an IPv4 or IPv6 host.
rfbBool SetDSCP(rfbSocket sock, int dscp)
void(* GotFillRectProc)(struct _rfbClient *client, int x, int y, int w, int h, uint32_t colour)
void(* HandleXvpMsgProc)(struct _rfbClient *client, uint8_t version, uint8_t opcode)
Handles XVP server messages.
rfbBool InitialiseRFBConnection(rfbClient *client)
rfbClient * rfbGetClient(int bitsPerSample, int samplesPerPixel, int bytesPerPixel)
Allocates and returns a pointer to an rfbClient structure.
int WaitForMessage(rfbClient *client, unsigned int usecs)
Waits for an RFB message to arrive from the server.
rfbBool HandleCursorShape(rfbClient *client, int xhot, int yhot, int width, int height, uint32_t enc)
Handles XCursor and RichCursor shape updates from the server.
rfbSocket ConnectClientToUnixSockWithTimeout(const char *sockFile, unsigned int timeout)
Tries to connect to a Unix socket using the given timeout value.
void(* FinishedFrameBufferUpdateProc)(struct _rfbClient *client)
Callback indicating that a client has completely processed an rfbFramebufferUpdate message sent by a ...
rfbBool WriteToRFBServer(rfbClient *client, const char *buf, unsigned int n)
rfbSocket ConnectClientToTcpAddr(unsigned int host, int port)
Tries to connect to an IPv4 host.
rfbBool TextChatOpen(rfbClient *client)
Opens a text chat window on the server.
void(* SoftCursorLockAreaProc)(struct _rfbClient *client, int x, int y, int w, int h)
rfbBool TextChatFinish(rfbClient *client)
rfbSocket ConnectClientToUnixSock(const char *sockFile)
Tries to connect to a Unix socket.
void listenForIncomingConnections(rfbClient *viewer)
rfbBool ConnectToRFBRepeater(rfbClient *client, const char *repeaterHost, int repeaterPort, const char *destHost, int destPort)
rfbBool(* HandleCursorPosProc)(struct _rfbClient *client, int x, int y)
rfbBool PermitServerInput(rfbClient *client, int enabled)
void(* rfbClientLogProc)(const char *format,...)
rfbBool errorMessageOnReadFailure
rfbSocket ListenAtTcpPortAndAddress(int port, const char *address)
rfbClientLogProc rfbClientLog
int FindFreeTcpPort(void)
void rfbClientCleanup(rfbClient *client)
Cleans up the client structure and releases the memory allocated for it.
void(* GotBitmapProc)(struct _rfbClient *client, const uint8_t *buffer, int x, int y, int w, int h)
void(* BellProc)(struct _rfbClient *client)
rfbBool SetNonBlocking(rfbSocket sock)
rfbBool SendExtendedKeyEvent(rfbClient *client, uint32_t keysym, uint32_t keycode, rfbBool down)
The same as SendKeyEvent, except a key code will be sent along with the symbol if the server supports...
rfbBool TextChatSend(rfbClient *client, char *text)
Sends a text chat message to the server.
void(* GotCopyRectProc)(struct _rfbClient *client, int src_x, int src_y, int w, int h, int dest_x, int dest_y)
rfbBool(* MallocFrameBufferProc)(struct _rfbClient *client)
rfbBool SendExtDesktopSize(rfbClient *client, uint16_t width, uint16_t height)
Sends a SetDesktopSize event to the server.
void(* GotFrameBufferUpdateProc)(struct _rfbClient *client, int x, int y, int w, int h)
Callback indicating that a rectangular area of the client's framebuffer was updated.
rfbSocket AcceptTcpConnection(rfbSocket listenSock)
rfbSocket ListenAtTcpPort(int port)
rfbBool(* GotJpegProc)(struct _rfbClient *client, const uint8_t *buffer, int length, int x, int y, int w, int h)
rfbBool TextChatClose(rfbClient *client)
Closes the text chat window on the server.
void(* HandleKeyboardLedStateProc)(struct _rfbClient *client, int value, int pad)
rfbBool SendScaleSetting(rfbClient *client, int scaleSetting)
void rfbClientRegisterExtension(rfbClientProtocolExtension *e)
void(* HandleTextChatProc)(struct _rfbClient *client, int value, char *text)
Handles a text chat message.
rfbSocket ConnectClientToTcpAddr6WithTimeout(const char *hostname, int port, unsigned int timeout)
Tries to connect to an IPv4 or IPv6 host using the given timeout value.
rfbBool HandleRFBServerMessage(rfbClient *client)
Handles messages from the RFB server.
rfbBool StringToIPAddr(const char *str, unsigned int *addr)
rfbBool SendPointerEvent(rfbClient *client, int x, int y, int buttonMask)
Sends a pointer event to the server.
void(* GotXCutTextProc)(struct _rfbClient *client, const char *text, int textlen)
rfbBool rfbInitClient(rfbClient *client, int *argc, char **argv)
Initializes the client.
rfbBool SendKeyEvent(rfbClient *client, uint32_t key, rfbBool down)
Sends a key event to the server.
rfbSocket ConnectClientToTcpAddrWithTimeout(unsigned int host, int port, unsigned int timeout)
Tries to connect to an IPv4 host using the given timeout value.
void(* SoftCursorUnlockScreenProc)(struct _rfbClient *client)
rfbBool SendXvpMsg(rfbClient *client, uint8_t version, uint8_t code)
rfbCredential *(* GetCredentialProc)(struct _rfbClient *client, int credentialType)
char *(* GetPasswordProc)(struct _rfbClient *client)
rfbBool(* LockWriteToTLSProc)(struct _rfbClient *client)
rfbBool SendFramebufferUpdateRequest(rfbClient *client, int x, int y, int w, int h, rfbBool incremental)
Sends a framebuffer update request to the server.
void SetClientAuthSchemes(rfbClient *client, const uint32_t *authSchemes, int size)
rfbBool SetBlocking(rfbSocket sock)
rfbBool ReadFromRFBServer(rfbClient *client, char *out, unsigned int n)
rfbBool SupportsServer2Client(rfbClient *client, int messageType)
rfbBool ConnectToRFBServer(rfbClient *client, const char *hostname, int port)
void * rfbClientGetClientData(rfbClient *client, void *tag)
Returns a pointer to the client data associated with the given tag.
int listenForIncomingConnectionsNoFork(rfbClient *viewer, int usec_timeout)
rfbClientLogProc rfbClientErr
rfbBool(* UnlockWriteToTLSProc)(struct _rfbClient *client)
void rfbClientSetClientData(rfbClient *client, void *tag, void *data)
Associates a client data tag with the given pointer.
rfbBool SendIncrementalFramebufferUpdateRequest(rfbClient *client)
rfbBool rfbEnableClientLogging
rfbBool SetFormatAndEncodings(rfbClient *client)
Sends format and encoding parameters to the server.
rfbBool SameMachine(rfbSocket sock)
rfbBool SupportsClient2Server(rfbClient *client, int messageType)
void PrintPixelFormat(rfbPixelFormat *format)
#define RFB_BUFFER_SIZE
Note that the CoRRE encoding uses this buffer and assumes it is big enough to hold 255 * 255 * 32 bit...
app data (belongs into rfbClient?)
rfbBool palmVNC
use palmvnc specific SetScale (vs ultravnc)
int scaleSetting
0 means no scale set, else 1/scaleSetting
const char * encodingsString
struct rfbClientData * next
rfbSupportedMessages supportedMessages
Which messages are supported by the server This is a guess for most servers.
unsigned int connectTimeout
HandleCursorPosProc HandleCursorPos
int KeyboardLedStateEnabled
GotFrameBufferUpdateProc GotFrameBufferUpdate
UnlockWriteToTLSProc UnlockWriteToTLS
SoftCursorUnlockScreenProc SoftCursorUnlockScreen
void * tlsSession
The TLS session for Anonymous TLS and VeNCrypt.
MUTEX(tlsRwMutex)
Mutex to protect concurrent TLS read/write.
LockWriteToTLSProc LockWriteToTLS
These lock/unlock hooks are not used anymore.
rfbClientData * clientData
private data pointer
rfbExtDesktopScreen screen
Used for intended dimensions, rfbClient.width and rfbClient.height are used to manage the real frameb...
GotXCutTextProc GotXCutText
HandleTextChatProc HandleTextChat
unsigned long outputWindow
FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate
GotFillRectProc GotFillRect
Hooks for custom rendering.
GetCredentialProc GetCredential
To support security types that requires user input (except VNC password authentication),...
HandleXvpMsgProc HandleXvpMsg
hook to handle xvp server messages
uint32_t * clientAuthSchemes
The 0-terminated security types supported by the client.
HandleKeyboardLedStateProc HandleKeyboardLedState
uint32_t authScheme
The selected security types.
GetPasswordProc GetPassword
the pointer returned by GetPassword will be freed after use!
int major
negotiated protocol version
char * destHost
When the server is a repeater, this specifies the final destination.
int QoS_DSCP
the QoS IP DSCP for this client
GotCursorShapeProc GotCursorShape
GotCopyRectProc GotCopyRect
GotJpegProc GotJpeg
Hook for custom JPEG decoding and rendering.
MallocFrameBufferProc MallocFrameBuffer
int serverPort
if -1, then use file recorded by vncrec
SoftCursorLockAreaProc SoftCursorLockArea
int CurrentKeyboardLedState
uint32_t const * securityTypes
struct _rfbClientProtocolExtension * next
For GetCredentialProc callback function to return.
char * x509ClientCertFile
uint8_t x509CrlVerifyMode