~ari-tczew/ubuntu/utopic/gtk-vnc/merge

« back to all changes in this revision

Viewing changes to debian/patches/Allow-Unix-domain-sockets-in-gvncviewer.patch

  • Committer: Package Import Robot
  • Author(s): Laurent Léonard
  • Date: 2012-07-24 00:49:55 UTC
  • mfrom: (1.2.5)
  • Revision ID: package-import@ubuntu.com-20120724004955-6711f7ontxvn9yzy
Tags: 0.5.1-1
* [e2591bf] Imported Upstream version 0.5.1
* [a0f6408] Drop patch
  - Allow-Unix-domain-sockets-in-gvncviewer.patch - fixed upstream
* [c031b94] Bump Standards-Version to 3.9.3
* [61e5796] Set build directories for dh_auto_clean
* [7fde78d] Drop patch
  - Look-for-generated-enums-in-srcdir.patch
* [fada5be] Add dh_auto_test override
* [d7567f1] Update symbols
* [6189676] Enable dpkg-buildflags

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
From: Daniel Kahn Gillmor <dkg@fifthhorseman.net>
2
 
Date: Sat, 28 Jan 2012 20:14:32 +0100
3
 
Subject: Allow Unix domain sockets in gvncviewer
4
 
 
5
 
gvncviewer is useful when connecting to unix domain sockets.
6
 
---
7
 
 examples/gvncviewer.c |   48 +++++++++++++++++++++++++++++++++++++-----------
8
 
 1 files changed, 37 insertions(+), 11 deletions(-)
9
 
 
10
 
diff --git a/examples/gvncviewer.c b/examples/gvncviewer.c
11
 
index 6d47d71..6730b33 100644
12
 
--- a/examples/gvncviewer.c
13
 
+++ b/examples/gvncviewer.c
14
 
@@ -30,6 +30,11 @@
15
 
 #include <stdlib.h>
16
 
 #include <string.h>
17
 
 #include <glib.h>
18
 
+#include <sys/types.h>
19
 
+#include <sys/stat.h>
20
 
+#include <unistd.h>
21
 
+#include <sys/socket.h>
22
 
+#include <sys/un.h>
23
 
 
24
 
 #if WITH_LIBVIEW
25
 
 #include <libview/autoDrawer.h>
26
 
@@ -586,6 +591,8 @@ int main(int argc, char **argv)
27
 
     GtkWidget *scaling;
28
 
     GtkWidget *showgrabkeydlg;
29
 
     const char *help_msg = "Run 'gvncviewer --help' to see a full list of available command line options";
30
 
+    struct stat sockstat;
31
 
+    int sock;
32
 
 
33
 
     name = g_strdup_printf("- Simple VNC Client on Gtk-VNC %s",
34
 
                            vnc_util_get_version_string());
35
 
@@ -688,17 +695,36 @@ int main(int argc, char **argv)
36
 
     gtk_widget_realize(vnc);
37
 
 
38
 
     snprintf(hostname, sizeof(hostname), "%s", args[0]);
39
 
-    display = strchr(hostname, ':');
40
 
-
41
 
-    if (display) {
42
 
-        *display = 0;
43
 
-        snprintf(port, sizeof(port), "%d", 5900 + atoi(display + 1));
44
 
-    } else
45
 
-        snprintf(port, sizeof(port), "%d", 5900);
46
 
-
47
 
-    if (!*hostname)
48
 
-        snprintf(hostname, sizeof(hostname), "%s", "127.0.0.1");
49
 
-    vnc_display_open_host(VNC_DISPLAY(vnc), hostname, port);
50
 
+    if ((0 == stat(hostname, &sockstat)) &&
51
 
+        S_ISSOCK(sockstat.st_mode)) {
52
 
+        size_t sockaddrsize = offsetof(struct sockaddr_un, sun_path) + strlen(hostname) + 1;
53
 
+        struct sockaddr_un* addr = malloc(sockaddrsize);
54
 
+        
55
 
+        /* the argument refers to a unix domain socket */
56
 
+        sock = socket(AF_UNIX, SOCK_STREAM, 0);
57
 
+        addr->sun_family = AF_UNIX;
58
 
+        strcpy(addr->sun_path, hostname);
59
 
+        if (0 == connect(sock, (const struct sockaddr *)addr, sockaddrsize)) {
60
 
+            vnc_display_open_fd(VNC_DISPLAY(vnc), sock);
61
 
+        } else {
62
 
+            fprintf(stderr, "Failed to open unix domain socket %s\n", hostname);
63
 
+            return 1;
64
 
+        }
65
 
+        free(addr);
66
 
+    } else {
67
 
+        /* treat it as a regular hostname */
68
 
+        display = strchr(hostname, ':');
69
 
+
70
 
+        if (display) {
71
 
+            *display = 0;
72
 
+            snprintf(port, sizeof(port), "%d", 5900 + atoi(display + 1));
73
 
+        } else
74
 
+            snprintf(port, sizeof(port), "%d", 5900);
75
 
+
76
 
+        if (!*hostname)
77
 
+            snprintf(hostname, sizeof(hostname), "%s", "127.0.0.1");
78
 
+        vnc_display_open_host(VNC_DISPLAY(vnc), hostname, port);
79
 
+    }
80
 
     vnc_display_set_keyboard_grab(VNC_DISPLAY(vnc), TRUE);
81
 
     vnc_display_set_pointer_grab(VNC_DISPLAY(vnc), TRUE);
82