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.
7 #ifndef NATIVE_CLIENT_SRC_PUBLIC_LINUX_SYSCALLS_INCLUDE_SYS_SOCKET_H_
8 #define NATIVE_CLIENT_SRC_PUBLIC_LINUX_SYSCALLS_INCLUDE_SYS_SOCKET_H_
11 #include <sys/types.h>
20 #define SOCK_SEQPACKET 5
30 #define MSG_CTRUNC 0x8
31 #define MSG_TRUNC 0x20
32 #define MSG_DONTWAIT 0x40
33 #define MSG_NOSIGNAL 0x4000
35 typedef uint32_t socklen_t;
44 socklen_t msg_namelen;
46 struct iovec *msg_iov;
50 size_t msg_controllen;
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]);
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)))
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;
79 return (struct cmsghdr *) __mhdr->msg_control;
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;