The `socket' function in the backends is only ever checked to see if
[u/mdw/putty] / telnet.c
index 36c0f72..0d32f8c 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -1,3 +1,7 @@
+/*
+ * Telnet backend.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -196,12 +200,10 @@ static const struct Opt o_tspeed =
     { WILL, WONT, DO, DONT, TELOPT_TSPEED, OPTINDEX_TSPEED, REQUESTED };
 static const struct Opt o_ttype =
     { WILL, WONT, DO, DONT, TELOPT_TTYPE, OPTINDEX_TTYPE, REQUESTED };
-static const struct Opt o_oenv = { WILL, WONT, DO, DONT, TELOPT_OLD_ENVIRON,
-    OPTINDEX_OENV, INACTIVE
-};
-static const struct Opt o_nenv = { WILL, WONT, DO, DONT, TELOPT_NEW_ENVIRON,
-    OPTINDEX_NENV, REQUESTED
-};
+static const struct Opt o_oenv =
+    { WILL, WONT, DO, DONT, TELOPT_OLD_ENVIRON, OPTINDEX_OENV, INACTIVE };
+static const struct Opt o_nenv =
+    { WILL, WONT, DO, DONT, TELOPT_NEW_ENVIRON, OPTINDEX_NENV, REQUESTED };
 static const struct Opt o_echo =
     { DO, DONT, WILL, WONT, TELOPT_ECHO, OPTINDEX_ECHO, REQUESTED };
 static const struct Opt o_we_sga =
@@ -396,9 +398,12 @@ static void proc_rec_opt(Telnet telnet, int cmd, int option)
     }
     /*
      * If we reach here, the option was one we weren't prepared to
-     * cope with. So send a negative ack.
+     * cope with. If the request was positive (WILL or DO), we send
+     * a negative ack to indicate refusal. If the request was
+     * negative (WONT / DONT), we must do nothing.
      */
-    send_opt(telnet, (cmd == WILL ? DONT : WONT), option);
+    if (cmd == WILL || cmd == DO)
+        send_opt(telnet, (cmd == WILL ? DONT : WONT), option);
 }
 
 static void process_subneg(Telnet telnet)
@@ -1014,10 +1019,10 @@ static const struct telnet_special *telnet_get_specials(void *handle)
     return specials;
 }
 
-static Socket telnet_socket(void *handle)
+static int telnet_connected(void *handle)
 {
     Telnet telnet = (Telnet) handle;
-    return telnet->s;
+    return telnet->s != NULL;
 }
 
 static int telnet_sendok(void *handle)
@@ -1080,7 +1085,7 @@ Backend telnet_backend = {
     telnet_size,
     telnet_special,
     telnet_get_specials,
-    telnet_socket,
+    telnet_connected,
     telnet_exitcode,
     telnet_sendok,
     telnet_ldisc,