From c0e012e4d26f2bc38ee5d34c3ee75e94cc799767 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 29 Mar 2014 14:53:24 -0500 Subject: [PATCH 1/6] Add an example how to connect to an UltraVNC-style repeater UltraVNC offers an add-on to connect clients and servers via IDs with a so-called repeater (e.g. to bridge firewalled clients and servers): http://www.uvnc.com/products/uvnc-repeater.html This example demonstrates how to use that feature with a LibVNCServer-based server. Signed-off-by: Johannes Schindelin --- .gitignore | 1 + examples/Makefile.am | 2 +- examples/repeater.c | 62 ++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 1 deletion(-) create mode 100644 examples/repeater.c diff --git a/.gitignore b/.gitignore index 083b816..c675991 100644 --- a/.gitignore +++ b/.gitignore @@ -51,6 +51,7 @@ examples/fontsel examples/pnmshow examples/pnmshow24 examples/regiontest +examples/repeater examples/rotate examples/simple examples/simple15 diff --git a/examples/Makefile.am b/examples/Makefile.am index 29d3774..6a7d656 100644 --- a/examples/Makefile.am +++ b/examples/Makefile.am @@ -23,5 +23,5 @@ noinst_HEADERS=radon.h rotatetemplate.c noinst_PROGRAMS=example pnmshow regiontest pnmshow24 fontsel \ vncev storepasswd colourmaptest simple simple15 $(MAC) \ $(FILETRANSFER) backchannel $(BLOOPTEST) camera rotate \ - zippy + zippy repeater diff --git a/examples/repeater.c b/examples/repeater.c new file mode 100644 index 0000000..ae65e25 --- /dev/null +++ b/examples/repeater.c @@ -0,0 +1,62 @@ +/* This example shows how to connect to an UltraVNC repeater. */ + +#include + +int main(int argc,char** argv) +{ + char *repeaterHost; + int repeaterPort, sock; + char id[250]; + rfbClientPtr cl; + + int i,j; + uint16_t* f; + + /* Parse command-line arguments */ + if (argc < 3) { + fprintf(stderr, + "Usage: %s []\n", argv[0]); + exit(1); + } + snprintf(id, sizeof(id) - 1, "ID:%s", argv[1]); + repeaterHost = argv[2]; + repeaterPort = argc < 4 ? 5500 : atoi(argv[3]); + + /* The initialization is identical to simple15.c */ + rfbScreenInfoPtr server=rfbGetScreen(&argc,argv,400,300,5,3,2); + if(!server) + return 0; + server->frameBuffer=(char*)malloc(400*300*2); + f=(uint16_t*)server->frameBuffer; + for(j=0;j<300;j++) + for(i=0;i<400;i++) + f[j*400+i]=/* red */ ((j*32/300) << 10) | + /* green */ (((j+400-i)*32/700) << 5) | + /* blue */ ((i*32/400)); + + /* Now for the repeater-specific part: */ + server->port = -1; /* do not listen on any port */ + server->ipv6port = -1; /* do not listen on any port */ + + sock = rfbConnectToTcpAddr(repeaterHost, repeaterPort); + if (sock < 0) { + perror("connect to repeater"); + return 1; + } + if (write(sock, id, sizeof(id)) != sizeof(id)) { + perror("writing id"); + return 1; + } + cl = rfbNewClient(server, sock); + if (!cl) { + perror("new client"); + return 1; + } + cl->reverseConnection = 0; + + /* Run the server */ + rfbInitServer(server); + rfbRunEventLoop(server,-1,FALSE); + + return 0; +} From 71d0f9b06fd3f574d79dcf9593fb8b6299c6143d Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 29 Mar 2014 15:03:12 -0500 Subject: [PATCH 2/6] Repeater example: show how to shut down cleanly Since we connected to the client through the repeater, chances are that we want this server shut down once the client disconnected. Signed-off-by: Johannes Schindelin --- examples/repeater.c | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/examples/repeater.c b/examples/repeater.c index ae65e25..cf0350f 100644 --- a/examples/repeater.c +++ b/examples/repeater.c @@ -2,6 +2,11 @@ #include +static void clientGone(rfbClientPtr cl) +{ + rfbShutdownServer(cl->screen, TRUE); +} + int main(int argc,char** argv) { char *repeaterHost; @@ -53,6 +58,7 @@ int main(int argc,char** argv) return 1; } cl->reverseConnection = 0; + cl->clientGoneHook = clientGone; /* Run the server */ rfbInitServer(server); From 186da4f10e2d399fdd73c390b36298d45af7816b Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 5 Apr 2014 09:52:24 -0500 Subject: [PATCH 3/6] Ignore rfbproto.rst A more up-to-date version of the RFB protocol is maintained by TigerVNC: http://sourceforge.net/p/tigervnc/code/HEAD/tree/rfbproto/rfbproto.rst Signed-off-by: Johannes Schindelin --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index c675991..deaceb5 100644 --- a/.gitignore +++ b/.gitignore @@ -74,3 +74,4 @@ x11vnc/x11vnc CMakeCache.txt cmake_install.cmake /CMakeFiles +/rfbproto.rst From 8d558daf05ef4385733f2892c7f9f73b5136d7d5 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 5 Apr 2014 16:24:21 -0500 Subject: [PATCH 4/6] Ignore the vencrypt document https://www.berrange.com/~dan/vencrypt.txt Signed-off-by: Johannes Schindelin --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index deaceb5..50638f2 100644 --- a/.gitignore +++ b/.gitignore @@ -75,3 +75,4 @@ CMakeCache.txt cmake_install.cmake /CMakeFiles /rfbproto.rst +/vencrypt.txt From 0e19b7c5096140d149f78ddda7c0317593164f35 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 5 Apr 2014 16:41:57 -0500 Subject: [PATCH 5/6] Ignore the 'mac' example, too Signed-off-by: Johannes Schindelin --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 50638f2..7c6b624 100644 --- a/.gitignore +++ b/.gitignore @@ -48,6 +48,7 @@ examples/colourmaptest examples/example examples/filetransfer examples/fontsel +examples/mac examples/pnmshow examples/pnmshow24 examples/regiontest From a705cd625cd4ae61ba05cb8333a46662429ca6a1 Mon Sep 17 00:00:00 2001 From: Johannes Schindelin Date: Sat, 5 Apr 2014 16:36:02 -0500 Subject: [PATCH 6/6] libvncclient: If we have TLS support, enable VeNCrypt by default Signed-off-by: Johannes Schindelin --- libvncclient/rfbproto.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/libvncclient/rfbproto.c b/libvncclient/rfbproto.c index 958780c..f5185ca 100644 --- a/libvncclient/rfbproto.c +++ b/libvncclient/rfbproto.c @@ -578,6 +578,9 @@ ReadSupportedSecurityType(rfbClient* client, uint32_t *result, rfbBool subAuth) rfbClientLog("%d) Received security type %d\n", loop, tAuth[loop]); if (flag) continue; if (tAuth[loop]==rfbVncAuth || tAuth[loop]==rfbNoAuth || +#if defined(LIBVNCSERVER_HAVE_GNUTLS) || defined(LIBVNCSERVER_HAVE_LIBSSL) + tAuth[loop]==rfbVeNCrypt || +#endif (tAuth[loop]==rfbARD && client->GetCredential) || (!subAuth && (tAuth[loop]==rfbTLS || (tAuth[loop]==rfbVeNCrypt && client->GetCredential)))) {