Commas at the end of enumerator lists aren't allowed.
[u/mdw/putty] / x11fwd.c
index 033184b..4b043fa 100644 (file)
--- a/x11fwd.c
+++ b/x11fwd.c
@@ -1,4 +1,3 @@
-#include <windows.h>
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -141,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.
@@ -172,13 +189,21 @@ 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);
+    addr = name_lookup(host, port, &dummy_realhost);
     if ((err = sk_addr_error(addr)))
        return err;