~ubuntu-branches/ubuntu/vivid/freerdp/vivid

« back to all changes in this revision

Viewing changes to libfreerdp/utils/uds.c

  • Committer: Package Import Robot
  • Author(s): Iain Lane
  • Date: 2014-11-11 12:20:50 UTC
  • mfrom: (1.2.5)
  • mto: This revision was merged to the branch mainline in revision 24.
  • Revision ID: package-import@ubuntu.com-20141111122050-7z628f4ab38qxad5
Tags: upstream-1.1.0~git20140921.1.440916e+dfsg1
ImportĀ upstreamĀ versionĀ 1.1.0~git20140921.1.440916e+dfsg1

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/**
 
2
 * FreeRDP: A Remote Desktop Protocol Implementation
 
3
 * Unix Domain Socket Utils
 
4
 *
 
5
 * Copyright 2012 Vic Lee
 
6
 *
 
7
 * Licensed under the Apache License, Version 2.0 (the "License");
 
8
 * you may not use this file except in compliance with the License.
 
9
 * You may obtain a copy of the License at
 
10
 *
 
11
 *     http://www.apache.org/licenses/LICENSE-2.0
 
12
 *
 
13
 * Unless required by applicable law or agreed to in writing, software
 
14
 * distributed under the License is distributed on an "AS IS" BASIS,
 
15
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 
16
 * See the License for the specific language governing permissions and
 
17
 * limitations under the License.
 
18
 */
 
19
 
 
20
#ifdef HAVE_CONFIG_H
 
21
#include "config.h"
 
22
#endif
 
23
 
 
24
#include <freerdp/utils/uds.h>
 
25
 
 
26
#include <stdio.h>
 
27
#include <stdlib.h>
 
28
#include <string.h>
 
29
#include <time.h>
 
30
#include <errno.h>
 
31
#include <fcntl.h>
 
32
 
 
33
#ifndef _WIN32
 
34
 
 
35
#include <netdb.h>
 
36
#include <unistd.h>
 
37
#include <sys/un.h>
 
38
#include <sys/ioctl.h>
 
39
#include <sys/socket.h>
 
40
#include <netinet/in.h>
 
41
#include <netinet/tcp.h>
 
42
#include <net/if.h>
 
43
 
 
44
#endif
 
45
 
 
46
int freerdp_uds_connect(const char* path)
 
47
{
 
48
#ifndef _WIN32
 
49
 
 
50
        int status;
 
51
        int sockfd;
 
52
        struct sockaddr_un addr;
 
53
 
 
54
        sockfd = socket(AF_UNIX, SOCK_STREAM, 0);
 
55
        if (sockfd == -1)
 
56
        {
 
57
                perror("socket");
 
58
                return -1;
 
59
        }
 
60
 
 
61
        addr.sun_family = AF_UNIX;
 
62
        strncpy(addr.sun_path, path, sizeof(addr.sun_path));
 
63
        status = connect(sockfd, (struct sockaddr *) &addr, sizeof(addr));
 
64
        if (status < 0)
 
65
        {
 
66
                perror("connect");
 
67
                close(sockfd);
 
68
                return -1;
 
69
        }
 
70
 
 
71
        return sockfd;
 
72
 
 
73
#else /* ifndef _WIN32 */
 
74
 
 
75
        return -1;
 
76
 
 
77
#endif
 
78
}