Home | History | Annotate | Download | only in rfb
      1 #ifndef RFBCLIENT_H
      2 #define RFBCLIENT_H
      3 
      4 /**
      5  * @defgroup libvncclient_api LibVNCClient API Reference
      6  * @{
      7  */
      8 
      9 /*
     10  *  Copyright (C) 2000, 2001 Const Kaplinsky.  All Rights Reserved.
     11  *  Copyright (C) 2000 Tridia Corporation.  All Rights Reserved.
     12  *  Copyright (C) 1999 AT&T Laboratories Cambridge.  All Rights Reserved.
     13  *
     14  *  This is free software; you can redistribute it and/or modify
     15  *  it under the terms of the GNU General Public License as published by
     16  *  the Free Software Foundation; either version 2 of the License, or
     17  *  (at your option) any later version.
     18  *
     19  *  This software is distributed in the hope that it will be useful,
     20  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
     21  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     22  *  GNU General Public License for more details.
     23  *
     24  *  You should have received a copy of the GNU General Public License
     25  *  along with this software; if not, write to the Free Software
     26  *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,
     27  *  USA.
     28  */
     29 
     30 /**
     31  * @file rfbclient.h
     32  */
     33 
     34 #ifdef WIN32
     35 #define WIN32_LEAN_AND_MEAN /* Prevent loading any Winsock 1.x headers from windows.h */
     36 #endif
     37 
     38 #include <stdio.h>
     39 #include <stdlib.h>
     40 #include <string.h>
     41 #include <sys/time.h>
     42 #include <unistd.h>
     43 #include <rfb/rfbproto.h>
     44 #include <rfb/keysym.h>
     45 
     46 #define rfbClientSwap16IfLE(s) \
     47     (*(char *)&client->endianTest ? ((((s) & 0xff) << 8) | (((s) >> 8) & 0xff)) : (s))
     48 
     49 #define rfbClientSwap32IfLE(l) \
     50     (*(char *)&client->endianTest ? ((((l) & 0xff000000) >> 24) | \
     51 			     (((l) & 0x00ff0000) >> 8)  | \
     52 			     (((l) & 0x0000ff00) << 8)  | \
     53 			     (((l) & 0x000000ff) << 24))  : (l))
     54 
     55 #define rfbClientSwap64IfLE(l) \
     56     (*(char *)&client->endianTest ? ((((l) & 0xff00000000000000ULL) >> 56) | \
     57 			     (((l) & 0x00ff000000000000ULL) >> 40)  | \
     58 			     (((l) & 0x0000ff0000000000ULL) >> 24)  | \
     59 			     (((l) & 0x000000ff00000000ULL) >> 8)  | \
     60 			     (((l) & 0x00000000ff000000ULL) << 8)  | \
     61 			     (((l) & 0x0000000000ff0000ULL) << 24)  | \
     62 			     (((l) & 0x000000000000ff00ULL) << 40)  | \
     63 			     (((l) & 0x00000000000000ffULL) << 56))  : (l))
     64 
     65 #define FLASH_PORT_OFFSET 5400
     66 #define LISTEN_PORT_OFFSET 5500
     67 #define TUNNEL_PORT_OFFSET 5500
     68 #define SERVER_PORT_OFFSET 5900
     69 
     70 #define DEFAULT_SSH_CMD "/usr/bin/ssh"
     71 #define DEFAULT_TUNNEL_CMD  \
     72   (DEFAULT_SSH_CMD " -f -L %L:localhost:%R %H sleep 20")
     73 #define DEFAULT_VIA_CMD     \
     74   (DEFAULT_SSH_CMD " -f -L %L:%H:%R %G sleep 20")
     75 
     76 #if(defined __cplusplus)
     77 extern "C"
     78 {
     79 #endif
     80 
     81 /** vncrec */
     82 
     83 typedef struct {
     84   FILE* file;
     85   struct timeval tv;
     86   rfbBool readTimestamp;
     87   rfbBool doNotSleep;
     88 } rfbVNCRec;
     89 
     90 /** client data */
     91 
     92 typedef struct rfbClientData {
     93 	void* tag;
     94 	void* data;
     95 	struct rfbClientData* next;
     96 } rfbClientData;
     97 
     98 /** app data (belongs into rfbClient?) */
     99 
    100 typedef struct {
    101   rfbBool shareDesktop;
    102   rfbBool viewOnly;
    103 
    104   const char* encodingsString;
    105 
    106   rfbBool useBGR233;
    107   int nColours;
    108   rfbBool forceOwnCmap;
    109   rfbBool forceTrueColour;
    110   int requestedDepth;
    111 
    112   int compressLevel;
    113   int qualityLevel;
    114   rfbBool enableJPEG;
    115   rfbBool useRemoteCursor;
    116   rfbBool palmVNC;  /**< use palmvnc specific SetScale (vs ultravnc) */
    117   int scaleSetting; /**< 0 means no scale set, else 1/scaleSetting */
    118 } AppData;
    119 
    120 /** For GetCredentialProc callback function to return */
    121 typedef union _rfbCredential
    122 {
    123   /** X509 (VeNCrypt) */
    124   struct
    125   {
    126     char *x509CACertFile;
    127     char *x509CACrlFile;
    128     char *x509ClientCertFile;
    129     char *x509ClientKeyFile;
    130   } x509Credential;
    131   /** Plain (VeNCrypt), MSLogon (UltraVNC) */
    132   struct
    133   {
    134     char *username;
    135     char *password;
    136   } userCredential;
    137 } rfbCredential;
    138 
    139 #define rfbCredentialTypeX509 1
    140 #define rfbCredentialTypeUser 2
    141 
    142 struct _rfbClient;
    143 
    144 /**
    145  * Handles a text chat message. If your application should accept text messages
    146  * from the server, define a function with this prototype and set
    147  * client->HandleTextChat to a pointer to that function subsequent to your
    148  * rfbGetClient() call.
    149  * @param client The client which called the text chat handler
    150  * @param value  text length if text != NULL, or one of rfbTextChatOpen,
    151  * rfbTextChatClose, rfbTextChatFinished if text == NULL
    152  * @param text The text message from the server
    153  */
    154 typedef void (*HandleTextChatProc)(struct _rfbClient* client, int value, char *text);
    155 /**
    156  * Handles XVP server messages. If your application sends XVP messages to the
    157  * server, you'll want to handle the server's XVP_FAIL and XVP_INIT responses.
    158  * Define a function with this prototype and set client->HandleXvpMsg to a
    159  * pointer to that function subsequent to your rfbGetClient() call.
    160  * @param client The client which called the XVP message handler
    161  * @param version The highest XVP extension version that the server supports
    162  * @param opcode The opcode. 0 is XVP_FAIL, 1 is XVP_INIT
    163  */
    164 typedef void (*HandleXvpMsgProc)(struct _rfbClient* client, uint8_t version, uint8_t opcode);
    165 typedef void (*HandleKeyboardLedStateProc)(struct _rfbClient* client, int value, int pad);
    166 typedef rfbBool (*HandleCursorPosProc)(struct _rfbClient* client, int x, int y);
    167 typedef void (*SoftCursorLockAreaProc)(struct _rfbClient* client, int x, int y, int w, int h);
    168 typedef void (*SoftCursorUnlockScreenProc)(struct _rfbClient* client);
    169 typedef void (*GotFrameBufferUpdateProc)(struct _rfbClient* client, int x, int y, int w, int h);
    170 typedef void (*FinishedFrameBufferUpdateProc)(struct _rfbClient* client);
    171 typedef char* (*GetPasswordProc)(struct _rfbClient* client);
    172 typedef rfbCredential* (*GetCredentialProc)(struct _rfbClient* client, int credentialType);
    173 typedef rfbBool (*MallocFrameBufferProc)(struct _rfbClient* client);
    174 typedef void (*GotXCutTextProc)(struct _rfbClient* client, const char *text, int textlen);
    175 typedef void (*BellProc)(struct _rfbClient* client);
    176 
    177 typedef void (*GotCursorShapeProc)(struct _rfbClient* client, int xhot, int yhot, int width, int height, int bytesPerPixel);
    178 typedef void (*GotCopyRectProc)(struct _rfbClient* client, int src_x, int src_y, int w, int h, int dest_x, int dest_y);
    179 
    180 typedef struct _rfbClient {
    181 	uint8_t* frameBuffer;
    182 	int width, height;
    183 
    184 	int endianTest;
    185 
    186 	AppData appData;
    187 
    188 	const char* programName;
    189 	char* serverHost;
    190 	int serverPort; /**< if -1, then use file recorded by vncrec */
    191 	rfbBool listenSpecified;
    192 	int listenPort, flashPort;
    193 
    194 	struct {
    195 		int x, y, w, h;
    196 	} updateRect;
    197 
    198 	/** Note that the CoRRE encoding uses this buffer and assumes it is big enough
    199 	   to hold 255 * 255 * 32 bits -> 260100 bytes.  640*480 = 307200 bytes.
    200 	   Hextile also assumes it is big enough to hold 16 * 16 * 32 bits.
    201 	   Tight encoding assumes BUFFER_SIZE is at least 16384 bytes. */
    202 
    203 #define RFB_BUFFER_SIZE (640*480)
    204 	char buffer[RFB_BUFFER_SIZE];
    205 
    206 	/* rfbproto.c */
    207 
    208 	int sock;
    209 	rfbBool canUseCoRRE;
    210 	rfbBool canUseHextile;
    211 	char *desktopName;
    212 	rfbPixelFormat format;
    213 	rfbServerInitMsg si;
    214 
    215 	/* sockets.c */
    216 #define RFB_BUF_SIZE 8192
    217 	char buf[RFB_BUF_SIZE];
    218 	char *bufoutptr;
    219 	int buffered;
    220 
    221 	/* The zlib encoding requires expansion/decompression/deflation of the
    222 	   compressed data in the "buffer" above into another, result buffer.
    223 	   However, the size of the result buffer can be determined precisely
    224 	   based on the bitsPerPixel, height and width of the rectangle.  We
    225 	   allocate this buffer one time to be the full size of the buffer. */
    226 
    227 	/* Ultra Encoding uses this buffer too */
    228 
    229 	int ultra_buffer_size;
    230 	char *ultra_buffer;
    231 
    232 	int raw_buffer_size;
    233 	char *raw_buffer;
    234 
    235 #ifdef LIBVNCSERVER_HAVE_LIBZ
    236 	z_stream decompStream;
    237 	rfbBool decompStreamInited;
    238 #endif
    239 
    240 
    241 #ifdef LIBVNCSERVER_HAVE_LIBZ
    242 	/*
    243 	 * Variables for the ``tight'' encoding implementation.
    244 	 */
    245 
    246 	/** Separate buffer for compressed data. */
    247 #define ZLIB_BUFFER_SIZE 30000
    248 	char zlib_buffer[ZLIB_BUFFER_SIZE];
    249 
    250 	/* Four independent compression streams for zlib library. */
    251 	z_stream zlibStream[4];
    252 	rfbBool zlibStreamActive[4];
    253 
    254 	/* Filter stuff. Should be initialized by filter initialization code. */
    255 	rfbBool cutZeros;
    256 	int rectWidth, rectColors;
    257 	char tightPalette[256*4];
    258 	uint8_t tightPrevRow[2048*3*sizeof(uint16_t)];
    259 
    260 #ifdef LIBVNCSERVER_HAVE_LIBJPEG
    261 	/** JPEG decoder state. */
    262 	rfbBool jpegError;
    263 
    264 	struct jpeg_source_mgr* jpegSrcManager;
    265 	void* jpegBufferPtr;
    266 	size_t jpegBufferLen;
    267 
    268 #endif
    269 #endif
    270 
    271 
    272 	/* cursor.c */
    273 	uint8_t *rcSource, *rcMask;
    274 
    275 	/** private data pointer */
    276 	rfbClientData* clientData;
    277 
    278 	rfbVNCRec* vncRec;
    279 
    280 	/* Keyboard State support (is 'Caps Lock' set on the remote display???) */
    281 	int KeyboardLedStateEnabled;
    282 	int CurrentKeyboardLedState;
    283 
    284 	int canHandleNewFBSize;
    285 
    286 	/* hooks */
    287 	HandleTextChatProc         HandleTextChat;
    288 	HandleKeyboardLedStateProc HandleKeyboardLedState;
    289 	HandleCursorPosProc HandleCursorPos;
    290 	SoftCursorLockAreaProc SoftCursorLockArea;
    291 	SoftCursorUnlockScreenProc SoftCursorUnlockScreen;
    292 	GotFrameBufferUpdateProc GotFrameBufferUpdate;
    293 	/** the pointer returned by GetPassword will be freed after use! */
    294 	GetPasswordProc GetPassword;
    295 	MallocFrameBufferProc MallocFrameBuffer;
    296 	GotXCutTextProc GotXCutText;
    297 	BellProc Bell;
    298 
    299 	GotCursorShapeProc GotCursorShape;
    300 	GotCopyRectProc GotCopyRect;
    301 
    302 	/** Which messages are supported by the server
    303 	 * This is a *guess* for most servers.
    304 	 * (If we can even detect the type of server)
    305 	 *
    306 	 * If the server supports the "rfbEncodingSupportedMessages"
    307 	 * then this will be updated when the encoding is received to
    308 	 * accurately reflect the servers capabilities.
    309 	 */
    310 	rfbSupportedMessages supportedMessages;
    311 
    312 	/** negotiated protocol version */
    313 	int major, minor;
    314 
    315 	/** The selected security types */
    316 	uint32_t authScheme, subAuthScheme;
    317 
    318 	/** The TLS session for Anonymous TLS and VeNCrypt */
    319 	void* tlsSession;
    320 
    321 	/** To support security types that requires user input (except VNC password
    322 	 * authentication), for example VeNCrypt and MSLogon, this callback function
    323 	 * must be set before the authentication. Otherwise, it implicates that the
    324 	 * caller application does not support it and related security types should
    325 	 * be bypassed.
    326 	 */
    327 	GetCredentialProc GetCredential;
    328 
    329 	/** The 0-terminated security types supported by the client.
    330 	 * Set by function SetClientAuthSchemes() */
    331 	uint32_t *clientAuthSchemes;
    332 
    333 	/** When the server is a repeater, this specifies the final destination */
    334 	char *destHost;
    335 	int destPort;
    336 
    337         /** the QoS IP DSCP for this client */
    338         int QoS_DSCP;
    339 
    340         /** hook to handle xvp server messages */
    341 	HandleXvpMsgProc           HandleXvpMsg;
    342 
    343 	/* listen.c */
    344         int listenSock;
    345 
    346 	FinishedFrameBufferUpdateProc FinishedFrameBufferUpdate;
    347 
    348 	char *listenAddress;
    349         /* IPv6 listen socket, address and port*/
    350         int listen6Sock;
    351         char* listen6Address;
    352         int listen6Port;
    353 
    354         /* Output Window ID. When set, client application enables libvncclient to perform direct rendering in its window */
    355         unsigned long outputWindow;
    356 
    357 } rfbClient;
    358 
    359 /* cursor.c */
    360 
    361 extern rfbBool HandleCursorShape(rfbClient* client,int xhot, int yhot, int width, int height, uint32_t enc);
    362 
    363 /* listen.c */
    364 
    365 extern void listenForIncomingConnections(rfbClient* viewer);
    366 extern int listenForIncomingConnectionsNoFork(rfbClient* viewer, int usec_timeout);
    367 
    368 /* rfbproto.c */
    369 
    370 extern rfbBool rfbEnableClientLogging;
    371 typedef void (*rfbClientLogProc)(const char *format, ...);
    372 extern rfbClientLogProc rfbClientLog,rfbClientErr;
    373 extern rfbBool ConnectToRFBServer(rfbClient* client,const char *hostname, int port);
    374 extern rfbBool ConnectToRFBRepeater(rfbClient* client,const char *repeaterHost, int repeaterPort, const char *destHost, int destPort);
    375 extern void SetClientAuthSchemes(rfbClient* client,const uint32_t *authSchemes, int size);
    376 extern rfbBool InitialiseRFBConnection(rfbClient* client);
    377 /**
    378  * Sends format and encoding parameters to the server. Your application can
    379  * modify the 'client' data structure directly. However some changes to this
    380  * structure must be communicated back to the server. For instance, if you
    381  * change the encoding to hextile, the server needs to know that it should send
    382  * framebuffer updates in hextile format. Likewise if you change the pixel
    383  * format of the framebuffer, the server must be notified about this as well.
    384  * Call this function to propagate your changes of the local 'client' structure
    385  * over to the server.
    386  * @li Encoding type
    387  * @li RFB protocol extensions announced via pseudo-encodings
    388  * @li Framebuffer pixel format (like RGB vs ARGB)
    389  * @li Remote cursor support
    390  * @param client The client in which the format or encodings have been changed
    391  * @return true if the format or encodings were sent to the server successfully,
    392  * false otherwise
    393  */
    394 extern rfbBool SetFormatAndEncodings(rfbClient* client);
    395 extern rfbBool SendIncrementalFramebufferUpdateRequest(rfbClient* client);
    396 /**
    397  * Sends a framebuffer update request to the server. A VNC client may request an
    398  * update from the server at any time. You can also specify which portions of
    399  * the screen you want updated. This can be handy if a pointer is at certain
    400  * location and the user pressed a mouse button, for instance. Then you can
    401  * immediately request an update of the region around the pointer from the
    402  * server.
    403  * @note The coordinate system is a left-handed Cartesian coordinate system with
    404  * the Z axis (unused) pointing out of the screen. Alternately you can think of
    405  * it as a right-handed Cartesian coordinate system with the Z axis pointing
    406  * into the screen. The origin is at the upper left corner of the framebuffer.
    407  * @param client The client through which to send the request
    408  * @param x The horizontal position of the update request rectangle
    409  * @param y The vertical position of the update request rectangle
    410  * @param w The width of the update request rectangle
    411  * @param h The height of the update request rectangle
    412  * @param incremental false: server sends rectangle even if nothing changed.
    413  * true: server only sends changed parts of rectangle.
    414  * @return true if the update request was sent successfully, false otherwise
    415  */
    416 extern rfbBool SendFramebufferUpdateRequest(rfbClient* client,
    417 					 int x, int y, int w, int h,
    418 					 rfbBool incremental);
    419 extern rfbBool SendScaleSetting(rfbClient* client,int scaleSetting);
    420 /**
    421  * Sends a pointer event to the server. A pointer event includes a cursor
    422  * location and a button mask. The button mask indicates which buttons on the
    423  * pointing device are pressed. Each button is represented by a bit in the
    424  * button mask. A 1 indicates the button is pressed while a 0 indicates that it
    425  * is not pressed. You may use these pre-defined button masks by ORing them
    426  * together: rfbButton1Mask, rfbButton2Mask, rfbButton3Mask, rfbButton4Mask
    427  * rfbButton5Mask
    428  * @note  The cursor location is relative to the client's framebuffer, not the
    429  * client's screen itself.
    430  * @note The coordinate system is a left-handed Cartesian coordinate system with
    431  * the Z axis (unused) pointing out of the screen. Alternately you can think of
    432  * it as a right-handed Cartesian coordinate system with the Z axis pointing
    433  * into the screen. The origin is at the upper left corner of the screen.
    434  * @param client The client through which to send the pointer event
    435  * @param x the horizontal location of the cursor
    436  * @param y the vertical location of the cursor
    437  * @param buttonMask the button mask indicating which buttons are pressed
    438  * @return true if the pointer event was sent successfully, false otherwise
    439  */
    440 extern rfbBool SendPointerEvent(rfbClient* client,int x, int y, int buttonMask);
    441 /**
    442  * Sends a key event to the server. If your application is not merely a VNC
    443  * viewer (i.e. it controls the server), you'll want to send the keys that the
    444  * user presses to the server. Use this function to do that.
    445  * @param client The client through which to send the key event
    446  * @param key An rfbKeySym defined in rfb/keysym.h
    447  * @param down true if this was a key down event, false otherwise
    448  * @return true if the key event was send successfully, false otherwise
    449  */
    450 extern rfbBool SendKeyEvent(rfbClient* client,uint32_t key, rfbBool down);
    451 /**
    452  * Places a string on the server's clipboard. Use this function if you want to
    453  * be able to copy and paste between the server and your application. For
    454  * instance, when your application is notified that the user copied some text
    455  * onto the clipboard, you would call this function to synchronize the server's
    456  * clipboard with your local clipboard.
    457  * @param client The client structure through which to send the client cut text
    458  * message
    459  * @param str The string to send (doesn't need to be NULL terminated)
    460  * @param len The length of the string
    461  * @return true if the client cut message was sent successfully, false otherwise
    462  */
    463 extern rfbBool SendClientCutText(rfbClient* client,char *str, int len);
    464 /**
    465  * Handles messages from the RFB server. You must call this function
    466  * intermittently so LibVNCClient can parse messages from the server. For
    467  * example, if your app has a draw loop, you could place a call to this
    468  * function within that draw loop.
    469  * @note You must call WaitForMessage() before you call this function.
    470  * @param client The client which will handle the RFB server messages
    471  * @return true if the client was able to handle the RFB server messages, false
    472  * otherwise
    473  */
    474 extern rfbBool HandleRFBServerMessage(rfbClient* client);
    475 
    476 /**
    477  * Sends a text chat message to the server.
    478  * @param client The client through which to send the message
    479  * @param text The text to send
    480  * @return true if the text was sent successfully, false otherwise
    481  */
    482 extern rfbBool TextChatSend(rfbClient* client, char *text);
    483 /**
    484  * Opens a text chat window on the server.
    485  * @param client The client through which to send the message
    486  * @return true if the window was opened successfully, false otherwise
    487  */
    488 extern rfbBool TextChatOpen(rfbClient* client);
    489 /**
    490  * Closes the text chat window on the server.
    491  * @param client The client through which to send the message
    492  * @return true if the window was closed successfully, false otherwise
    493  */
    494 extern rfbBool TextChatClose(rfbClient* client);
    495 extern rfbBool TextChatFinish(rfbClient* client);
    496 extern rfbBool PermitServerInput(rfbClient* client, int enabled);
    497 extern rfbBool SendXvpMsg(rfbClient* client, uint8_t version, uint8_t code);
    498 
    499 extern void PrintPixelFormat(rfbPixelFormat *format);
    500 
    501 extern rfbBool SupportsClient2Server(rfbClient* client, int messageType);
    502 extern rfbBool SupportsServer2Client(rfbClient* client, int messageType);
    503 
    504 /* client data */
    505 
    506 /**
    507  * Associates a client data tag with the given pointer. LibVNCClient has
    508  * several events to which you can associate your own handlers. These handlers
    509  * have the client structure as one of their parameters. Sometimes, you may want
    510  * to make data from elsewhere in your application available to these handlers
    511  * without using a global variable. To do this, you call
    512  * rfbClientSetClientData() and associate the data with a tag. Then, your
    513  * handler can call rfbClientGetClientData() and get the a pointer to the data
    514  * associated with that tag.
    515  * @param client The client in which to set the client data
    516  * @param tag A unique tag which identifies the data
    517  * @param data A pointer to the data to associate with the tag
    518  */
    519 void rfbClientSetClientData(rfbClient* client, void* tag, void* data);
    520 /**
    521  * Returns a pointer to the client data associated with the given tag. See the
    522  * the documentation for rfbClientSetClientData() for a discussion of how you
    523  * can use client data.
    524  * @param client The client from which to get the client data
    525  * @param tag The tag which identifies the client data
    526  * @return a pointer to the client data
    527  */
    528 void* rfbClientGetClientData(rfbClient* client, void* tag);
    529 
    530 /* protocol extensions */
    531 
    532 typedef struct _rfbClientProtocolExtension {
    533 	int* encodings;
    534 	/** returns TRUE if the encoding was handled */
    535 	rfbBool (*handleEncoding)(rfbClient* cl,
    536 		rfbFramebufferUpdateRectHeader* rect);
    537 	/** returns TRUE if it handled the message */
    538 	rfbBool (*handleMessage)(rfbClient* cl,
    539 		 rfbServerToClientMsg* message);
    540 	struct _rfbClientProtocolExtension* next;
    541 } rfbClientProtocolExtension;
    542 
    543 void rfbClientRegisterExtension(rfbClientProtocolExtension* e);
    544 
    545 /* sockets.c */
    546 
    547 extern rfbBool errorMessageOnReadFailure;
    548 
    549 extern rfbBool ReadFromRFBServer(rfbClient* client, char *out, unsigned int n);
    550 extern rfbBool WriteToRFBServer(rfbClient* client, char *buf, int n);
    551 extern int FindFreeTcpPort(void);
    552 extern int ListenAtTcpPort(int port);
    553 extern int ListenAtTcpPortAndAddress(int port, const char *address);
    554 extern int ConnectClientToTcpAddr(unsigned int host, int port);
    555 extern int ConnectClientToTcpAddr6(const char *hostname, int port);
    556 extern int ConnectClientToUnixSock(const char *sockFile);
    557 extern int AcceptTcpConnection(int listenSock);
    558 extern rfbBool SetNonBlocking(int sock);
    559 extern rfbBool SetDSCP(int sock, int dscp);
    560 
    561 extern rfbBool StringToIPAddr(const char *str, unsigned int *addr);
    562 extern rfbBool SameMachine(int sock);
    563 /**
    564  * Waits for an RFB message to arrive from the server. Before handling a message
    565  * with HandleRFBServerMessage(), you must wait for your client to receive one.
    566  * This function blocks until a message is received. You may specify a timeout
    567  * in microseconds. Once this number of microseconds have elapsed, the function
    568  * will return.
    569  * @param client The client to cause to wait until a message is received
    570  * @param usecs The timeout in microseconds
    571  * @return the return value of the underlying select() call
    572  */
    573 extern int WaitForMessage(rfbClient* client,unsigned int usecs);
    574 
    575 /* vncviewer.c */
    576 /**
    577  * Allocates and returns a pointer to an rfbClient structure. This will probably
    578  * be the first LibVNCClient function your client code calls. Most libVNCClient
    579  * functions operate on an rfbClient structure, and this function allocates
    580  * memory for that structure. When you're done with the rfbClient structure
    581  * pointer this function returns, you should free the memory rfbGetClient()
    582  * allocated by calling rfbClientCleanup().
    583  *
    584  * A pixel is one dot on the screen. The number of bytes in a pixel will depend
    585  * on the number of samples in that pixel and the number of bits in each sample.
    586  * A sample represents one of the primary colors in a color model. The RGB
    587  * color model uses red, green, and blue samples respectively. Suppose you
    588  * wanted to use 16-bit RGB color: You would have three samples per pixel (one
    589  * for each primary color), five bits per sample (the quotient of 16 RGB bits
    590  * divided by three samples), and two bytes per pixel (the smallest multiple of
    591  * eight bits in which the 16-bit pixel will fit). If you wanted 32-bit RGB
    592  * color, you would have three samples per pixel again, eight bits per sample
    593  * (since that's how 32-bit color is defined), and four bytes per pixel (the
    594  * smallest multiple of eight bits in which the 32-bit pixel will fit.
    595  * @param bitsPerSample The number of bits in a sample
    596  * @param samplesPerPixel The number of samples in a pixel
    597  * @param bytesPerPixel The number of bytes in a pixel
    598  * @return a pointer to the allocated rfbClient structure
    599  */
    600 rfbClient* rfbGetClient(int bitsPerSample,int samplesPerPixel,int bytesPerPixel);
    601 /**
    602  * Initializes the client. The format is {PROGRAM_NAME, [OPTIONS]..., HOST}. This
    603  * function does not initialize the program name if the rfbClient's program
    604  * name is set already. The options are as follows:
    605  * <table>
    606  * <tr><th>Option</th><th>Description</th></tr>
    607  * <tr><td>-listen</td><td>Listen for incoming connections.</td></tr>
    608  * <tr><td>-listennofork</td><td>Listen for incoming connections without forking.
    609  * </td></tr>
    610  * <tr><td>-play</td><td>Set this client to replay a previously recorded session.</td></tr>
    611  * <tr><td>-encodings</td><td>Set the encodings to use. The next item in the
    612  * argv array is the encodings string, consisting of comma separated encodings like 'tight,ultra,raw'.</td></tr>
    613  * <tr><td>-compress</td><td>Set the compression level. The next item in the
    614  * argv array is the compression level as an integer. Ranges from 0 (lowest) to 9 (highest).
    615  * </td></tr>
    616  * <tr><td>-scale</td><td>Set the scaling level. The next item in the
    617  * argv array is the scaling level as an integer. The screen will be scaled down by this factor.</td></tr>
    618  * <tr><td>-qosdscp</td><td>Set the Quality of Service Differentiated Services
    619  * Code Point (QoS DSCP). The next item in the argv array is the code point as
    620  * an integer.</td></tr>
    621  * <tr><td>-repeaterdest</td><td>Set a VNC repeater address. The next item in the argv array is
    622  * the repeater's address as a string.</td></tr>
    623  * </table>
    624  *
    625  * The host may include a port number (delimited by a ':').
    626  * @param client The client to initialize
    627  * @param argc The number of arguments to the initializer
    628  * @param argv The arguments to the initializer as an array of NULL terminated
    629  * strings
    630  * @return true if the client was initialized successfully, false otherwise.
    631  */
    632 rfbBool rfbInitClient(rfbClient* client,int* argc,char** argv);
    633 /**
    634  * Cleans up the client structure and releases the memory allocated for it. You
    635  * should call this when you're done with the rfbClient structure that you
    636  * allocated with rfbGetClient().
    637  * @note rfbClientCleanup() does not touch client->frameBuffer.
    638  * @param client The client to clean up
    639  */
    640 void rfbClientCleanup(rfbClient* client);
    641 
    642 #if(defined __cplusplus)
    643 }
    644 #endif
    645 
    646 /**
    647  * @}
    648  */
    649 
    650 /**
    651  @page libvncclient_doc LibVNCClient Documentation
    652  @section example_code Example Code
    653  See SDLvncviewer.c for a rather complete client example.
    654 */
    655 
    656 #endif
    657