You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

vncviewer.cxx 18KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686
  1. /* Copyright (C) 2002-2005 RealVNC Ltd. All Rights Reserved.
  2. * Copyright 2011 Pierre Ossman <ossman@cendio.se> for Cendio AB
  3. * Copyright (C) 2011 D. R. Commander. All Rights Reserved.
  4. *
  5. * This is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 2 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This software is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this software; if not, write to the Free Software
  17. * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,
  18. * USA.
  19. */
  20. #ifdef HAVE_CONFIG_H
  21. #include <config.h>
  22. #endif
  23. #include <string.h>
  24. #include <stdio.h>
  25. #include <ctype.h>
  26. #include <stdlib.h>
  27. #include <errno.h>
  28. #include <signal.h>
  29. #include <locale.h>
  30. #include <fcntl.h>
  31. #include <unistd.h>
  32. #include <sys/stat.h>
  33. #ifdef WIN32
  34. #include <os/winerrno.h>
  35. #include <direct.h>
  36. #define mkdir(path, mode) _mkdir(path)
  37. #endif
  38. #if !defined(WIN32) && !defined(__APPLE__)
  39. #include <X11/Xlib.h>
  40. #include <X11/XKBlib.h>
  41. #endif
  42. #include <rfb/Logger_stdio.h>
  43. #include <rfb/SecurityClient.h>
  44. #include <rfb/Security.h>
  45. #ifdef HAVE_GNUTLS
  46. #include <rfb/CSecurityTLS.h>
  47. #endif
  48. #include <rfb/LogWriter.h>
  49. #include <rfb/Timer.h>
  50. #include <rfb/Exception.h>
  51. #include <network/TcpSocket.h>
  52. #include <os/os.h>
  53. #include <FL/Fl.H>
  54. #include <FL/Fl_Widget.H>
  55. #include <FL/Fl_PNG_Image.H>
  56. #include <FL/Fl_Sys_Menu_Bar.H>
  57. #include <FL/fl_ask.H>
  58. #include <FL/x.H>
  59. #include "i18n.h"
  60. #include "parameters.h"
  61. #include "CConn.h"
  62. #include "ServerDialog.h"
  63. #include "UserDialog.h"
  64. #include "vncviewer.h"
  65. #include "fltk_layout.h"
  66. #ifdef WIN32
  67. #include "resource.h"
  68. #include "win32.h"
  69. #endif
  70. rfb::LogWriter vlog("main");
  71. using namespace network;
  72. using namespace rfb;
  73. using namespace std;
  74. char vncServerName[VNCSERVERNAMELEN] = { '\0' };
  75. static const char *argv0 = NULL;
  76. static bool exitMainloop = false;
  77. static const char *exitError = NULL;
  78. static const char *about_text()
  79. {
  80. static char buffer[1024];
  81. // This is used in multiple places with potentially different
  82. // encodings, so we need to make sure we get a fresh string every
  83. // time.
  84. snprintf(buffer, sizeof(buffer),
  85. _("TigerVNC Viewer %d-bit v%s\n"
  86. "Built on: %s\n"
  87. "Copyright (C) 1999-%d TigerVNC Team and many others (see README.rst)\n"
  88. "See https://www.tigervnc.org for information on TigerVNC."),
  89. (int)sizeof(size_t)*8, PACKAGE_VERSION,
  90. BUILD_TIMESTAMP, 2020);
  91. return buffer;
  92. }
  93. void exit_vncviewer(const char *error)
  94. {
  95. // Prioritise the first error we get as that is probably the most
  96. // relevant one.
  97. if ((error != NULL) && (exitError == NULL))
  98. exitError = strdup(error);
  99. exitMainloop = true;
  100. }
  101. bool should_exit()
  102. {
  103. return exitMainloop;
  104. }
  105. void about_vncviewer()
  106. {
  107. fl_message_title(_("About TigerVNC Viewer"));
  108. fl_message("%s", about_text());
  109. }
  110. void run_mainloop()
  111. {
  112. int next_timer;
  113. next_timer = Timer::checkTimeouts();
  114. if (next_timer == 0)
  115. next_timer = INT_MAX;
  116. if (Fl::wait((double)next_timer / 1000.0) < 0.0) {
  117. vlog.error(_("Internal FLTK error. Exiting."));
  118. exit(-1);
  119. }
  120. }
  121. #ifdef __APPLE__
  122. static void about_callback(Fl_Widget *widget, void *data)
  123. {
  124. about_vncviewer();
  125. }
  126. static void new_connection_cb(Fl_Widget *widget, void *data)
  127. {
  128. const char *argv[2];
  129. pid_t pid;
  130. pid = fork();
  131. if (pid == -1) {
  132. vlog.error(_("Error starting new TigerVNC Viewer: %s"), strerror(errno));
  133. return;
  134. }
  135. if (pid != 0)
  136. return;
  137. argv[0] = argv0;
  138. argv[1] = NULL;
  139. execvp(argv[0], (char * const *)argv);
  140. vlog.error(_("Error starting new TigerVNC Viewer: %s"), strerror(errno));
  141. _exit(1);
  142. }
  143. #endif
  144. static void CleanupSignalHandler(int sig)
  145. {
  146. // CleanupSignalHandler allows C++ object cleanup to happen because it calls
  147. // exit() rather than the default which is to abort.
  148. vlog.info(_("Termination signal %d has been received. TigerVNC Viewer will now exit."), sig);
  149. exit(1);
  150. }
  151. static void init_fltk()
  152. {
  153. // Basic text size (10pt @ 96 dpi => 13px)
  154. FL_NORMAL_SIZE = 13;
  155. // Select a FLTK scheme and background color that looks somewhat
  156. // close to modern systems
  157. Fl::scheme("gtk+");
  158. Fl::background(220, 220, 220);
  159. // macOS has a slightly brighter default background though
  160. #ifdef __APPLE__
  161. Fl::background(240, 240, 240);
  162. #endif
  163. // Proper Gnome Shell integration requires that we set a sensible
  164. // WM_CLASS for the window.
  165. Fl_Window::default_xclass("vncviewer");
  166. // Set the default icon for all windows.
  167. #ifdef WIN32
  168. HICON lg, sm;
  169. lg = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON),
  170. IMAGE_ICON, GetSystemMetrics(SM_CXICON),
  171. GetSystemMetrics(SM_CYICON),
  172. LR_DEFAULTCOLOR | LR_SHARED);
  173. sm = (HICON)LoadImage(GetModuleHandle(NULL), MAKEINTRESOURCE(IDI_ICON),
  174. IMAGE_ICON, GetSystemMetrics(SM_CXSMICON),
  175. GetSystemMetrics(SM_CYSMICON),
  176. LR_DEFAULTCOLOR | LR_SHARED);
  177. Fl_Window::default_icons(lg, sm);
  178. #elif ! defined(__APPLE__)
  179. const int icon_sizes[] = {48, 32, 24, 16};
  180. Fl_PNG_Image *icons[4];
  181. int count;
  182. count = 0;
  183. // FIXME: Follow icon theme specification
  184. for (size_t i = 0;i < sizeof(icon_sizes)/sizeof(icon_sizes[0]);i++) {
  185. char icon_path[PATH_MAX];
  186. bool exists;
  187. sprintf(icon_path, "%s/icons/hicolor/%dx%d/apps/tigervnc.png",
  188. DATA_DIR, icon_sizes[i], icon_sizes[i]);
  189. #ifndef WIN32
  190. struct stat st;
  191. if (stat(icon_path, &st) != 0)
  192. #else
  193. struct _stat st;
  194. if (_stat(icon_path, &st) != 0)
  195. return(false);
  196. #endif
  197. exists = false;
  198. else
  199. exists = true;
  200. if (exists) {
  201. icons[count] = new Fl_PNG_Image(icon_path);
  202. if (icons[count]->w() == 0 ||
  203. icons[count]->h() == 0 ||
  204. icons[count]->d() != 4) {
  205. delete icons[count];
  206. continue;
  207. }
  208. count++;
  209. }
  210. }
  211. Fl_Window::default_icons((const Fl_RGB_Image**)icons, count);
  212. for (int i = 0;i < count;i++)
  213. delete icons[i];
  214. #endif
  215. // This makes the "icon" in dialogs rounded, which fits better
  216. // with the above schemes.
  217. fl_message_icon()->box(FL_UP_BOX);
  218. // Turn off the annoying behaviour where popups track the mouse.
  219. fl_message_hotspot(false);
  220. // Avoid empty titles for popups
  221. fl_message_title_default(_("TigerVNC Viewer"));
  222. #ifdef WIN32
  223. // Most "normal" Windows apps use this font for UI elements.
  224. Fl::set_font(FL_HELVETICA, "Tahoma");
  225. #endif
  226. // FLTK exposes these so that we can translate them.
  227. fl_no = _("No");
  228. fl_yes = _("Yes");
  229. fl_ok = _("OK");
  230. fl_cancel = _("Cancel");
  231. fl_close = _("Close");
  232. #ifdef __APPLE__
  233. /* Needs trailing space */
  234. static char fltk_about[16];
  235. snprintf(fltk_about, sizeof(fltk_about), "%s ", _("About"));
  236. Fl_Mac_App_Menu::about = fltk_about;
  237. static char fltk_hide[16];
  238. snprintf(fltk_hide, sizeof(fltk_hide), "%s ", _("Hide"));
  239. Fl_Mac_App_Menu::hide = fltk_hide;
  240. static char fltk_quit[16];
  241. snprintf(fltk_quit, sizeof(fltk_quit), "%s ", _("Quit"));
  242. Fl_Mac_App_Menu::quit = fltk_quit;
  243. Fl_Mac_App_Menu::print = ""; // Don't want the print item
  244. Fl_Mac_App_Menu::services = _("Services");
  245. Fl_Mac_App_Menu::hide_others = _("Hide Others");
  246. Fl_Mac_App_Menu::show = _("Show All");
  247. fl_mac_set_about(about_callback, NULL);
  248. Fl_Sys_Menu_Bar *menubar;
  249. char buffer[1024];
  250. menubar = new Fl_Sys_Menu_Bar(0, 0, 500, 25);
  251. // Fl_Sys_Menu_Bar overrides methods without them being virtual,
  252. // which means we cannot use our generic Fl_Menu_ helpers.
  253. if (fltk_menu_escape(p_("SysMenu|", "&File"),
  254. buffer, sizeof(buffer)) < sizeof(buffer))
  255. menubar->add(buffer, 0, 0, 0, FL_SUBMENU);
  256. if (fltk_menu_escape(p_("SysMenu|File|", "&New Connection"),
  257. buffer, sizeof(buffer)) < sizeof(buffer))
  258. menubar->insert(1, buffer, FL_COMMAND | 'n', new_connection_cb);
  259. #endif
  260. }
  261. static void mkvnchomedir()
  262. {
  263. // Create .vnc in the user's home directory if it doesn't already exist
  264. char* homeDir = NULL;
  265. if (getvnchomedir(&homeDir) == -1) {
  266. vlog.error(_("Could not create VNC home directory: can't obtain home "
  267. "directory path."));
  268. } else {
  269. int result = mkdir(homeDir, 0755);
  270. if (result == -1 && errno != EEXIST)
  271. vlog.error(_("Could not create VNC home directory: %s."), strerror(errno));
  272. delete [] homeDir;
  273. }
  274. }
  275. static void usage(const char *programName)
  276. {
  277. #ifdef WIN32
  278. // If we don't have a console then we need to create one for output
  279. if (GetConsoleWindow() == NULL) {
  280. HANDLE handle;
  281. int fd;
  282. AllocConsole();
  283. handle = GetStdHandle(STD_ERROR_HANDLE);
  284. fd = _open_osfhandle((intptr_t)handle, O_TEXT);
  285. *stderr = *fdopen(fd, "w");
  286. }
  287. #endif
  288. fprintf(stderr,
  289. "\n"
  290. "usage: %s [parameters] [host][:displayNum]\n"
  291. " %s [parameters] [host][::port]\n"
  292. #ifndef WIN32
  293. " %s [parameters] [unix socket]\n"
  294. #endif
  295. " %s [parameters] -listen [port]\n"
  296. " %s [parameters] [.tigervnc file]\n",
  297. programName, programName,
  298. #ifndef WIN32
  299. programName,
  300. #endif
  301. programName, programName);
  302. #if !defined(WIN32) && !defined(__APPLE__)
  303. fprintf(stderr,"\n"
  304. "Options:\n\n"
  305. " -display Xdisplay - Specifies the X display for the viewer window\n"
  306. " -geometry geometry - Initial position of the main VNC viewer window. See the\n"
  307. " man page for details.\n");
  308. #endif
  309. fprintf(stderr,"\n"
  310. "Parameters can be turned on with -<param> or off with -<param>=0\n"
  311. "Parameters which take a value can be specified as "
  312. "-<param> <value>\n"
  313. "Other valid forms are <param>=<value> -<param>=<value> "
  314. "--<param>=<value>\n"
  315. "Parameter names are case-insensitive. The parameters are:\n\n");
  316. Configuration::listParams(79, 14);
  317. #ifdef WIN32
  318. // Just wait for the user to kill the console window
  319. Sleep(INFINITE);
  320. #endif
  321. exit(1);
  322. }
  323. static void
  324. potentiallyLoadConfigurationFile(char *vncServerName)
  325. {
  326. const bool hasPathSeparator = (strchr(vncServerName, '/') != NULL ||
  327. (strchr(vncServerName, '\\')) != NULL);
  328. if (hasPathSeparator) {
  329. #ifndef WIN32
  330. struct stat sb;
  331. // This might be a UNIX socket, we need to check
  332. if (stat(vncServerName, &sb) == -1) {
  333. // Some access problem; let loadViewerParameters() deal with it...
  334. } else {
  335. if ((sb.st_mode & S_IFMT) == S_IFSOCK)
  336. return;
  337. }
  338. #endif
  339. try {
  340. const char* newServerName;
  341. newServerName = loadViewerParameters(vncServerName);
  342. // This might be empty, but we still need to clear it so we
  343. // don't try to connect to the filename
  344. strncpy(vncServerName, newServerName, VNCSERVERNAMELEN-1);
  345. vncServerName[VNCSERVERNAMELEN-1] = '\0';
  346. } catch (rfb::Exception& e) {
  347. vlog.error("%s", e.str());
  348. if (alertOnFatalError)
  349. fl_alert("%s", e.str());
  350. exit(EXIT_FAILURE);
  351. }
  352. }
  353. }
  354. #ifndef WIN32
  355. static int
  356. interpretViaParam(char *remoteHost, int *remotePort, int localPort)
  357. {
  358. const int SERVER_PORT_OFFSET = 5900;
  359. char *pos = strchr(vncServerName, ':');
  360. if (pos == NULL)
  361. *remotePort = SERVER_PORT_OFFSET;
  362. else {
  363. int portOffset = SERVER_PORT_OFFSET;
  364. size_t len;
  365. *pos++ = '\0';
  366. len = strlen(pos);
  367. if (*pos == ':') {
  368. /* Two colons is an absolute port number, not an offset. */
  369. pos++;
  370. len--;
  371. portOffset = 0;
  372. }
  373. if (!len || strspn (pos, "-0123456789") != len )
  374. return 1;
  375. *remotePort = atoi(pos) + portOffset;
  376. }
  377. if (*vncServerName != '\0')
  378. strncpy(remoteHost, vncServerName, VNCSERVERNAMELEN);
  379. else
  380. strncpy(remoteHost, "localhost", VNCSERVERNAMELEN);
  381. remoteHost[VNCSERVERNAMELEN - 1] = '\0';
  382. snprintf(vncServerName, VNCSERVERNAMELEN, "localhost::%d", localPort);
  383. vncServerName[VNCSERVERNAMELEN - 1] = '\0';
  384. return 0;
  385. }
  386. static void
  387. createTunnel(const char *gatewayHost, const char *remoteHost,
  388. int remotePort, int localPort)
  389. {
  390. const char *cmd = getenv("VNC_VIA_CMD");
  391. char *cmd2, *percent;
  392. char lport[10], rport[10];
  393. sprintf(lport, "%d", localPort);
  394. sprintf(rport, "%d", remotePort);
  395. setenv("G", gatewayHost, 1);
  396. setenv("H", remoteHost, 1);
  397. setenv("R", rport, 1);
  398. setenv("L", lport, 1);
  399. if (!cmd)
  400. cmd = "/usr/bin/ssh -f -L \"$L\":\"$H\":\"$R\" \"$G\" sleep 20";
  401. /* Compatibility with TigerVNC's method. */
  402. cmd2 = strdup(cmd);
  403. while ((percent = strchr(cmd2, '%')) != NULL)
  404. *percent = '$';
  405. system(cmd2);
  406. free(cmd2);
  407. }
  408. static int mktunnel()
  409. {
  410. const char *gatewayHost;
  411. char remoteHost[VNCSERVERNAMELEN];
  412. int localPort = findFreeTcpPort();
  413. int remotePort;
  414. if (interpretViaParam(remoteHost, &remotePort, localPort) != 0)
  415. return 1;
  416. gatewayHost = (const char*)via;
  417. createTunnel(gatewayHost, remoteHost, remotePort, localPort);
  418. return 0;
  419. }
  420. #endif /* !WIN32 */
  421. int main(int argc, char** argv)
  422. {
  423. UserDialog dlg;
  424. argv0 = argv[0];
  425. setlocale(LC_ALL, "");
  426. bindtextdomain(PACKAGE_NAME, LOCALE_DIR);
  427. textdomain(PACKAGE_NAME);
  428. rfb::SecurityClient::setDefaults();
  429. // Write about text to console, still using normal locale codeset
  430. fprintf(stderr,"\n%s\n", about_text());
  431. // Set gettext codeset to what our GUI toolkit uses. Since we are
  432. // passing strings from strerror/gai_strerror to the GUI, these must
  433. // be in GUI codeset as well.
  434. bind_textdomain_codeset(PACKAGE_NAME, "UTF-8");
  435. bind_textdomain_codeset("libc", "UTF-8");
  436. rfb::initStdIOLoggers();
  437. #ifdef WIN32
  438. rfb::initFileLogger("C:\\temp\\vncviewer.log");
  439. #else
  440. rfb::initFileLogger("/tmp/vncviewer.log");
  441. #endif
  442. rfb::LogWriter::setLogParams("*:stderr:30");
  443. #ifdef SIGHUP
  444. signal(SIGHUP, CleanupSignalHandler);
  445. #endif
  446. signal(SIGINT, CleanupSignalHandler);
  447. signal(SIGTERM, CleanupSignalHandler);
  448. init_fltk();
  449. Configuration::enableViewerParams();
  450. /* Load the default parameter settings */
  451. char defaultServerName[VNCSERVERNAMELEN] = "";
  452. try {
  453. const char* configServerName;
  454. configServerName = loadViewerParameters(NULL);
  455. if (configServerName != NULL) {
  456. strncpy(defaultServerName, configServerName, VNCSERVERNAMELEN-1);
  457. defaultServerName[VNCSERVERNAMELEN-1] = '\0';
  458. }
  459. } catch (rfb::Exception& e) {
  460. vlog.error("%s", e.str());
  461. if (alertOnFatalError)
  462. fl_alert("%s", e.str());
  463. }
  464. for (int i = 1; i < argc;) {
  465. if (Configuration::setParam(argv[i])) {
  466. i++;
  467. continue;
  468. }
  469. if (argv[i][0] == '-') {
  470. if (i+1 < argc) {
  471. if (Configuration::setParam(&argv[i][1], argv[i+1])) {
  472. i += 2;
  473. continue;
  474. }
  475. }
  476. usage(argv[0]);
  477. }
  478. strncpy(vncServerName, argv[i], VNCSERVERNAMELEN);
  479. vncServerName[VNCSERVERNAMELEN - 1] = '\0';
  480. i++;
  481. }
  482. // Check if the server name in reality is a configuration file
  483. potentiallyLoadConfigurationFile(vncServerName);
  484. mkvnchomedir();
  485. #if !defined(WIN32) && !defined(__APPLE__)
  486. if (strcmp(display, "") != 0) {
  487. Fl::display(display);
  488. }
  489. fl_open_display();
  490. XkbSetDetectableAutoRepeat(fl_display, True, NULL);
  491. #endif
  492. CSecurity::upg = &dlg;
  493. #ifdef HAVE_GNUTLS
  494. CSecurityTLS::msg = &dlg;
  495. #endif
  496. Socket *sock = NULL;
  497. #ifndef WIN32
  498. /* Specifying -via and -listen together is nonsense */
  499. if (listenMode && strlen(via.getValueStr()) > 0) {
  500. // TRANSLATORS: "Parameters" are command line arguments, or settings
  501. // from a file or the Windows registry.
  502. vlog.error(_("Parameters -listen and -via are incompatible"));
  503. if (alertOnFatalError)
  504. fl_alert(_("Parameters -listen and -via are incompatible"));
  505. exit_vncviewer();
  506. return 1;
  507. }
  508. #endif
  509. if (listenMode) {
  510. std::list<SocketListener*> listeners;
  511. try {
  512. int port = 5500;
  513. if (isdigit(vncServerName[0]))
  514. port = atoi(vncServerName);
  515. createTcpListeners(&listeners, 0, port);
  516. vlog.info(_("Listening on port %d"), port);
  517. /* Wait for a connection */
  518. while (sock == NULL) {
  519. fd_set rfds;
  520. FD_ZERO(&rfds);
  521. for (std::list<SocketListener*>::iterator i = listeners.begin();
  522. i != listeners.end();
  523. i++)
  524. FD_SET((*i)->getFd(), &rfds);
  525. int n = select(FD_SETSIZE, &rfds, 0, 0, 0);
  526. if (n < 0) {
  527. if (errno == EINTR) {
  528. vlog.debug("Interrupted select() system call");
  529. continue;
  530. } else {
  531. throw rdr::SystemException("select", errno);
  532. }
  533. }
  534. for (std::list<SocketListener*>::iterator i = listeners.begin ();
  535. i != listeners.end();
  536. i++)
  537. if (FD_ISSET((*i)->getFd(), &rfds)) {
  538. sock = (*i)->accept();
  539. if (sock)
  540. /* Got a connection */
  541. break;
  542. }
  543. }
  544. } catch (rdr::Exception& e) {
  545. vlog.error("%s", e.str());
  546. if (alertOnFatalError)
  547. fl_alert("%s", e.str());
  548. exit_vncviewer();
  549. return 1;
  550. }
  551. while (!listeners.empty()) {
  552. delete listeners.back();
  553. listeners.pop_back();
  554. }
  555. } else {
  556. if (vncServerName[0] == '\0') {
  557. ServerDialog::run(defaultServerName, vncServerName);
  558. if (vncServerName[0] == '\0')
  559. return 1;
  560. }
  561. #ifndef WIN32
  562. if (strlen (via.getValueStr()) > 0 && mktunnel() != 0)
  563. usage(argv[0]);
  564. #endif
  565. }
  566. CConn *cc = new CConn(vncServerName, sock);
  567. while (!exitMainloop)
  568. run_mainloop();
  569. delete cc;
  570. if (exitError != NULL && alertOnFatalError)
  571. fl_alert("%s", exitError);
  572. return 0;
  573. }