Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / native_client / src / public / linux_syscalls / sys / socket.h
1 /*
2  * Copyright 2014 The Native Client Authors. All rights reserved.
3  * Use of this source code is governed by a BSD-style license that can be
4  * found in the LICENSE file.
5  */
6
7 #ifndef NATIVE_CLIENT_SRC_PUBLIC_LINUX_SYSCALLS_INCLUDE_SYS_SOCKET_H_
8 #define NATIVE_CLIENT_SRC_PUBLIC_LINUX_SYSCALLS_INCLUDE_SYS_SOCKET_H_
9
10 #include <stdint.h>
11 #include <sys/types.h>
12
13 #ifdef __cplusplus
14 extern "C" {
15 #endif
16
17 #define AF_UNIX 1
18 #define SOCK_STREAM 1
19 #define SOCK_DGRAM 2
20 #define SOCK_SEQPACKET 5
21
22 #define SOL_SOCKET 1
23
24 #define SHUT_RD 0
25 #define SHUT_WR 1
26 #define SHUT_RDWR 2
27
28 #define SCM_RIGHTS 1
29
30 #define MSG_CTRUNC 0x8
31 #define MSG_TRUNC 0x20
32 #define MSG_DONTWAIT 0x40
33 #define MSG_NOSIGNAL 0x4000
34
35 typedef uint32_t socklen_t;
36
37 struct iovec {
38   void *iov_base;
39   size_t iov_len;
40 };
41
42 struct msghdr {
43   void *msg_name;
44   socklen_t msg_namelen;
45
46   struct iovec *msg_iov;
47   size_t msg_iovlen;
48
49   void *msg_control;
50   size_t msg_controllen;
51
52   int msg_flags;
53 };
54
55 struct cmsghdr {
56   socklen_t cmsg_len;
57   int cmsg_level;
58   int cmsg_type;
59 };
60
61 ssize_t recv(int sockfd, void *buf, size_t len, int flags);
62 ssize_t send(int sockfd, const void *buf, size_t len, int flags);
63 ssize_t recvmsg(int sockfd, struct msghdr *msg, int flags);
64 ssize_t sendmsg(int sockfd, const struct msghdr *msg, int flags);
65 int shutdown(int sockfd, int how);
66 int socketpair(int domain, int type, int protocol, int sv[2]);
67
68 #define CMSG_ALIGN(len) (((len) + sizeof(size_t) - 1) & ~(sizeof(size_t) - 1))
69 #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
70 #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
71 #define CMSG_DATA(cmsg) \
72     ((unsigned char *) ((uintptr_t) (cmsg) + sizeof(struct cmsghdr)))
73
74 #define CMSG_FIRSTHDR(mhdr) __cmsg_firsthdr(mhdr)
75 static __inline__ struct cmsghdr *__cmsg_firsthdr(struct msghdr *__mhdr) {
76   if (__mhdr->msg_controllen < sizeof(struct cmsghdr)) {
77     return (struct cmsghdr *) 0;
78   }
79   return (struct cmsghdr *) __mhdr->msg_control;
80 }
81
82 #define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr(mhdr, cmsg)
83 static __inline__ struct cmsghdr *__cmsg_nxthdr(struct msghdr *__mhdr,
84                                                 struct cmsghdr *__cmsg) {
85   struct cmsghdr *__next =
86       (struct cmsghdr *) ((uintptr_t) __cmsg + CMSG_ALIGN(__cmsg->cmsg_len));
87   if ((uintptr_t) (__next + 1) >
88       (uintptr_t) __mhdr->msg_control + __mhdr->msg_controllen) {
89     return (struct cmsghdr *) 0;
90   }
91   return __next;
92 }
93
94 #ifdef __cplusplus
95 }
96 #endif
97
98 #endif