~ubuntu-branches/ubuntu/vivid/gtk-vnc/vivid-proposed

« back to all changes in this revision

Viewing changes to examples/gvncviewer.c

  • Committer: Package Import Robot
  • Author(s): Guido Günther
  • Date: 2012-01-28 20:16:42 UTC
  • Revision ID: package-import@ubuntu.com-20120128201642-syuzp2g5w9ltvcu0
Tags: 0.5.0-3
* [0d2d0ae] Build-Conflict on valac-0.12.
  Thanks to Daniel Kahn Gillmor for the testing (Closes: #654849)
* [b12be0b] Allow Unix domain sockets in gvncviewer.
  Thanks to Daniel Kahn Gillmor for the patch (Closes: #655460)

Show diffs side-by-side

added added

removed removed

Lines of Context:
30
30
#include <stdlib.h>
31
31
#include <string.h>
32
32
#include <glib.h>
 
33
#include <sys/types.h>
 
34
#include <sys/stat.h>
 
35
#include <unistd.h>
 
36
#include <sys/socket.h>
 
37
#include <sys/un.h>
33
38
 
34
39
#if WITH_LIBVIEW
35
40
#include <libview/autoDrawer.h>
586
591
    GtkWidget *scaling;
587
592
    GtkWidget *showgrabkeydlg;
588
593
    const char *help_msg = "Run 'gvncviewer --help' to see a full list of available command line options";
 
594
    struct stat sockstat;
 
595
    int sock;
589
596
 
590
597
    name = g_strdup_printf("- Simple VNC Client on Gtk-VNC %s",
591
598
                           vnc_util_get_version_string());
688
695
    gtk_widget_realize(vnc);
689
696
 
690
697
    snprintf(hostname, sizeof(hostname), "%s", args[0]);
691
 
    display = strchr(hostname, ':');
692
 
 
693
 
    if (display) {
694
 
        *display = 0;
695
 
        snprintf(port, sizeof(port), "%d", 5900 + atoi(display + 1));
696
 
    } else
697
 
        snprintf(port, sizeof(port), "%d", 5900);
698
 
 
699
 
    if (!*hostname)
700
 
        snprintf(hostname, sizeof(hostname), "%s", "127.0.0.1");
701
 
    vnc_display_open_host(VNC_DISPLAY(vnc), hostname, port);
 
698
    if ((0 == stat(hostname, &sockstat)) &&
 
699
        S_ISSOCK(sockstat.st_mode)) {
 
700
        size_t sockaddrsize = offsetof(struct sockaddr_un, sun_path) + strlen(hostname) + 1;
 
701
        struct sockaddr_un* addr = malloc(sockaddrsize);
 
702
        
 
703
        /* the argument refers to a unix domain socket */
 
704
        sock = socket(AF_UNIX, SOCK_STREAM, 0);
 
705
        addr->sun_family = AF_UNIX;
 
706
        strcpy(addr->sun_path, hostname);
 
707
        if (0 == connect(sock, (const struct sockaddr *)addr, sockaddrsize)) {
 
708
            vnc_display_open_fd(VNC_DISPLAY(vnc), sock);
 
709
        } else {
 
710
            fprintf(stderr, "Failed to open unix domain socket %s\n", hostname);
 
711
            return 1;
 
712
        }
 
713
        free(addr);
 
714
    } else {
 
715
        /* treat it as a regular hostname */
 
716
        display = strchr(hostname, ':');
 
717
 
 
718
        if (display) {
 
719
            *display = 0;
 
720
            snprintf(port, sizeof(port), "%d", 5900 + atoi(display + 1));
 
721
        } else
 
722
            snprintf(port, sizeof(port), "%d", 5900);
 
723
 
 
724
        if (!*hostname)
 
725
            snprintf(hostname, sizeof(hostname), "%s", "127.0.0.1");
 
726
        vnc_display_open_host(VNC_DISPLAY(vnc), hostname, port);
 
727
    }
702
728
    vnc_display_set_keyboard_grab(VNC_DISPLAY(vnc), TRUE);
703
729
    vnc_display_set_pointer_grab(VNC_DISPLAY(vnc), TRUE);
704
730