Give up X server for now, connect to VNC on localhost instead.
authorSteinar H. Gunderson <sesse@samfundet.no>
Fri, 4 Feb 2005 15:49:23 +0000 (15:49 +0000)
committerSteinar H. Gunderson <sesse@samfundet.no>
Fri, 4 Feb 2005 15:49:23 +0000 (15:49 +0000)
proto.h
rdpsrv.c
tcp.c
util.c

diff --git a/proto.h b/proto.h
index fa41088..00ab7a0 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -119,6 +119,7 @@ STREAM tcp_init(uint32 maxlen);
 void tcp_send(STREAM s);
 STREAM tcp_recv(STREAM s, uint32 length);
 BOOL tcp_recv_connect(int server_sock);
+int tcp_connect(char *server, int port);
 void tcp_disconnect(void);
 /* xclip.c */
 void ui_clip_format_announce(uint8 * data, uint32 length);
index e97515b..7c6b1f6 100644 (file)
--- a/rdpsrv.c
+++ b/rdpsrv.c
@@ -104,10 +104,13 @@ void handle_input_pdu(STREAM s)
 
 int serve_client()
 {
+       // connect to VNC
+       int vnc_sock = tcp_connect("127.0.0.1", 5901);
+       
        if (!mcs_recv_connect_initial())
                error("MCS_CONNECT_INITIAL recv failed");
        mcs_send_connect_response();
-       
+
        for ( ;; ) {
                uint8 type, data_pdu_type;
                STREAM s;
diff --git a/tcp.c b/tcp.c
index fef986e..30aecad 100644 (file)
--- a/tcp.c
+++ b/tcp.c
@@ -132,6 +132,99 @@ tcp_recv(STREAM s, uint32 length)
        return s;
 }
 
+/* Establish a connection on the TCP layer */
+int
+tcp_connect(char *server, int port)
+{
+        int true_value = 1;
+       int sock;
+
+#ifdef IPv6
+
+        int n;
+        struct addrinfo hints, *res, *ressave;
+        char tcp_port_rdp_s[10];
+
+        snprintf(tcp_port_rdp_s, 10, "%d", tcp_port_rdp);
+
+        memset(&hints, 0, sizeof(struct addrinfo));
+        hints.ai_family = AF_UNSPEC;
+        hints.ai_socktype = SOCK_STREAM;
+
+        n = getaddrinfo(server, tcp_port_rdp_s, &hints, &res);
+
+        if (n < 0)
+        {
+                error("getaddrinfo: %s\n", gai_strerror(n));
+                return -1;
+        }
+
+        ressave = res;
+        sock = -1;
+        while (res)
+        {
+                sock = socket(res->ai_family, res->ai_socktype, res->ai_protocol);
+                if (!(sock < 0))
+                {
+                        if (connect(sock, res->ai_addr, res->ai_addrlen) == 0)
+                                break;
+                        close(sock);
+                        sock = -1;
+                }
+                res = res->ai_next;
+        }
+        freeaddrinfo(ressave);
+
+        if (sock == -1)
+        {
+                error("%s: unable to connect\n", server);
+                return -1;
+        }
+
+#else /* no IPv6 support */
+
+        struct hostent *nslookup;
+        struct sockaddr_in servaddr;
+
+        if ((nslookup = gethostbyname(server)) != NULL)
+        {
+                memcpy(&servaddr.sin_addr, nslookup->h_addr, sizeof(servaddr.sin_addr));
+        }
+        else if ((servaddr.sin_addr.s_addr = inet_addr(server)) == INADDR_NONE)
+        {
+                error("%s: unable to resolve host\n", server);
+                return -1;
+        }
+
+        if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
+        {
+                error("socket: %s\n", strerror(errno));
+                return -1;
+        }
+
+        servaddr.sin_family = AF_INET;
+        servaddr.sin_port = htons(port);
+
+        if (connect(sock, (struct sockaddr *) &servaddr, sizeof(struct sockaddr)) < 0)
+        {
+                error("connect: %s\n", strerror(errno));
+                close(sock);
+                return -1;
+        }
+
+#endif /* IPv6 */
+
+        setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *) &true_value, sizeof(true_value));
+
+        in.size = 4096;
+        in.data = (uint8 *) xmalloc(in.size);
+
+        out.size = 4096;
+        out.data = (uint8 *) xmalloc(out.size);
+
+        return sock;
+}
+
 /* Establish a connection on the TCP layer */
 BOOL
 tcp_recv_connect(int server_sock)
diff --git a/util.c b/util.c
index 44aefe7..3c2e4bd 100644 (file)
--- a/util.c
+++ b/util.c
@@ -27,7 +27,6 @@
 #include <sys/time.h>           /* gettimeofday */
 #include <sys/times.h>          /* times */
 #include <errno.h>
-#include <X11/Xlib.h>           /* Window */
 #include "rdesktop.h"
 
 #ifdef EGD_SOCKET