Yet another attempt at OOB handling in the network abstraction. This
[u/mdw/putty] / rlogin.c
index 20296a0..8a7b1fa 100644 (file)
--- a/rlogin.c
+++ b/rlogin.c
@@ -24,13 +24,14 @@ static void c_write (char *buf, int len) {
     from_backend(0, buf, len);
 }
 
-static int rlogin_receive (Socket s, int urgent, char *data, int len) {
+static int rlogin_receive (Socket skt, int urgent, char *data, int len) {
     if (urgent==3) {
         /* A socket error has occurred. */
+        sk_close(s);
+        s = NULL;
         connection_fatal(data);
-        len = 0;
-    }
-    if (!len) {
+        return 0;
+    } else if (!len) {
        /* Connection has closed. */
        sk_close(s);
        s = NULL;
@@ -40,7 +41,7 @@ static int rlogin_receive (Socket s, int urgent, char *data, int len) {
         char c;
         
         c = *data++; len--;
-        if (c == 0x80)
+        if (c == '\x80')
             rlogin_size();
         /*
          * We should flush everything (aka Telnet SYNCH) if we see
@@ -48,8 +49,22 @@ static int rlogin_receive (Socket s, int urgent, char *data, int len) {
          * on 0x10 and 0x20 respectively. I'm not convinced it's
          * worth it...
          */
+    } else {
+        /*
+         * Main rlogin protocol. This is really simple: the first
+         * byte is expected to be NULL and is ignored, and the rest
+         * is printed.
+         */
+        static int firstbyte = 1;
+        if (firstbyte) {
+            if (data[0] == '\0') {
+                data++;
+                len--;
+            }
+            firstbyte = 0;
+        }
+        c_write(data, len);
     }
-    c_write(data, len);
     return 1;
 }
 
@@ -77,7 +92,7 @@ static char *rlogin_init (char *host, int port, char **realhost) {
     /*
      * Open socket.
      */
-    s = sk_new(addr, port, 1, rlogin_receive);
+    s = sk_new(addr, port, 1, 0, rlogin_receive);
     if ( (err = sk_socket_error(s)) )
        return err;