]> Git Repo - qemu.git/blobdiff - vnc.c
Use correct types to enable > 2G support, based on a patch from
[qemu.git] / vnc.c
diff --git a/vnc.c b/vnc.c
index 64889de5a6ee4bd082d871c3053faf130dd06870..842124b056c221e5bf16174177b6ee6b29600551 100644 (file)
--- a/vnc.c
+++ b/vnc.c
@@ -633,8 +633,18 @@ static void buffer_append(Buffer *buffer, const void *data, size_t len)
 static int vnc_client_io_error(VncState *vs, int ret, int last_errno)
 {
     if (ret == 0 || ret == -1) {
-       if (ret == -1 && (last_errno == EINTR || last_errno == EAGAIN))
-           return 0;
+        if (ret == -1) {
+            switch (last_errno) {
+                case EINTR:
+                case EAGAIN:
+#ifdef _WIN32
+                case WSAEWOULDBLOCK:
+#endif
+                    return 0;
+                default:
+                    break;
+            }
+        }
 
        VNC_DEBUG("Closing down client sock %d %d\n", ret, ret < 0 ? last_errno : 0);
        qemu_set_fd_handler2(vs->csock, NULL, NULL, NULL, NULL);
@@ -879,8 +889,8 @@ static void pointer_event(VncState *vs, int button_mask, int x, int y)
        dz = 1;
 
     if (vs->absolute) {
-       kbd_mouse_event(x * 0x7FFF / vs->ds->width,
-                       y * 0x7FFF / vs->ds->height,
+       kbd_mouse_event(x * 0x7FFF / (vs->ds->width - 1),
+                       y * 0x7FFF / (vs->ds->height - 1),
                        dz, buttons);
     } else if (vs->has_pointer_type_change) {
        x -= 0x7FFF;
@@ -945,6 +955,7 @@ static void do_key_event(VncState *vs, int down, uint32_t sym)
             return;
         }
         break;
+    case 0x3a:                 /* CapsLock */
     case 0x45:                 /* NumLock */
         if (!down)
             vs->modifiers_state[keycode] ^= 1;
@@ -1898,6 +1909,22 @@ static int protocol_version(VncState *vs, uint8_t *version, size_t len)
     return 0;
 }
 
+static void vnc_connect(VncState *vs)
+{
+    VNC_DEBUG("New client on socket %d\n", vs->csock);
+    socket_set_nonblock(vs->csock);
+    qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, vs);
+    vnc_write(vs, "RFB 003.008\n", 12);
+    vnc_flush(vs);
+    vnc_read_when(vs, protocol_version, 12);
+    memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height);
+    memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
+    vs->has_resize = 0;
+    vs->has_hextile = 0;
+    vs->ds->dpy_copy = NULL;
+    vnc_update_client(vs);
+}
+
 static void vnc_listen_read(void *opaque)
 {
     VncState *vs = opaque;
@@ -1909,18 +1936,7 @@ static void vnc_listen_read(void *opaque)
 
     vs->csock = accept(vs->lsock, (struct sockaddr *)&addr, &addrlen);
     if (vs->csock != -1) {
-       VNC_DEBUG("New client on socket %d\n", vs->csock);
-        socket_set_nonblock(vs->csock);
-       qemu_set_fd_handler2(vs->csock, NULL, vnc_client_read, NULL, opaque);
-       vnc_write(vs, "RFB 003.008\n", 12);
-       vnc_flush(vs);
-       vnc_read_when(vs, protocol_version, 12);
-       memset(vs->old_data, 0, vs->ds->linesize * vs->ds->height);
-       memset(vs->dirty_row, 0xFF, sizeof(vs->dirty_row));
-       vs->has_resize = 0;
-       vs->has_hextile = 0;
-       vs->ds->dpy_copy = NULL;
-        vnc_update_client(vs);
+        vnc_connect(vs);
     }
 }
 
@@ -2080,13 +2096,14 @@ int vnc_display_open(DisplayState *ds, const char *display)
     struct sockaddr_in iaddr;
 #ifndef _WIN32
     struct sockaddr_un uaddr;
+    const char *p;
 #endif
     int reuse_addr, ret;
     socklen_t addrlen;
-    const char *p;
     VncState *vs = ds ? (VncState *)ds->opaque : vnc_state;
     const char *options;
     int password = 0;
+    int reverse = 0;
 #if CONFIG_VNC_TLS
     int tls = 0, x509 = 0;
 #endif
@@ -2103,6 +2120,8 @@ int vnc_display_open(DisplayState *ds, const char *display)
        options++;
        if (strncmp(options, "password", 8) == 0) {
            password = 1; /* Require password auth */
+       } else if (strncmp(options, "reverse", 7) == 0) {
+           reverse = 1;
 #if CONFIG_VNC_TLS
        } else if (strncmp(options, "tls", 3) == 0) {
            tls = 1; /* Require TLS */
@@ -2196,7 +2215,9 @@ int vnc_display_open(DisplayState *ds, const char *display)
        memset(uaddr.sun_path, 0, 108);
        snprintf(uaddr.sun_path, 108, "%s", p);
 
-       unlink(uaddr.sun_path);
+       if (!reverse) {
+           unlink(uaddr.sun_path);
+       }
     } else
 #endif
     {
@@ -2210,7 +2231,7 @@ int vnc_display_open(DisplayState *ds, const char *display)
            return -1;
        }
 
-       iaddr.sin_port = htons(ntohs(iaddr.sin_port) + 5900);
+       iaddr.sin_port = htons(ntohs(iaddr.sin_port) + (reverse ? 0 : 5900));
 
        vs->lsock = socket(PF_INET, SOCK_STREAM, 0);
        if (vs->lsock == -1) {
@@ -2233,6 +2254,22 @@ int vnc_display_open(DisplayState *ds, const char *display)
        }
     }
 
+    if (reverse) {
+        if (connect(vs->lsock, addr, addrlen) == -1) {
+            fprintf(stderr, "Connection to VNC client failed\n");
+            close(vs->lsock);
+            vs->lsock = -1;
+            free(vs->display);
+            vs->display = NULL;
+            return -1;
+        } else {
+            vs->csock = vs->lsock;
+            vs->lsock = -1;
+            vnc_connect(vs);
+            return 0;
+        }
+    }
+
     if (bind(vs->lsock, addr, addrlen) == -1) {
        fprintf(stderr, "bind() failed\n");
        close(vs->lsock);
This page took 0.024626 seconds and 4 git commands to generate.