2012-05-22 15:57:19 +04:00
|
|
|
/**
|
2012-10-09 07:02:04 +04:00
|
|
|
* FreeRDP: A Remote Desktop Protocol Implementation
|
2012-05-22 15:57:19 +04:00
|
|
|
* 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.
|
|
|
|
*/
|
|
|
|
|
2012-08-15 01:09:01 +04:00
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include "config.h"
|
|
|
|
#endif
|
|
|
|
|
2012-05-22 15:57:19 +04:00
|
|
|
#include <freerdp/utils/uds.h>
|
2014-08-11 11:49:57 +04:00
|
|
|
#include <freerdp/utils/debug.h>
|
2012-05-22 15:57:19 +04:00
|
|
|
|
|
|
|
#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)
|
|
|
|
{
|
2014-08-11 11:19:23 +04:00
|
|
|
DEBUG_WARN("socket");
|
2012-05-22 15:57:19 +04:00
|
|
|
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)
|
|
|
|
{
|
2014-08-11 11:19:23 +04:00
|
|
|
DEBUG_WARN("connect");
|
2012-05-22 15:57:19 +04:00
|
|
|
close(sockfd);
|
|
|
|
return -1;
|
|
|
|
}
|
|
|
|
|
|
|
|
return sockfd;
|
|
|
|
|
|
|
|
#else /* ifndef _WIN32 */
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
#endif
|
|
|
|
}
|