[gtk-vnc] gvncviewer.py: add support for UNIX domain sockets
- From: Daniel P. Berrange <dberrange src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk-vnc] gvncviewer.py: add support for UNIX domain sockets
- Date: Tue, 8 Dec 2020 14:30:14 +0000 (UTC)
commit 034edd02ed8f7e1c5ac5689f3ee9cb098c2eccc0
Author: Dr. Matthias St. Pierre <matthias st pierre ncp-e com>
Date: Thu Oct 22 17:54:49 2020 +0200
gvncviewer.py: add support for UNIX domain sockets
In addition to specifying a <host> name (and optional <display> number)
gvncviewer.py <host>[:<display>] [password]
it is now also possible to specify the <path> of a UNIX domain socket:
gvncviewer.py unix:<path> [password]
The syntax is inspired by QEMU's `-vnc unix:<path>` argument.
examples/gvncviewer.py | 39 +++++++++++++++++++++++++++++++--------
1 file changed, 31 insertions(+), 8 deletions(-)
---
diff --git a/examples/gvncviewer.py b/examples/gvncviewer.py
index a82b0cf..b9cd47d 100755
--- a/examples/gvncviewer.py
+++ b/examples/gvncviewer.py
@@ -28,8 +28,18 @@ from gi.repository import Gdk
from gi.repository import GtkVnc
import sys
+usage = """
+usage: gvncviewer.py <host>[:<display>] [password]
+ gvncviewer.py unix:<path> [password]
+
+Connect to the given <host> and <display>. If the <display> is omitted,
+it defaults to 0.
+
+Alternatively, a unix domain socket can be specified using unix:<path>.
+"""
+
if len(sys.argv) != 2 and len(sys.argv) != 3:
- print("syntax: gvncviewer.py host:display [password]")
+ print(usage)
sys.exit(1)
def set_title(vnc, window, grabbed):
@@ -198,16 +208,29 @@ vnc.set_grab_keys(grab_keys)
if len(sys.argv) == 3:
vnc.set_credential(GtkVnc.DisplayCredential.PASSWORD, sys.argv[2])
-disp = sys.argv[1].find(":")
-if disp != -1:
- host = sys.argv[1][:disp]
- port = str(5900 + int(sys.argv[1][disp+1:]))
+target = sys.argv[1]
+
+if ":" in target:
+ host, target = target.split(":", 1)
+
+ if host == 'unix':
+ path = target # path of the domain socket
+ else:
+ port = str(5900 + int(target)) # port number of the display
else:
- host = sys.argv[1]
+ host = target
port = "5900"
-print("Connecting to %s %s" % (host, port))
-vnc.open_host(host, port)
+if host == "unix":
+ import socket
+ domain_socket = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM, 0)
+ print("Connecting to domain socket", path)
+ domain_socket.connect(path)
+ vnc.open_fd(domain_socket.fileno())
+else:
+ print("Connecting to %s:%s" % (host, port))
+ vnc.open_host(host, port)
+
vnc.connect("vnc-pointer-grab", vnc_grab, window)
vnc.connect("vnc-pointer-ungrab", vnc_ungrab, window)
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]