#include #include #include #include #include #include #include #include #include #include #include #include "vnc.h" /* ------------------------------------------------------------------ */ static const char *progname; static void usage(FILE *fp) { fprintf(fp, "This is a simple vnc client\n" "\n" "usage: %s [options] display\n" "options:\n" " -h Print this text.\n" " -d Enable debug output.\n" " -p Show mouse pointer.\n" " -f Start in fullscreen mode.\n" " -c Close on disconnect.\n" " -u Set username.\n" " -s Set password.\n" "\n" "-- \n" "(c) 2006 Gerd Hoffmann \n", progname); } int main(int argc, char *argv[]) { unsigned long vnc_flags = VNC_FLAG_STANDALONE; char hostname[65], *username = NULL, *password = NULL; int port; int debug = 0; int c; progname = strrchr(argv[0], '/'); if (progname == NULL) progname = argv[0]; else ++progname; gtk_init(&argc, &argv); while ((c = getopt(argc, argv, "hdpfcu:s:")) != -1) { switch (c) { case 'd': debug++; break; case 'p': vnc_flags |= VNC_FLAG_SHOW_MOUSE; break; case 'f': vnc_flags |= VNC_FLAG_FULLSCREEN; break; case 'c': vnc_flags |= VNC_FLAG_DISCONNECT_CLOSE; break; case 'u': username = optarg; break; case 's': password = optarg; break; case 'h': usage(stdout); exit(0); case '?': fprintf(stderr, "Try `%s -h' for more information.\n", progname); exit(1); default: fprintf(stderr, "%s: getopt returned %d?\n", progname, c); exit(1); } } if (optind == argc) { *hostname = '\0'; port = 5901; } else if (optind == argc - 1) { char *arg = argv[optind]; int n, displayno; if (2 == sscanf(arg, "%64[^:]:%d%n", hostname, &displayno, &n)) port = displayno + 5900; else if (2 == sscanf(arg, "%64[^:]::%d%n", hostname, &port, &n)) ; else { fprintf(stderr, "%s: malformed display name '%s'\n", progname, arg); exit(1); } if (arg[n] != '\0') { fprintf(stderr, "%s: malformed display name '%s'\n", progname, arg); exit(1); } } else { fprintf(stderr, "%s: wrong number of arguments.\n", progname); fprintf(stderr, "Try `%s -h' for more information.\n", progname); exit(1); } if (debug) printf("Connecting to host '%s' port %d\n", hostname, port); if (NULL == vnc_open(strlen(hostname) ? hostname : NULL, port, vnc_flags, debug, username, password)) exit(1); if (password) { while (*password) { *(password++) = '*'; } } gtk_main(); exit(0); }