}
}
-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");