]> git.sesse.net Git - rdpsrv/commitdiff
Moved socket functions around a bit.
authorSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 3 Feb 2005 22:52:47 +0000 (22:52 +0000)
committerSteinar H. Gunderson <sgunderson@bigfoot.com>
Thu, 3 Feb 2005 22:52:47 +0000 (22:52 +0000)
iso.c
proto.h
rdpsrv.c
tcp.c

diff --git a/iso.c b/iso.c
index 26e967b384560fbe790d92e047ac8e57e9354d33..9a343ad207f5dce2282a9fded81b85776be1af42 100644 (file)
--- a/iso.c
+++ b/iso.c
@@ -182,30 +182,6 @@ iso_recv(void)
        return s;
 }
 
-/* Establish a connection up to the ISO layer */
-BOOL
-iso_connect(char *server, char *username)
-{
-       uint8 code;
-
-       if (!tcp_connect(server))
-               return False;
-
-       iso_send_connection_request(username);
-
-       if (iso_recv_msg(&code) == NULL)
-               return False;
-
-       if (code != ISO_PDU_CC)
-       {
-               error("expected CC, got 0x%x\n", code);
-               tcp_disconnect();
-               return False;
-       }
-
-       return True;
-}
-
 /* Disconnect from the ISO layer */
 void
 iso_disconnect(void)
diff --git a/proto.h b/proto.h
index b371330c73a51b74db454226aece19964ffb89c6..db5e98fa202a1cd3fa0829176258a0c2593a95b6 100644 (file)
--- a/proto.h
+++ b/proto.h
@@ -115,7 +115,7 @@ void sec_disconnect(void);
 STREAM tcp_init(uint32 maxlen);
 void tcp_send(STREAM s);
 STREAM tcp_recv(STREAM s, uint32 length);
-BOOL tcp_connect(char *server);
+BOOL tcp_recv_connect(int server_sock);
 void tcp_disconnect(void);
 /* xclip.c */
 void ui_clip_format_announce(uint8 * data, uint32 length);
index 8355426ebc0755b51cef60570dd9ac7bd77cc155..045cf8db7fd40f58a415dd6b4e059df03fe3e5ad 100644 (file)
--- a/rdpsrv.c
+++ b/rdpsrv.c
 
 const int tcp_port_rdp = 3389;
 int create_server_socket();
-int serve_client(int sock);
+int serve_client();
 
 int main()
 {
        int server_sock = create_server_socket();
        for ( ;; ) {
-               struct sockaddr_in sin;
-               socklen_t len;
-               int sock = accept(server_sock, (struct sockaddr *)&sin, &len);
-       
-               if (sock == -1) {
-                       perror("accept()");
-                       exit(1);
-               }
-
-               serve_client(sock);
-
-               close(sock);
+               tcp_recv_connect(server_sock);
+               serve_client();
        }
 }
 
@@ -67,7 +57,7 @@ int create_server_socket()
 }
 
 
-int serve_client(int sock)
+int serve_client()
 {
        for ( ;; ) {
                unsigned char buf[4096];
diff --git a/tcp.c b/tcp.c
index 4e114223ef11e6a392544ff3e79cf6d85c1f3f0a..fef986eafabd56c8d70ca9bfb5829ddfcbf872ba 100644 (file)
--- a/tcp.c
+++ b/tcp.c
@@ -134,85 +134,18 @@ tcp_recv(STREAM s, uint32 length)
 
 /* Establish a connection on the TCP layer */
 BOOL
-tcp_connect(char *server)
+tcp_recv_connect(int server_sock)
 {
-       int true_value = 1;
-
-#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 False;
-       }
-
-       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 False;
+       struct sockaddr_in sin;
+       unsigned true_value = 1;
+       socklen_t len = sizeof(sin);
+       sock = accept(server_sock, (struct sockaddr *)&sin, &len);
+
+       if (sock == -1) {
+               perror("accept()");
+               exit(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 False;
-       }
-
-       if ((sock = socket(AF_INET, SOCK_STREAM, 0)) < 0)
-       {
-               error("socket: %s\n", strerror(errno));
-               return False;
-       }
-
-       servaddr.sin_family = AF_INET;
-       servaddr.sin_port = htons(tcp_port_rdp);
-
-       if (connect(sock, (struct sockaddr *) &servaddr, sizeof(struct sockaddr)) < 0)
-       {
-               error("connect: %s\n", strerror(errno));
-               close(sock);
-               return False;
-       }
-
-#endif /* IPv6 */
-
        setsockopt(sock, IPPROTO_TCP, TCP_NODELAY, (void *) &true_value, sizeof(true_value));
 
        in.size = 4096;