linux_socket.h revision 246085
1238104Sdes/*-
2238104Sdes * Copyright (c) 2000 Assar Westerlund
3238104Sdes * All rights reserved.
4238104Sdes *
5238104Sdes * Redistribution and use in source and binary forms, with or without
6238104Sdes * modification, are permitted provided that the following conditions
7238104Sdes * are met:
8238104Sdes * 1. Redistributions of source code must retain the above copyright
9238104Sdes *    notice, this list of conditions and the following disclaimer
10238104Sdes *    in this position and unchanged.
11238104Sdes * 2. Redistributions in binary form must reproduce the above copyright
12238104Sdes *    notice, this list of conditions and the following disclaimer in the
13238104Sdes *    documentation and/or other materials provided with the distribution.
14238104Sdes * 3. The name of the author may not be used to endorse or promote products
15238104Sdes *    derived from this software without specific prior written permission
16238104Sdes *
17238104Sdes * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
18238104Sdes * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
19238104Sdes * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
20238104Sdes * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
21238104Sdes * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
22238104Sdes * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23238104Sdes * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24238104Sdes * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25238104Sdes * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
26238104Sdes * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27238104Sdes *
28238104Sdes * $FreeBSD: head/sys/compat/linux/linux_socket.h 246085 2013-01-29 18:41:30Z jhb $
29238104Sdes */
30238104Sdes
31238104Sdes#ifndef _LINUX_SOCKET_H_
32238104Sdes#define _LINUX_SOCKET_H_
33238104Sdes
34238104Sdes/* msg flags in recvfrom/recvmsg */
35238104Sdes
36238104Sdes#define LINUX_MSG_OOB		0x01
37238104Sdes#define LINUX_MSG_PEEK		0x02
38238104Sdes#define LINUX_MSG_DONTROUTE	0x04
39238104Sdes#define LINUX_MSG_CTRUNC	0x08
40238104Sdes#define LINUX_MSG_PROXY		0x10
41238104Sdes#define LINUX_MSG_TRUNC		0x20
42238104Sdes#define LINUX_MSG_DONTWAIT	0x40
43238104Sdes#define LINUX_MSG_EOR		0x80
44238104Sdes#define LINUX_MSG_WAITALL	0x100
45238104Sdes#define LINUX_MSG_FIN		0x200
46238104Sdes#define LINUX_MSG_SYN		0x400
47238104Sdes#define LINUX_MSG_CONFIRM	0x800
48238104Sdes#define LINUX_MSG_RST		0x1000
49238104Sdes#define LINUX_MSG_ERRQUEUE	0x2000
50238104Sdes#define LINUX_MSG_NOSIGNAL	0x4000
51238104Sdes#define LINUX_MSG_CMSG_CLOEXEC	0x40000000
52238104Sdes
53238104Sdes/* Socket-level control message types */
54238104Sdes
55238104Sdes#define LINUX_SCM_RIGHTS	0x01
56238104Sdes#define LINUX_SCM_CREDENTIALS   0x02
57238104Sdes
58238104Sdes/* Ancilliary data object information macros */
59238104Sdes
60238104Sdes#define LINUX_CMSG_ALIGN(len)	roundup2(len, sizeof(l_ulong))
61238104Sdes#define LINUX_CMSG_DATA(cmsg)	((void *)((char *)(cmsg) + \
62238104Sdes				    LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr))))
63238104Sdes#define LINUX_CMSG_SPACE(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
64238104Sdes				    LINUX_CMSG_ALIGN(len))
65238104Sdes#define LINUX_CMSG_LEN(len)	(LINUX_CMSG_ALIGN(sizeof(struct l_cmsghdr)) + \
66238104Sdes				    (len))
67238104Sdes#define LINUX_CMSG_FIRSTHDR(msg) \
68238104Sdes				((msg)->msg_controllen >= \
69238104Sdes				    sizeof(struct l_cmsghdr) ? \
70238104Sdes				    (struct l_cmsghdr *) \
71238104Sdes				        PTRIN((msg)->msg_control) : \
72238104Sdes				    (struct l_cmsghdr *)(NULL))
73238104Sdes#define LINUX_CMSG_NXTHDR(msg, cmsg) \
74238104Sdes				((((char *)(cmsg) + \
75238104Sdes				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len) + \
76238104Sdes				    sizeof(*(cmsg))) > \
77238104Sdes				    (((char *)PTRIN((msg)->msg_control)) + \
78238104Sdes				    (msg)->msg_controllen)) ? \
79238104Sdes				    (struct l_cmsghdr *) NULL : \
80238104Sdes				    (struct l_cmsghdr *)((char *)(cmsg) + \
81238104Sdes				    LINUX_CMSG_ALIGN((cmsg)->cmsg_len)))
82238104Sdes
83238104Sdes#define CMSG_HDRSZ		CMSG_LEN(0)
84238104Sdes#define L_CMSG_HDRSZ		LINUX_CMSG_LEN(0)
85238104Sdes
86238104Sdes/* Supported address families */
87238104Sdes
88238104Sdes#define	LINUX_AF_UNSPEC		0
89238104Sdes#define	LINUX_AF_UNIX		1
90238104Sdes#define	LINUX_AF_INET		2
91238104Sdes#define	LINUX_AF_AX25		3
92238104Sdes#define	LINUX_AF_IPX		4
93238104Sdes#define	LINUX_AF_APPLETALK	5
94238104Sdes#define	LINUX_AF_INET6		10
95238104Sdes
96238104Sdes/* Supported socket types */
97238104Sdes
98238104Sdes#define	LINUX_SOCK_STREAM	1
99238104Sdes#define	LINUX_SOCK_DGRAM	2
100238104Sdes#define	LINUX_SOCK_RAW		3
101238104Sdes#define	LINUX_SOCK_RDM		4
102238104Sdes#define	LINUX_SOCK_SEQPACKET	5
103238104Sdes
104238104Sdes#define	LINUX_SOCK_MAX		LINUX_SOCK_SEQPACKET
105238104Sdes
106238104Sdes#define	LINUX_SOCK_TYPE_MASK	0xf
107238104Sdes
108238104Sdes/* Flags for socket, socketpair, accept4 */
109238104Sdes
110238104Sdes#define	LINUX_SOCK_CLOEXEC	LINUX_O_CLOEXEC
111238104Sdes#define	LINUX_SOCK_NONBLOCK	LINUX_O_NONBLOCK
112238104Sdes
113238104Sdesstruct l_ucred {
114238104Sdes	uint32_t	pid;
115238104Sdes	uint32_t	uid;
116238104Sdes	uint32_t	gid;
117238104Sdes};
118238104Sdes
119238104Sdes/* Operations for socketcall */
120238104Sdes
121238104Sdes#define	LINUX_SOCKET 		1
122238104Sdes#define	LINUX_BIND		2
123238104Sdes#define	LINUX_CONNECT 		3
124238104Sdes#define	LINUX_LISTEN 		4
125238104Sdes#define	LINUX_ACCEPT 		5
126238104Sdes#define	LINUX_GETSOCKNAME	6
127238104Sdes#define	LINUX_GETPEERNAME	7
128238104Sdes#define	LINUX_SOCKETPAIR	8
129238104Sdes#define	LINUX_SEND		9
130238104Sdes#define	LINUX_RECV		10
131238104Sdes#define	LINUX_SENDTO 		11
132238104Sdes#define	LINUX_RECVFROM 		12
133238104Sdes#define	LINUX_SHUTDOWN 		13
134238104Sdes#define	LINUX_SETSOCKOPT	14
135238104Sdes#define	LINUX_GETSOCKOPT	15
136238104Sdes#define	LINUX_SENDMSG		16
137238104Sdes#define	LINUX_RECVMSG		17
138238104Sdes#define	LINUX_ACCEPT4		18
139238104Sdes
140238104Sdes/* Socket options */
141238104Sdes#define	LINUX_IP_TOS		1
142238104Sdes#define	LINUX_IP_TTL		2
143238104Sdes#define	LINUX_IP_HDRINCL	3
144238104Sdes#define	LINUX_IP_OPTIONS	4
145238104Sdes
146238104Sdes#define	LINUX_IP_MULTICAST_IF		32
147238104Sdes#define	LINUX_IP_MULTICAST_TTL		33
148238104Sdes#define	LINUX_IP_MULTICAST_LOOP		34
149238104Sdes#define	LINUX_IP_ADD_MEMBERSHIP		35
150238104Sdes#define	LINUX_IP_DROP_MEMBERSHIP	36
151238104Sdes
152238104Sdes#define	LINUX_TCP_NODELAY	1
153238104Sdes#define	LINUX_TCP_MAXSEG	2
154238104Sdes#define	LINUX_TCP_KEEPIDLE	4
155238104Sdes#define	LINUX_TCP_KEEPINTVL	5
156238104Sdes#define	LINUX_TCP_KEEPCNT	6
157238104Sdes#define	LINUX_TCP_MD5SIG	14
158238104Sdes
159238104Sdes#endif /* _LINUX_SOCKET_H_ */
160238104Sdes