+ 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();