The `socket' function in the backends is only ever checked to see if
[u/mdw/putty] / telnet.c
index 54b9a7c..0d32f8c 100644 (file)
--- a/telnet.c
+++ b/telnet.c
@@ -1,3 +1,7 @@
+/*
+ * Telnet backend.
+ */
+
 #include <stdio.h>
 #include <stdlib.h>
 
@@ -394,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)
@@ -1012,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)
@@ -1078,7 +1085,7 @@ Backend telnet_backend = {
     telnet_size,
     telnet_special,
     telnet_get_specials,
-    telnet_socket,
+    telnet_connected,
     telnet_exitcode,
     telnet_sendok,
     telnet_ldisc,