X-Git-Url: https://git.distorted.org.uk/u/mdw/putty/blobdiff_plain/68a49acbf3f96fbbbc385620655dcb577e62c328..ab8605c2047cac4e6f30cee6530e886e63324bf5:/x11fwd.c diff --git a/x11fwd.c b/x11fwd.c index c6e36378..d21441b9 100644 --- a/x11fwd.c +++ b/x11fwd.c @@ -140,6 +140,24 @@ static void x11_sent(Plug plug, int bufsize) } /* + * When setting up X forwarding, we should send the screen number + * from the specified local display. This function extracts it from + * the display string. + */ +int x11_get_screen_number(char *display) +{ + int n; + + n = strcspn(display, ":"); + if (!display[n]) + return 0; + n = strcspn(display, "."); + if (!display[n]) + return 0; + return atoi(display + n + 1); +} + +/* * Called to set up the raw connection. * * Returns an error message, or NULL on success. @@ -171,14 +189,22 @@ char *x11_init(Socket * s, char *display, void *c, void *auth) displaynum = 0; /* sensible default */ if (n > sizeof(host) - 1) n = sizeof(host) - 1; - strncpy(host, display, n); - host[n] = '\0'; + if (n > 0) { + strncpy(host, display, n); + host[n] = '\0'; + } else { + /* + * Local display numbers, particularly on Unix, often omit + * the display part completely. + */ + strcpy(host, "localhost"); + } /* * Try to find host. */ - addr = sk_namelookup(host, &dummy_realhost); - if ((err = sk_addr_error(addr))) + addr = name_lookup(host, port, &dummy_realhost); + if ((err = sk_addr_error(addr)) != NULL) return err; port = 6000 + displaynum; @@ -196,7 +222,7 @@ char *x11_init(Socket * s, char *display, void *c, void *auth) pr->c = c; pr->s = *s = new_connection(addr, dummy_realhost, port, 0, 1, 0, (Plug) pr); - if ((err = sk_socket_error(*s))) { + if ((err = sk_socket_error(*s)) != NULL) { sfree(pr); return err; } @@ -273,7 +299,7 @@ int x11_send(Socket s, char *data, int len) pr->auth_dsize = (pr->auth_dlen + 3) & ~3; /* Leave room for a terminating zero, to make our lives easier. */ pr->auth_protocol = (char *) smalloc(pr->auth_psize + 1); - pr->auth_data = (char *) smalloc(pr->auth_dsize); + pr->auth_data = (unsigned char *) smalloc(pr->auth_dsize); } /* @@ -312,7 +338,7 @@ int x11_send(Socket s, char *data, int len) PUT_16BIT(pr->firstpkt[0], reply + 6, msgsize >> 2);/* data len */ memset(reply + 8, 0, msgsize); memcpy(reply + 8, message, msglen); - sshfwd_write(pr->c, reply, 8 + msgsize); + sshfwd_write(pr->c, (char *)reply, 8 + msgsize); sshfwd_close(pr->c); x11_close(s); return 0; @@ -325,7 +351,7 @@ int x11_send(Socket s, char *data, int len) */ PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 6, 0); /* auth proto */ PUT_16BIT(pr->firstpkt[0], pr->firstpkt + 8, 0); /* auth data */ - sk_write(s, pr->firstpkt, 12); + sk_write(s, (char *)pr->firstpkt, 12); pr->verified = 1; }