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, si.name_len) != si.name_len)
141 error("short read on server name");
143 printf("Server name is '%*s'\n", si.name_len, buf);
145 printf("Connected to VNC!\n");
152 int vnc_sock = vnc_init();
154 if (!mcs_recv_connect_initial())
155 error("MCS_CONNECT_INITIAL recv failed");
156 mcs_send_connect_response();
159 uint8 type, data_pdu_type;
162 while ((s = rdp_recv(&type)) != NULL) {
163 if (type != RDP_PDU_DATA) {
164 printf("Unknown RDP packet of type %u\n", type);
168 in_uint8s(s, 8); /* shareid, pad, streamid, length */
169 in_uint8(s, data_pdu_type);
170 in_uint8s(s, 3); /* compress_type, compress_len */
172 switch (data_pdu_type) {
173 case RDP_DATA_PDU_INPUT:
174 printf("Input PDU\n");
178 printf("Unknown data PDU type %u\n", data_pdu_type);