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);
108 int vnc_sock = tcp_connect("127.0.0.1", 5901);
110 if (!mcs_recv_connect_initial())
111 error("MCS_CONNECT_INITIAL recv failed");
112 mcs_send_connect_response();
115 uint8 type, data_pdu_type;
118 while ((s = rdp_recv(&type)) != NULL) {
119 if (type != RDP_PDU_DATA) {
120 printf("Unknown RDP packet of type %u\n", type);
124 in_uint8s(s, 8); /* shareid, pad, streamid, length */
125 in_uint8(s, data_pdu_type);
126 in_uint8s(s, 3); /* compress_type, compress_len */
128 switch (data_pdu_type) {
129 case RDP_DATA_PDU_INPUT:
130 printf("Input PDU\n");
134 printf("Unknown data PDU type %u\n", data_pdu_type);