]> git.proxmox.com Git - mirror_ovs.git/blame - include/sparse/sys/socket.h
socket-util: Support sendmmsg() regardless of platform.
[mirror_ovs.git] / include / sparse / sys / socket.h
CommitLineData
6506f45c 1/*
32383c3b 2 * Copyright (c) 2011, 2012, 2013 Nicira, Inc.
6506f45c
BP
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>
4d3daf04 26#include <stddef.h>
6506f45c
BP
27
28typedef unsigned short int sa_family_t;
29typedef __socklen_t socklen_t;
30
31struct sockaddr {
32 sa_family_t sa_family;
33 char sa_data[64];
34};
35
36struct sockaddr_storage {
37 sa_family_t ss_family;
38 char sa_data[64];
39};
40
41struct 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
fd94a42c
BP
51struct 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
68static 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
8a8c1b93
BP
78struct mmsghdr {
79 struct msghdr msg_hdr;
80 unsigned int msg_len;
81};
82
fd94a42c
BP
83enum {
84 SCM_RIGHTS = 1
85};
86
6506f45c
BP
87enum {
88 SOCK_DGRAM,
89 SOCK_RAW,
90 SOCK_SEQPACKET,
91 SOCK_STREAM
92};
93
94enum {
b73c8518 95 SOL_PACKET,
6506f45c
BP
96 SOL_SOCKET
97};
98
99enum {
100 SO_ACCEPTCONN,
101 SO_BROADCAST,
102 SO_DEBUG,
103 SO_DONTROUTE,
104 SO_ERROR,
105 SO_KEEPALIVE,
106 SO_LINGER,
107 SO_OOBINLINE,
108 SO_RCVBUF,
109 SO_RCVLOWAT,
110 SO_RCVTIMEO,
111 SO_REUSEADDR,
112 SO_SNDBUF,
113 SO_SNDLOWAT,
114 SO_SNDTIMEO,
d2b9f5b0 115 SO_TYPE,
32383c3b
MM
116 SO_RCVBUFFORCE,
117 SO_ATTACH_FILTER
6506f45c
BP
118};
119
120enum {
121 MSG_CTRUNC,
122 MSG_DONTROUTE,
123 MSG_EOR,
124 MSG_OOB,
125 MSG_NOSIGNAL,
126 MSG_PEEK,
127 MSG_TRUNC,
128 MSG_WAITALL,
129 MSG_DONTWAIT
130};
131
132enum {
133 AF_UNSPEC,
134 PF_UNSPEC = AF_UNSPEC,
135 AF_INET,
136 PF_INET = AF_INET,
137 AF_INET6,
138 PF_INET6 = AF_INET6,
139 AF_UNIX,
140 PF_UNIX = AF_UNIX,
141 AF_NETLINK,
142 PF_NETLINK = AF_NETLINK,
143 AF_PACKET,
144 PF_PACKET = AF_PACKET
145};
146
147enum {
148 SHUT_RD,
149 SHUT_RDWR,
150 SHUT_WR
151};
152
153int accept(int, struct sockaddr *, socklen_t *);
154int bind(int, const struct sockaddr *, socklen_t);
155int connect(int, const struct sockaddr *, socklen_t);
156int getpeername(int, struct sockaddr *, socklen_t *);
157int getsockname(int, struct sockaddr *, socklen_t *);
158int getsockopt(int, int, int, void *, socklen_t *);
159int listen(int, int);
160ssize_t recv(int, void *, size_t, int);
161ssize_t recvfrom(int, void *, size_t, int, struct sockaddr *, socklen_t *);
162ssize_t recvmsg(int, struct msghdr *, int);
163ssize_t send(int, const void *, size_t, int);
164ssize_t sendmsg(int, const struct msghdr *, int);
165ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *,
166 socklen_t);
167int setsockopt(int, int, int, const void *, socklen_t);
168int shutdown(int, int);
169int sockatmark(int);
170int socket(int, int, int);
171int socketpair(int, int, int, int[2]);
172
173#endif /* <sys/socket.h> for sparse */