aboutsummaryrefslogtreecommitdiffstats
path: root/vnc-client.c
diff options
context:
space:
mode:
Diffstat (limited to 'vnc-client.c')
-rw-r--r--vnc-client.c60
1 files changed, 44 insertions, 16 deletions
diff --git a/vnc-client.c b/vnc-client.c
index 6b777a6..d6db233 100644
--- a/vnc-client.c
+++ b/vnc-client.c
@@ -15,12 +15,14 @@
/* ------------------------------------------------------------------ */
+static const char *progname;
+
static void usage(FILE *fp)
{
fprintf(fp,
"This is a simple vnc client\n"
"\n"
- "usage: vnc-client [options] display\n"
+ "usage: %s [options] display\n"
"options:\n"
" -h Print this text.\n"
" -d Enable debug output.\n"
@@ -29,7 +31,8 @@ static void usage(FILE *fp)
" -c Close on disconnect.\n"
"\n"
"-- \n"
- "(c) 2006 Gerd Hoffmann <kraxel@redhat.com>\n");
+ "(c) 2006 Gerd Hoffmann <kraxel@redhat.com>\n",
+ progname);
}
int
@@ -37,14 +40,18 @@ main(int argc, char *argv[])
{
unsigned long vnc_flags = VNC_FLAG_STANDALONE;
char hostname[65];
- int displayno, port;
+ int port;
int debug = 0;
int c;
+ progname = strrchr(argv[0], '/');
+ if (progname == NULL)
+ progname = argv[0];
+ else
+ ++progname;
+
gtk_init(&argc, &argv);
- for (;;) {
- if (-1 == (c = getopt(argc, argv, "hdpfc")))
- break;
+ while ((c = getopt(argc, argv, "hdpfc")) != -1) {
switch (c) {
case 'd':
debug++;
@@ -61,24 +68,45 @@ main(int argc, char *argv[])
case 'h':
usage(stdout);
exit(0);
+ case '?':
+ fprintf(stderr, "Try `%s -h' for more information.\n", progname);
+ exit(1);
default:
- usage(stderr);
+ fprintf(stderr, "%s: getopt returned %d?\n", progname, c);
exit(1);
}
}
- if (optind < argc) {
- if (2 == sscanf(argv[optind], "%64[^:]:%d", hostname, &displayno)) {
+ 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;
- goto connect;
- }
- if (2 != sscanf(argv[optind], "%64[^:]::%d", hostname, &port)) {
- goto connect;
- }
+ 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);
+ }
}
- strcpy(hostname, "");
+ 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);
-connect:
if (NULL == vnc_open(strlen(hostname) ? hostname : NULL,
port, vnc_flags, debug))
exit(1);