mirror of https://github.com/FreeRDP/FreeRDP
libfreerdp-core: add client unix domain socket.
This commit is contained in:
parent
f4c8ebf13f
commit
20f038581b
|
@ -0,0 +1,28 @@
|
|||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Unix Domain Socket Utils
|
||||
*
|
||||
* Copyright 2012 Vic Lee
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#ifndef FREERDP_UDS_UTILS_H
|
||||
#define FREERDP_UDS_UTILS_H
|
||||
|
||||
#include <freerdp/api.h>
|
||||
#include <freerdp/types.h>
|
||||
|
||||
FREERDP_API int freerdp_uds_connect(const char* path);
|
||||
|
||||
#endif /* FREERDP_UDS_UTILS_H */
|
|
@ -46,6 +46,7 @@
|
|||
#endif
|
||||
|
||||
#include <freerdp/utils/tcp.h>
|
||||
#include <freerdp/utils/uds.h>
|
||||
#include <freerdp/utils/print.h>
|
||||
#include <freerdp/utils/stream.h>
|
||||
#include <freerdp/utils/memory.h>
|
||||
|
@ -115,30 +116,40 @@ boolean tcp_connect(rdpTcp* tcp, const char* hostname, uint16 port)
|
|||
uint32 option_value;
|
||||
socklen_t option_len;
|
||||
|
||||
tcp->sockfd = freerdp_tcp_connect(hostname, port);
|
||||
|
||||
if (tcp->sockfd < 0)
|
||||
return false;
|
||||
|
||||
tcp_get_ip_address(tcp);
|
||||
tcp_get_mac_address(tcp);
|
||||
|
||||
option_value = 1;
|
||||
option_len = sizeof(option_value);
|
||||
setsockopt(tcp->sockfd, IPPROTO_TCP, TCP_NODELAY, (void*) &option_value, option_len);
|
||||
|
||||
/* receive buffer must be a least 32 K */
|
||||
if (getsockopt(tcp->sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &option_value, &option_len) == 0)
|
||||
if (hostname[0] == '/')
|
||||
{
|
||||
if (option_value < (1024 * 32))
|
||||
{
|
||||
option_value = 1024 * 32;
|
||||
option_len = sizeof(option_value);
|
||||
setsockopt(tcp->sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &option_value, option_len);
|
||||
}
|
||||
}
|
||||
tcp->sockfd = freerdp_uds_connect(hostname);
|
||||
|
||||
tcp_set_keep_alive_mode(tcp);
|
||||
if (tcp->sockfd < 0)
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
tcp->sockfd = freerdp_tcp_connect(hostname, port);
|
||||
|
||||
if (tcp->sockfd < 0)
|
||||
return false;
|
||||
|
||||
tcp_get_ip_address(tcp);
|
||||
tcp_get_mac_address(tcp);
|
||||
|
||||
option_value = 1;
|
||||
option_len = sizeof(option_value);
|
||||
setsockopt(tcp->sockfd, IPPROTO_TCP, TCP_NODELAY, (void*) &option_value, option_len);
|
||||
|
||||
/* receive buffer must be a least 32 K */
|
||||
if (getsockopt(tcp->sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &option_value, &option_len) == 0)
|
||||
{
|
||||
if (option_value < (1024 * 32))
|
||||
{
|
||||
option_value = 1024 * 32;
|
||||
option_len = sizeof(option_value);
|
||||
setsockopt(tcp->sockfd, SOL_SOCKET, SO_RCVBUF, (void*) &option_value, option_len);
|
||||
}
|
||||
}
|
||||
|
||||
tcp_set_keep_alive_mode(tcp);
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
|
|
@ -48,6 +48,7 @@ set(FREERDP_UTILS_SRCS
|
|||
tcp.c
|
||||
thread.c
|
||||
time.c
|
||||
uds.c
|
||||
unicode.c
|
||||
wait_obj.c)
|
||||
|
||||
|
|
|
@ -0,0 +1,74 @@
|
|||
/**
|
||||
* FreeRDP: A Remote Desktop Protocol Client
|
||||
* Unix Domain Socket Utils
|
||||
*
|
||||
* Copyright 2012 Vic Lee
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
#include <freerdp/utils/uds.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <errno.h>
|
||||
#include <fcntl.h>
|
||||
|
||||
#ifndef _WIN32
|
||||
|
||||
#include <netdb.h>
|
||||
#include <unistd.h>
|
||||
#include <sys/un.h>
|
||||
#include <sys/ioctl.h>
|
||||
#include <sys/socket.h>
|
||||
#include <netinet/in.h>
|
||||
#include <netinet/tcp.h>
|
||||
#include <net/if.h>
|
||||
|
||||
#endif
|
||||
|
||||
int freerdp_uds_connect(const char* path)
|
||||
{
|
||||
#ifndef _WIN32
|
||||
|
||||
int status;
|
||||
int sockfd;
|
||||
struct sockaddr_un addr;
|
||||
|
||||
sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
|
||||
if (sockfd == -1)
|
||||
{
|
||||
perror("socket");
|
||||
return -1;
|
||||
}
|
||||
|
||||
addr.sun_family = AF_UNIX;
|
||||
strncpy(addr.sun_path, path, sizeof(addr.sun_path));
|
||||
status = connect(sockfd, (struct sockaddr *) &addr, sizeof(addr));
|
||||
if (status < 0)
|
||||
{
|
||||
perror("connect");
|
||||
close(sockfd);
|
||||
return -1;
|
||||
}
|
||||
|
||||
return sockfd;
|
||||
|
||||
#else /* ifndef _WIN32 */
|
||||
|
||||
return -1;
|
||||
|
||||
#endif
|
||||
}
|
Loading…
Reference in New Issue