From 157828ef180d47a03ce8b000db4e348b0067a9bc Mon Sep 17 00:00:00 2001 From: Michael Jumper Date: Thu, 19 Sep 2013 14:41:28 -0700 Subject: [PATCH] Implement listen mode (ticket #25). --- src/protocols/vnc/client.c | 28 ++++++++++++++++++++++++++++ src/protocols/vnc/client.h | 12 ++++++++++++ 2 files changed, 40 insertions(+) diff --git a/src/protocols/vnc/client.c b/src/protocols/vnc/client.c index 24c5fb12..5598198e 100644 --- a/src/protocols/vnc/client.c +++ b/src/protocols/vnc/client.c @@ -77,6 +77,8 @@ const char* GUAC_CLIENT_ARGS[] = { "audio-servername", #endif + "reverse-connect", + "listen-timeout", NULL }; @@ -102,6 +104,8 @@ enum VNC_ARGS_IDX { IDX_AUDIO_SERVERNAME, #endif + IDX_REVERSE_CONNECT, + IDX_LISTEN_TIMEOUT, VNC_ARGS_COUNT }; @@ -165,6 +169,20 @@ static rfbClient* __guac_vnc_get_client(guac_client* client) { } #endif + /* If reverse connection enabled, start listening */ + if (guac_client_data->reverse_connect) { + + guac_client_log_info(client, "Listening for connections on port %i", + guac_client_data->port); + + /* Listen for connection from server */ + rfb_client->listenPort = guac_client_data->port; + if (listenForIncomingConnectionsNoFork(rfb_client, + guac_client_data->listen_timeout*1000) <= 0) + return NULL; + + } + /* Connect */ if (rfbInitClient(rfb_client, NULL, NULL)) return rfb_client; @@ -239,6 +257,16 @@ int guac_client_init(guac_client* client, int argc, char** argv) { else retries_remaining = 0; + /* Set reverse-connection flag */ + guac_client_data->reverse_connect = + (strcmp(argv[IDX_REVERSE_CONNECT], "true") == 0); + + /* Parse listen timeout */ + if (argv[IDX_LISTEN_TIMEOUT][0] != '\0') + guac_client_data->listen_timeout = atoi(argv[IDX_LISTEN_TIMEOUT]); + else + guac_client_data->listen_timeout = 5000; + /* Attempt connection */ rfb_client = __guac_vnc_get_client(client); diff --git a/src/protocols/vnc/client.h b/src/protocols/vnc/client.h index a7e310f0..3752c0ef 100644 --- a/src/protocols/vnc/client.h +++ b/src/protocols/vnc/client.h @@ -134,6 +134,18 @@ typedef struct vnc_guac_client_data { */ int dest_port; + /** + * Whether not actually connecting to a VNC server, but rather listening + * for a connection from the VNC server (reverse connection). + */ + int reverse_connect; + + /** + * The maximum amount of time to wait when listening for connections, in + * milliseconds. + */ + int listen_timeout; + /** * Whether the cursor should be rendered on the server (remote) or on the * client (local).