]> git.sesse.net Git - rdpsrv/commitdiff
Basic connection to VNC added (read width and height, mostly).
authorSteinar H. Gunderson <sesse@samfundet.no>
Fri, 4 Feb 2005 15:58:59 +0000 (15:58 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Fri, 4 Feb 2005 15:58:59 +0000 (15:58 +0000)
rdpsrv.c

index 7c6b1f60a7dbeba7ca3118a9b6afc70d23890b90..43bf2a42d449faf1d11d2149355d92356e4134e6 100644 (file)
--- a/rdpsrv.c
+++ b/rdpsrv.c
@@ -102,10 +102,54 @@ void handle_input_pdu(STREAM s)
        }
 }
 
-int serve_client()
+struct ServerInitialization {
+       unsigned short width;
+       unsigned short height;
+       unsigned char pixelformat[16]; // FIXME
+       unsigned int name_len;
+};
+
+int vnc_init()
 {
-       // connect to VNC
+       char buf[256];
        int vnc_sock = tcp_connect("127.0.0.1", 5901);
+       struct ServerInitialization si;
+
+       // get handshake
+       if (read(vnc_sock, buf, 12) != 12)
+               error("short read on handshake\n");
+       write(vnc_sock, "RFB 003.003\n", 12);
+
+       // get auth
+       if (read(vnc_sock, buf, 4) != 4)
+               error("short read on auth\n");
+
+       if (buf[3] != 1)
+               error("auth needed or connection failed\n");
+
+       // send shared flag
+       buf[0] = 1;
+       write(vnc_sock, buf, 1);
+
+       // read the server initialization
+       if (read(vnc_sock, &si, sizeof(struct ServerInitialization)) != sizeof(struct ServerInitialization))
+               error("short read on SI");
+
+       printf("Server is %u x %u\n", ntohs(si.width), ntohs(si.height));
+
+       if (read(vnc_sock, buf, si.name_len) != si.name_len)
+               error("short read on server name");
+
+       printf("Server name is '%*s'\n", si.name_len, buf);
+       
+       printf("Connected to VNC!\n");
+
+       return vnc_sock;
+}
+
+int serve_client()
+{
+       int vnc_sock = vnc_init();
        
        if (!mcs_recv_connect_initial())
                error("MCS_CONNECT_INITIAL recv failed");