5 #include <sys/socket.h>
11 const int tcp_port_rdp = 3389;
12 int create_server_socket();
17 int server_sock = create_server_socket();
19 iso_recv_connect(server_sock);
20 printf("Got connection.\n");
22 printf("Client closed.\n");
26 int create_server_socket()
28 int server_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
29 const unsigned int one = 1, zero = 0;
30 struct sockaddr_in addr;
33 setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
34 ioctl(server_sock, FIONBIO, &zero);
36 addr.sin_family = AF_INET;
37 addr.sin_addr.s_addr = INADDR_ANY;
38 addr.sin_port = htons(tcp_port_rdp);
41 err = bind(server_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr));
46 /* try to recover from recoverable errors... */
47 if (errno == ENOMEM || errno == EADDRINUSE) {
48 puts("Waiting 1 sec before trying again...");
57 listen(server_sock, 20);
61 void handle_input_pdu(STREAM s)
64 uint16 message_type, device_flags, param1, param2;
68 in_uint16_le(s, num_events); // number of events
69 in_uint8s(s, 2); // pad
71 for (i = 0; i < num_events; ++i) {
72 rdp_recv_input(s, &time, &message_type, &device_flags, ¶m1, ¶m2);
73 printf("Input event at time %u\n", time);
75 switch (message_type) {
76 case RDP_INPUT_SYNCHRONIZE:
77 printf("- Type: Synchronize (ignored)\n");
79 case RDP_INPUT_CODEPOINT:
80 printf("- Type: Codepoint (ignored)\n");
82 case RDP_INPUT_VIRTKEY:
83 printf("- Type: Virtual key (ignored)\n");
85 case RDP_INPUT_SCANCODE:
86 printf("- Type: Scancode (ignored)\n");
89 printf("- Type: Mouse\n");
90 printf("- Device flags: %x\n", device_flags);
91 printf("- Position: (%u,%u)\n", param1, param2);
94 rdp_send_bitmap_update(param1, param2);
98 printf("- Unknown type %x\n", message_type);
105 struct ServerInitialization {
106 unsigned short width;
107 unsigned short height;
108 unsigned char pixelformat[16]; // FIXME
109 unsigned int name_len;
115 int vnc_sock = tcp_connect("127.0.0.1", 5901);
116 struct ServerInitialization si;
119 if (read(vnc_sock, buf, 12) != 12)
120 error("short read on handshake\n");
121 write(vnc_sock, "RFB 003.003\n", 12);
124 if (read(vnc_sock, buf, 4) != 4)
125 error("short read on auth\n");
128 error("auth needed or connection failed\n");
132 write(vnc_sock, buf, 1);
134 // read the server initialization
135 if (read(vnc_sock, &si, sizeof(struct ServerInitialization)) != sizeof(struct ServerInitialization))
136 error("short read on SI");
138 printf("Server is %u x %u\n", ntohs(si.width), ntohs(si.height));
140 if (read(vnc_sock, buf, ntohs(si.name_len)) != ntohs(si.name_len))
141 error("short read on server name\n");
143 printf("Server name is '%*s'\n", ntohs(si.name_len), buf);
145 // we can only accept raw encoding
146 buf[0] = 2; // message type
147 buf[1] = 0; // padding
148 buf[2] = 0; // number of encodings
150 buf[4] = 0; // raw encoding
152 write(vnc_sock, buf, 5);
154 // request the entire framebuffer
155 buf[0] = 3; // message type
156 buf[1] = 0; // incremental
161 buf[6] = 640 >> 8; // width
163 buf[8] = 480 >> 8; // height
166 write(vnc_sock, buf, 10);
168 printf("Connected to VNC!\n");
175 int vnc_sock = vnc_init();
177 if (!mcs_recv_connect_initial())
178 error("MCS_CONNECT_INITIAL recv failed");
179 mcs_send_connect_response();
182 uint8 type, data_pdu_type;
185 while ((s = rdp_recv(&type)) != NULL) {
186 if (type != RDP_PDU_DATA) {
187 printf("Unknown RDP packet of type %u\n", type);
191 in_uint8s(s, 8); /* shareid, pad, streamid, length */
192 in_uint8(s, data_pdu_type);
193 in_uint8s(s, 3); /* compress_type, compress_len */
195 switch (data_pdu_type) {
196 case RDP_DATA_PDU_INPUT:
197 printf("Input PDU\n");
201 printf("Unknown data PDU type %u\n", data_pdu_type);