Fix for `psftp-pscp-ignore-load': Default Settings is now loaded
[u/mdw/putty] / plink.c
diff --git a/plink.c b/plink.c
index b46c5d6..3afd73c 100644 (file)
--- a/plink.c
+++ b/plink.c
@@ -1,5 +1,5 @@
 /*
- * PLink - a command-line (stdin/stdout) variant of PuTTY.
+ * PLink - a Windows command-line (stdin/stdout) variant of PuTTY.
  */
 
 #include <stdio.h>
@@ -210,6 +210,7 @@ static void usage(void)
     printf("Usage: plink [options] [user@]host [command]\n");
     printf("       (\"host\" can also be a PuTTY saved session name)\n");
     printf("Options:\n");
+    printf("  -V        print version information\n");
     printf("  -v        show verbose messages\n");
     printf("  -load sessname  Load settings from saved session\n");
     printf("  -ssh -telnet -rlogin -raw\n");
@@ -220,11 +221,12 @@ static void usage(void)
     printf("  -batch    disable all interactive prompts\n");
     printf("The following options only apply to SSH connections:\n");
     printf("  -pw passw login with specified password\n");
-    printf("  -D listen-port   Dynamic SOCKS-based port forwarding\n");
-    printf("  -L listen-port:host:port   Forward local port to "
-          "remote address\n");
-    printf("  -R listen-port:host:port   Forward remote port to"
-          " local address\n");
+    printf("  -D [listen-IP:]listen-port\n");
+    printf("            Dynamic SOCKS-based port forwarding\n");
+    printf("  -L [listen-IP:]listen-port:host:port\n");
+    printf("            Forward local port to remote address\n");
+    printf("  -R [listen-IP:]listen-port:host:port\n");
+    printf("            Forward remote port to local address\n");
     printf("  -X -x     enable / disable X11 forwarding\n");
     printf("  -A -a     enable / disable agent forwarding\n");
     printf("  -t -T     enable / disable pty allocation\n");
@@ -235,6 +237,12 @@ static void usage(void)
     exit(1);
 }
 
+static void version(void)
+{
+    printf("plink: %s\n", ver);
+    exit(1);
+}
+
 char *do_select(SOCKET skt, int startup)
 {
     int events;
@@ -287,6 +295,7 @@ int main(int argc, char **argv)
      * Process the command line.
      */
     do_defaults(NULL, &cfg);
+    loaded_session = FALSE;
     default_protocol = cfg.protocol;
     default_port = cfg.port;
     errors = 0;
@@ -325,6 +334,8 @@ int main(int argc, char **argv)
            } else if (!strcmp(p, "-s")) {
                /* Save status to write to cfg later. */
                use_subsystem = 1;
+           } else if (!strcmp(p, "-V")) {
+                version();
            } else {
                fprintf(stderr, "plink: unknown option \"%s\"\n", p);
                errors = 1;
@@ -399,13 +410,15 @@ int main(int argc, char **argv)
                         */
                        Config cfg2;
                        do_defaults(p, &cfg2);
-                       if (cfg2.host[0] == '\0') {
+                       if (loaded_session || cfg2.host[0] == '\0') {
                            /* No settings for this host; use defaults */
+                           /* (or session was already loaded with -load) */
                            strncpy(cfg.host, p, sizeof(cfg.host) - 1);
                            cfg.host[sizeof(cfg.host) - 1] = '\0';
                            cfg.port = default_port;
                        } else {
                            cfg = cfg2;
+                           /* Ick: patch up internal pointer after copy */
                            cfg.remote_cmd_ptr = cfg.remote_cmd;
                        }
                    } else {
@@ -554,7 +567,7 @@ int main(int argc, char **argv)
            (GetFileType(GetStdHandle(STD_INPUT_HANDLE)) == FILE_TYPE_CHAR);
 
        error = back->init(NULL, &backhandle, &cfg, cfg.host, cfg.port,
-                          &realhost, nodelay);
+                          &realhost, nodelay, cfg.tcp_keepalives);
        if (error) {
            fprintf(stderr, "Unable to open connection:\n%s", error);
            return 1;