75ee43c6c37b86e1774ddadd1254f430104ac0d1
[sliver-openvswitch.git] / include / sparse / sys / socket.h
1 /*
2  * Copyright (c) 2011, 2012, 2013 Nicira, Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at:
7  *
8  *     http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16
17 #ifndef __CHECKER__
18 #error "Use this header only with sparse.  It is not a correct implementation."
19 #endif
20
21 #ifndef __SYS_SOCKET_SPARSE
22 #define __SYS_SOCKET_SPARSE 1
23
24 #include "openvswitch/types.h"
25 #include <sys/uio.h>
26 #include <stddef.h>
27
28 typedef unsigned short int sa_family_t;
29 typedef __socklen_t socklen_t;
30
31 struct sockaddr {
32     sa_family_t sa_family;
33     char sa_data[64];
34 };
35
36 struct sockaddr_storage {
37     sa_family_t ss_family;
38     char sa_data[64];
39 };
40
41 struct msghdr {
42     void *msg_name;
43     socklen_t      msg_namelen;
44     struct iovec  *msg_iov;
45     int            msg_iovlen;
46     void          *msg_control;
47     socklen_t      msg_controllen;
48     int            msg_flags;
49 };
50
51 struct cmsghdr {
52     size_t cmsg_len;
53     int cmsg_level;
54     int cmsg_type;
55     unsigned char cmsg_data[];
56 };
57
58 #define __CMSG_ALIGNTO sizeof(size_t)
59 #define CMSG_ALIGN(LEN) \
60         (((LEN) + __CMSG_ALIGNTO - 1) / __CMSG_ALIGNTO * __CMSG_ALIGNTO)
61 #define CMSG_DATA(CMSG) ((CMSG)->cmsg_data)
62 #define CMSG_LEN(LEN) (sizeof(struct cmsghdr) + (LEN))
63 #define CMSG_SPACE(LEN) CMSG_ALIGN(CMSG_LEN(LEN))
64 #define CMSG_FIRSTHDR(MSG) \
65     ((MSG)->msg_controllen ? (struct cmsghdr *) (MSG)->msg_control : NULL)
66 #define CMSG_NXTHDR(MSG, CMSG) __cmsg_nxthdr(MSG, CMSG)
67
68 static inline struct cmsghdr *
69 __cmsg_nxthdr(struct msghdr *msg, struct cmsghdr *cmsg)
70 {
71     size_t ofs = (char *) cmsg - (char *) msg->msg_control;
72     size_t next_ofs = ofs + CMSG_ALIGN(cmsg->cmsg_len);
73     return (next_ofs < msg->msg_controllen
74             ? (void *) ((char *) msg->msg_control + next_ofs)
75             : NULL);
76 }
77
78 enum {
79     SCM_RIGHTS = 1
80 };
81
82 enum {
83     SOCK_DGRAM,
84     SOCK_RAW,
85     SOCK_SEQPACKET,
86     SOCK_STREAM
87 };
88
89 enum {
90     SOL_SOCKET
91 };
92
93 enum {
94     SO_ACCEPTCONN,
95     SO_BROADCAST,
96     SO_DEBUG,
97     SO_DONTROUTE,
98     SO_ERROR,
99     SO_KEEPALIVE,
100     SO_LINGER,
101     SO_OOBINLINE,
102     SO_RCVBUF,
103     SO_RCVLOWAT,
104     SO_RCVTIMEO,
105     SO_REUSEADDR,
106     SO_SNDBUF,
107     SO_SNDLOWAT,
108     SO_SNDTIMEO,
109     SO_TYPE,
110     SO_RCVBUFFORCE,
111     SO_ATTACH_FILTER
112 };
113
114 enum {
115     MSG_CTRUNC,
116     MSG_DONTROUTE,
117     MSG_EOR,
118     MSG_OOB,
119     MSG_NOSIGNAL,
120     MSG_PEEK,
121     MSG_TRUNC,
122     MSG_WAITALL,
123     MSG_DONTWAIT
124 };
125
126 enum {
127     AF_UNSPEC,
128     PF_UNSPEC = AF_UNSPEC,
129     AF_INET,
130     PF_INET = AF_INET,
131     AF_INET6,
132     PF_INET6 = AF_INET6,
133     AF_UNIX,
134     PF_UNIX = AF_UNIX,
135     AF_NETLINK,
136     PF_NETLINK = AF_NETLINK,
137     AF_PACKET,
138     PF_PACKET = AF_PACKET
139 };
140
141 enum {
142     SHUT_RD,
143     SHUT_RDWR,
144     SHUT_WR
145 };
146
147 int accept(int, struct sockaddr *, socklen_t *);
148 int bind(int, const struct sockaddr *, socklen_t);
149 int connect(int, const struct sockaddr *, socklen_t);
150 int getpeername(int, struct sockaddr *, socklen_t *);
151 int getsockname(int, struct sockaddr *, socklen_t *);
152 int getsockopt(int, int, int, void *, socklen_t *);
153 int listen(int, int);
154 ssize_t recv(int, void *, size_t, int);
155 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
156 ssize_t recvmsg(int, struct msghdr *, int);
157 ssize_t send(int, const void *, size_t, int);
158 ssize_t sendmsg(int, const struct msghdr *, int);
159 ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
160                socklen_t);
161 int setsockopt(int, int, int, const void *, socklen_t);
162 int shutdown(int, int);
163 int sockatmark(int);
164 int socket(int, int, int);
165 int socketpair(int, int, int, int[2]);
166
167 #endif /* <sys/socket.h> for sparse */