2 * Copyright (c) 2000 Assar Westerlund
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer
10 * in this position and unchanged.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
14 * 3. The name of the author may not be used to endorse or promote products
15 * derived from this software without specific prior written permission
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31 #ifndef _LINUX_SOCKET_H_
32 #define _LINUX_SOCKET_H_
34 /* msg flags in recvfrom/recvmsg */
36 #define LINUX_MSG_OOB 0x01
37 #define LINUX_MSG_PEEK 0x02
38 #define LINUX_MSG_DONTROUTE 0x04
39 #define LINUX_MSG_CTRUNC 0x08
40 #define LINUX_MSG_PROXY 0x10
41 #define LINUX_MSG_TRUNC 0x20
42 #define LINUX_MSG_DONTWAIT 0x40
43 #define LINUX_MSG_EOR 0x80
44 #define LINUX_MSG_WAITALL 0x100
45 #define LINUX_MSG_FIN 0x200
46 #define LINUX_MSG_SYN 0x400
47 #define LINUX_MSG_CONFIRM 0x800
48 #define LINUX_MSG_RST 0x1000
49 #define LINUX_MSG_ERRQUEUE 0x2000
50 #define LINUX_MSG_NOSIGNAL 0x4000
51 #define LINUX_MSG_WAITFORONE 0x10000
52 #define LINUX_MSG_CMSG_CLOEXEC 0x40000000
54 /* Socket-level control message types */
56 #define LINUX_SCM_RIGHTS 0x01
57 #define LINUX_SCM_CREDENTIALS 0x02
58 #define LINUX_SCM_TIMESTAMP 0x1D
65 l_uintptr_t msg_control;
66 l_size_t msg_controllen;
71 struct l_msghdr msg_hdr;
82 /* Ancilliary data object information macros */
84 #define LINUX_CMSG_ALIGN(len) roundup2(len, sizeof(l_ulong))
85 #define LINUX_CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + \
86 LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr))))
87 #define LINUX_CMSG_SPACE(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
88 LINUX_CMSG_ALIGN(len))
89 #define LINUX_CMSG_LEN(len) (LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
91 #define LINUX_CMSG_FIRSTHDR(msg) \
92 ((msg)->msg_controllen >= \
93 sizeof(struct l_cmsghdr) ? \
94 (struct l_cmsghdr *) \
95 PTRIN((msg)->msg_control) : \
96 (struct l_cmsghdr *)(NULL))
97 #define LINUX_CMSG_NXTHDR(msg, cmsg) \
99 LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
101 (((char *)PTRIN((msg)->msg_control)) + \
102 (msg)->msg_controllen)) ? \
103 (struct l_cmsghdr *) NULL : \
104 (struct l_cmsghdr *)((char *)(cmsg) + \
105 LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
107 #define CMSG_HDRSZ CMSG_LEN(0)
108 #define L_CMSG_HDRSZ LINUX_CMSG_LEN(0)
110 /* Supported address families */
112 #define LINUX_AF_UNSPEC 0
113 #define LINUX_AF_UNIX 1
114 #define LINUX_AF_INET 2
115 #define LINUX_AF_AX25 3
116 #define LINUX_AF_IPX 4
117 #define LINUX_AF_APPLETALK 5
118 #define LINUX_AF_INET6 10
120 /* Supported socket types */
122 #define LINUX_SOCK_STREAM 1
123 #define LINUX_SOCK_DGRAM 2
124 #define LINUX_SOCK_RAW 3
125 #define LINUX_SOCK_RDM 4
126 #define LINUX_SOCK_SEQPACKET 5
128 #define LINUX_SOCK_MAX LINUX_SOCK_SEQPACKET
130 #define LINUX_SOCK_TYPE_MASK 0xf
132 /* Flags for socket, socketpair, accept4 */
134 #define LINUX_SOCK_CLOEXEC LINUX_O_CLOEXEC
135 #define LINUX_SOCK_NONBLOCK LINUX_O_NONBLOCK
143 #if defined(__i386__) || (defined(__amd64__) && defined(COMPAT_LINUX32))
145 struct linux_sendto_args {
154 struct linux_socket_args {
160 struct linux_bind_args {
166 struct linux_connect_args {
172 struct linux_listen_args {
177 struct linux_accept_args {
183 struct linux_accept4_args {
190 struct linux_getsockname_args {
196 struct linux_getpeername_args {
202 struct linux_socketpair_args {
209 struct linux_recvfrom_args {
218 struct linux_sendmsg_args {
224 struct linux_recvmsg_args {
230 struct linux_shutdown_args {
235 struct linux_setsockopt_args {
243 struct linux_getsockopt_args {
251 int linux_socket(struct thread *td, struct linux_socket_args *args);
252 int linux_bind(struct thread *td, struct linux_bind_args *args);
253 int linux_connect(struct thread *, struct linux_connect_args *);
254 int linux_listen(struct thread *td, struct linux_listen_args *args);
255 int linux_accept(struct thread *td, struct linux_accept_args *args);
256 int linux_accept4(struct thread *td, struct linux_accept4_args *args);
257 int linux_getsockname(struct thread *td, struct linux_getsockname_args *args);
258 int linux_getpeername(struct thread *td, struct linux_getpeername_args *args);
259 int linux_socketpair(struct thread *td, struct linux_socketpair_args *args);
260 int linux_sendto(struct thread *td, struct linux_sendto_args *args);
261 int linux_recvfrom(struct thread *td, struct linux_recvfrom_args *args);
262 int linux_sendmsg(struct thread *td, struct linux_sendmsg_args *args);
263 int linux_recvmsg(struct thread *td, struct linux_recvmsg_args *args);
264 int linux_shutdown(struct thread *td, struct linux_shutdown_args *args);
265 int linux_setsockopt(struct thread *td, struct linux_setsockopt_args *args);
266 int linux_getsockopt(struct thread *td, struct linux_getsockopt_args *args);
268 #endif /* __i386__ || (__amd64__ && COMPAT_LINUX32) */
270 /* Operations for socketcall */
272 #define LINUX_SOCKET 1
274 #define LINUX_CONNECT 3
275 #define LINUX_LISTEN 4
276 #define LINUX_ACCEPT 5
277 #define LINUX_GETSOCKNAME 6
278 #define LINUX_GETPEERNAME 7
279 #define LINUX_SOCKETPAIR 8
281 #define LINUX_RECV 10
282 #define LINUX_SENDTO 11
283 #define LINUX_RECVFROM 12
284 #define LINUX_SHUTDOWN 13
285 #define LINUX_SETSOCKOPT 14
286 #define LINUX_GETSOCKOPT 15
287 #define LINUX_SENDMSG 16
288 #define LINUX_RECVMSG 17
289 #define LINUX_ACCEPT4 18
290 #define LINUX_RECVMMSG 19
291 #define LINUX_SENDMMSG 20
294 #define LINUX_IP_TOS 1
295 #define LINUX_IP_TTL 2
296 #define LINUX_IP_HDRINCL 3
297 #define LINUX_IP_OPTIONS 4
299 #define LINUX_IP_MULTICAST_IF 32
300 #define LINUX_IP_MULTICAST_TTL 33
301 #define LINUX_IP_MULTICAST_LOOP 34
302 #define LINUX_IP_ADD_MEMBERSHIP 35
303 #define LINUX_IP_DROP_MEMBERSHIP 36
305 #define LINUX_TCP_NODELAY 1
306 #define LINUX_TCP_MAXSEG 2
307 #define LINUX_TCP_KEEPIDLE 4
308 #define LINUX_TCP_KEEPINTVL 5
309 #define LINUX_TCP_KEEPCNT 6
310 #define LINUX_TCP_MD5SIG 14
312 #endif /* _LINUX_SOCKET_H_ */