Reimplement -listen in the new FLTK vncviewer. Work done by
Justina Mickonyte for Cendio.


git-svn-id: svn://svn.code.sf.net/p/tigervnc/code/trunk@5041 3789f03b-4d11-0410-bbf8-ca57d06f2519
diff --git a/vncviewer/vncviewer.cxx b/vncviewer/vncviewer.cxx
index 569ee4a..8e9622a 100644
--- a/vncviewer/vncviewer.cxx
+++ b/vncviewer/vncviewer.cxx
@@ -24,6 +24,7 @@
 
 #include <string.h>
 #include <stdio.h>
+#include <ctype.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <signal.h>
@@ -441,18 +442,39 @@
   CSecurityTLS::msg = &dlg;
 #endif
 
-  if (vncServerName[0] == '\0') {
-    ServerDialog::run(defaultServerName, vncServerName);
-    if (vncServerName[0] == '\0')
-      return 1;
-  }
+  Socket *sock = NULL;
+
+  if(listenMode) {
+    try {
+      int port = 5500;
+      if (isdigit(vncServerName[0]))
+        port = atoi(vncServerName);
+
+      TcpListener listener(NULL, port);
+
+      vlog.info("Listening on port %d\n", port);
+      sock = listener.accept();   
+    } catch (rdr::Exception& e) {
+      vlog.error("%s", e.str());
+      fl_alert("%s", e.str());
+      exit_vncviewer();
+      return 1; 
+    }
+
+  } else {
+    if (vncServerName[0] == '\0') {
+      ServerDialog::run(defaultServerName, vncServerName);
+      if (vncServerName[0] == '\0')
+        return 1;
+    }
 
 #ifndef WIN32
-  if (strlen (via.getValueStr()) > 0 && mktunnel() != 0)
-    usage(argv[0]);
+    if (strlen (via.getValueStr()) > 0 && mktunnel() != 0)
+      usage(argv[0]);
 #endif
+  }
 
-  CConn *cc = new CConn(vncServerName);
+  CConn *cc = new CConn(vncServerName, sock);
 
   while (!exitMainloop) {
     int next_timer;