diff options
author | Jay Sorg <jay.sorg@gmail.com> | 2018-08-20 23:12:04 +0300 |
---|---|---|
committer | Jay Sorg <jay.sorg@gmail.com> | 2018-08-20 23:12:04 +0300 |
commit | cebc9d8f3a12c14f250d0e6c3d811f5ed173b7a3 (patch) | |
tree | 39d1d62c433f72cc907e1c4b93a4ba29fcb4083f | |
parent | 5526fa0d4da9c4f61be488ea2677f6df4c20e917 (diff) |
add connect to unix domain socket
-rw-r--r-- | libfreerdp-core/tcp.c | 24 |
1 files changed, 24 insertions, 0 deletions
diff --git a/libfreerdp-core/tcp.c b/libfreerdp-core/tcp.c index 1d85cd8..988db7d 100644 --- a/libfreerdp-core/tcp.c +++ b/libfreerdp-core/tcp.c @@ -31,6 +31,7 @@ #include <unistd.h> #include <sys/ioctl.h> #include <sys/socket.h> +#include <sys/un.h> #include <netinet/in.h> #include <netinet/tcp.h> #include <net/if.h> @@ -126,6 +127,29 @@ tbool tcp_connect(rdpTcp* tcp, const char* hostname, uint16 port) struct addrinfo hints = { 0 }; struct addrinfo * res, * ai; + printf("host %s port %d\n", hostname, port); + if (hostname[0] == '/') + { + struct sockaddr_un s; + memset(&s, 0, sizeof(struct sockaddr_un)); + s.sun_family = AF_UNIX; + strncpy(s.sun_path, hostname, sizeof(s.sun_path)); + s.sun_path[sizeof(s.sun_path) - 1] = 0; + tcp->sockfd = socket(PF_LOCAL, SOCK_STREAM, 0); + if (tcp->sockfd == -1) + { + printf("socket failed, unable to connect to %s\n", hostname); + return false; + } + if (connect(tcp->sockfd, (struct sockaddr *)&s, sizeof(struct sockaddr_un)) < 0) + { + printf("connect failed, unable to connect to %s\n", hostname); + return false; + } + printf("connected to %s ok\n", hostname); + return true; + } + memset(&hints, 0, sizeof(struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; |