Remove buffer we don't need.
[rdpsrv] / rdpsrv.c
1 #include <stdio.h>
2 #include <stdlib.h>
3 #include <unistd.h>
4 #include <errno.h>
5 #include <sys/socket.h>
6 #include <sys/ioctl.h>
7 #include <arpa/inet.h>
8
9 #include "rdesktop.h"
10
11 const int tcp_port_rdp = 3389;
12 int create_server_socket();
13 int serve_client();
14
15 int main()
16 {
17         int server_sock = create_server_socket();
18         for ( ;; ) {
19                 tcp_recv_connect(server_sock);
20                 serve_client();
21         }
22 }
23
24 int create_server_socket()
25 {
26         int server_sock = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
27         const unsigned int one = 1, zero = 0;
28         struct sockaddr_in addr;
29         int err;
30
31         setsockopt(server_sock, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one));
32         ioctl(server_sock, FIONBIO, &zero);
33
34         addr.sin_family = AF_INET;
35         addr.sin_addr.s_addr = INADDR_ANY;
36         addr.sin_port = htons(tcp_port_rdp);
37
38         do {
39                 err = bind(server_sock, (struct sockaddr *)&addr, sizeof(struct sockaddr));
40
41                 if (err == -1) {
42                         perror("bind()");
43
44                         /* try to recover from recoverable errors... */
45                         if (errno == ENOMEM || errno == EADDRINUSE) {
46                                 puts("Waiting 1 sec before trying again...");
47                                 sleep(1);
48                         } else {
49                                 puts("Giving up.");
50                                 exit(1);
51                         }
52                 }
53         } while (err == -1);
54
55         listen(server_sock, 20);
56         return server_sock;
57 }
58
59
60 int serve_client()
61 {
62         for ( ;; ) {
63                 short channel;
64                 
65                 /* receive ISO packets */
66                 mcs_recv(&channel);
67         }
68 }