64b905e543fb1b11b7b7d1cbce10092b5d188959
[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
27 typedef unsigned short int sa_family_t;
28 typedef __socklen_t socklen_t;
29
30 struct sockaddr {
31     sa_family_t sa_family;
32     char sa_data[64];
33 };
34
35 struct sockaddr_storage {
36     sa_family_t ss_family;
37     char sa_data[64];
38 };
39
40 struct msghdr {
41     void *msg_name;
42     socklen_t      msg_namelen;
43     struct iovec  *msg_iov;
44     int            msg_iovlen;
45     void          *msg_control;
46     socklen_t      msg_controllen;
47     int            msg_flags;
48 };
49
50 struct cmsghdr {
51     size_t cmsg_len;
52     int cmsg_level;
53     int cmsg_type;
54     unsigned char cmsg_data[];
55 };
56
57 #define __CMSG_ALIGNTO sizeof(size_t)
58 #define CMSG_ALIGN(LEN) \
59         (((LEN) + __CMSG_ALIGNTO - 1) / __CMSG_ALIGNTO * __CMSG_ALIGNTO)
60 #define CMSG_DATA(CMSG) ((CMSG)->cmsg_data)
61 #define CMSG_LEN(LEN) (sizeof(struct cmsghdr) + (LEN))
62 #define CMSG_SPACE(LEN) CMSG_ALIGN(CMSG_LEN(LEN))
63 #define CMSG_FIRSTHDR(MSG) \
64     ((MSG)->msg_controllen ? (struct cmsghdr *) (MSG)->msg_control : NULL)
65 #define CMSG_NXTHDR(MSG, CMSG) __cmsg_nxthdr(MSG, CMSG)
66
67 static inline struct cmsghdr *
68 __cmsg_nxthdr(struct msghdr *msg, struct cmsghdr *cmsg)
69 {
70     size_t ofs = (char *) cmsg - (char *) msg->msg_control;
71     size_t next_ofs = ofs + CMSG_ALIGN(cmsg->cmsg_len);
72     return (next_ofs < msg->msg_controllen
73             ? (void *) ((char *) msg->msg_control + next_ofs)
74             : NULL);
75 }
76
77 enum {
78     SCM_RIGHTS = 1
79 };
80
81 enum {
82     SOCK_DGRAM,
83     SOCK_RAW,
84     SOCK_SEQPACKET,
85     SOCK_STREAM
86 };
87
88 enum {
89     SOL_SOCKET
90 };
91
92 enum {
93     SO_ACCEPTCONN,
94     SO_BROADCAST,
95     SO_DEBUG,
96     SO_DONTROUTE,
97     SO_ERROR,
98     SO_KEEPALIVE,
99     SO_LINGER,
100     SO_OOBINLINE,
101     SO_RCVBUF,
102     SO_RCVLOWAT,
103     SO_RCVTIMEO,
104     SO_REUSEADDR,
105     SO_SNDBUF,
106     SO_SNDLOWAT,
107     SO_SNDTIMEO,
108     SO_TYPE,
109     SO_RCVBUFFORCE,
110     SO_ATTACH_FILTER
111 };
112
113 enum {
114     MSG_CTRUNC,
115     MSG_DONTROUTE,
116     MSG_EOR,
117     MSG_OOB,
118     MSG_NOSIGNAL,
119     MSG_PEEK,
120     MSG_TRUNC,
121     MSG_WAITALL,
122     MSG_DONTWAIT
123 };
124
125 enum {
126     AF_UNSPEC,
127     PF_UNSPEC = AF_UNSPEC,
128     AF_INET,
129     PF_INET = AF_INET,
130     AF_INET6,
131     PF_INET6 = AF_INET6,
132     AF_UNIX,
133     PF_UNIX = AF_UNIX,
134     AF_NETLINK,
135     PF_NETLINK = AF_NETLINK,
136     AF_PACKET,
137     PF_PACKET = AF_PACKET
138 };
139
140 enum {
141     SHUT_RD,
142     SHUT_RDWR,
143     SHUT_WR
144 };
145
146 int accept(int, struct sockaddr *, socklen_t *);
147 int bind(int, const struct sockaddr *, socklen_t);
148 int connect(int, const struct sockaddr *, socklen_t);
149 int getpeername(int, struct sockaddr *, socklen_t *);
150 int getsockname(int, struct sockaddr *, socklen_t *);
151 int getsockopt(int, int, int, void *, socklen_t *);
152 int listen(int, int);
153 ssize_t recv(int, void *, size_t, int);
154 ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
155 ssize_t recvmsg(int, struct msghdr *, int);
156 ssize_t send(int, const void *, size_t, int);
157 ssize_t sendmsg(int, const struct msghdr *, int);
158 ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
159                socklen_t);
160 int setsockopt(int, int, int, const void *, socklen_t);
161 int shutdown(int, int);
162 int sockatmark(int);
163 int socket(int, int, int);
164 int socketpair(int, int, int, int[2]);
165
166 #endif /* <sys/socket.h> for sparse */