1#ifndef _LINUX_SOCKET_H
2#define _LINUX_SOCKET_H
3
4
5#include <asm/socket.h>
6#include <linux/sockios.h>
7#include <linux/uio.h>
8#include <linux/types.h>
9#include <linux/compiler.h>
10#include <uapi/linux/socket.h>
11
12struct pid;
13struct cred;
14
15#define __sockaddr_check_size(size) \
16 BUILD_BUG_ON(((size) > sizeof(struct __kernel_sockaddr_storage)))
17
18#ifdef CONFIG_PROC_FS
19struct seq_file;
20extern void socket_seq_show(struct seq_file *seq);
21#endif
22
23typedef __kernel_sa_family_t sa_family_t;
24
25
26
27
28
29struct sockaddr {
30 sa_family_t sa_family;
31 char sa_data[14];
32};
33
34struct linger {
35 int l_onoff;
36 int l_linger;
37};
38
39#define sockaddr_storage __kernel_sockaddr_storage
40
41
42
43
44
45
46
47struct msghdr {
48 void *msg_name;
49 int msg_namelen;
50 struct iov_iter msg_iter;
51 void *msg_control;
52 __kernel_size_t msg_controllen;
53 unsigned int msg_flags;
54 struct kiocb *msg_iocb;
55};
56
57struct user_msghdr {
58 void __user *msg_name;
59 int msg_namelen;
60 struct iovec __user *msg_iov;
61 __kernel_size_t msg_iovlen;
62 void __user *msg_control;
63 __kernel_size_t msg_controllen;
64 unsigned int msg_flags;
65};
66
67
68struct mmsghdr {
69 struct user_msghdr msg_hdr;
70 unsigned int msg_len;
71};
72
73
74
75
76
77
78
79struct cmsghdr {
80 __kernel_size_t cmsg_len;
81 int cmsg_level;
82 int cmsg_type;
83};
84
85
86
87
88
89
90#define __CMSG_NXTHDR(ctl, len, cmsg) __cmsg_nxthdr((ctl),(len),(cmsg))
91#define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg))
92
93#define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
94
95#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
96#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
97#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
98
99#define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ? \
100 (struct cmsghdr *)(ctl) : \
101 (struct cmsghdr *)NULL)
102#define CMSG_FIRSTHDR(msg) __CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen)
103#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) && \
104 (cmsg)->cmsg_len <= (unsigned long) \
105 ((mhdr)->msg_controllen - \
106 ((char *)(cmsg) - (char *)(mhdr)->msg_control)))
107#define for_each_cmsghdr(cmsg, msg) \
108 for (cmsg = CMSG_FIRSTHDR(msg); \
109 cmsg; \
110 cmsg = CMSG_NXTHDR(msg, cmsg))
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125static inline struct cmsghdr * __cmsg_nxthdr(void *__ctl, __kernel_size_t __size,
126 struct cmsghdr *__cmsg)
127{
128 struct cmsghdr * __ptr;
129
130 __ptr = (struct cmsghdr*)(((unsigned char *) __cmsg) + CMSG_ALIGN(__cmsg->cmsg_len));
131 if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
132 return (struct cmsghdr *)0;
133
134 return __ptr;
135}
136
137static inline struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__cmsg)
138{
139 return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
140}
141
142static inline size_t msg_data_left(struct msghdr *msg)
143{
144 return iov_iter_count(&msg->msg_iter);
145}
146
147
148
149#define SCM_RIGHTS 0x01
150#define SCM_CREDENTIALS 0x02
151#define SCM_SECURITY 0x03
152
153struct ucred {
154 __u32 pid;
155 __u32 uid;
156 __u32 gid;
157};
158
159
160#define AF_UNSPEC 0
161#define AF_UNIX 1
162#define AF_LOCAL 1
163#define AF_INET 2
164#define AF_AX25 3
165#define AF_IPX 4
166#define AF_APPLETALK 5
167#define AF_NETROM 6
168#define AF_BRIDGE 7
169#define AF_ATMPVC 8
170#define AF_X25 9
171#define AF_INET6 10
172#define AF_ROSE 11
173#define AF_DECnet 12
174#define AF_NETBEUI 13
175#define AF_SECURITY 14
176#define AF_KEY 15
177#define AF_NETLINK 16
178#define AF_ROUTE AF_NETLINK
179#define AF_PACKET 17
180#define AF_ASH 18
181#define AF_ECONET 19
182#define AF_ATMSVC 20
183#define AF_RDS 21
184#define AF_SNA 22
185#define AF_IRDA 23
186#define AF_PPPOX 24
187#define AF_WANPIPE 25
188#define AF_LLC 26
189#define AF_IB 27
190#define AF_MPLS 28
191#define AF_CAN 29
192#define AF_TIPC 30
193#define AF_BLUETOOTH 31
194#define AF_IUCV 32
195#define AF_RXRPC 33
196#define AF_ISDN 34
197#define AF_PHONET 35
198#define AF_IEEE802154 36
199#define AF_CAIF 37
200#define AF_ALG 38
201#define AF_NFC 39
202#define AF_VSOCK 40
203#define AF_KCM 41
204#define AF_QIPCRTR 42
205
206#define AF_MAX 43
207
208
209#define PF_UNSPEC AF_UNSPEC
210#define PF_UNIX AF_UNIX
211#define PF_LOCAL AF_LOCAL
212#define PF_INET AF_INET
213#define PF_AX25 AF_AX25
214#define PF_IPX AF_IPX
215#define PF_APPLETALK AF_APPLETALK
216#define PF_NETROM AF_NETROM
217#define PF_BRIDGE AF_BRIDGE
218#define PF_ATMPVC AF_ATMPVC
219#define PF_X25 AF_X25
220#define PF_INET6 AF_INET6
221#define PF_ROSE AF_ROSE
222#define PF_DECnet AF_DECnet
223#define PF_NETBEUI AF_NETBEUI
224#define PF_SECURITY AF_SECURITY
225#define PF_KEY AF_KEY
226#define PF_NETLINK AF_NETLINK
227#define PF_ROUTE AF_ROUTE
228#define PF_PACKET AF_PACKET
229#define PF_ASH AF_ASH
230#define PF_ECONET AF_ECONET
231#define PF_ATMSVC AF_ATMSVC
232#define PF_RDS AF_RDS
233#define PF_SNA AF_SNA
234#define PF_IRDA AF_IRDA
235#define PF_PPPOX AF_PPPOX
236#define PF_WANPIPE AF_WANPIPE
237#define PF_LLC AF_LLC
238#define PF_IB AF_IB
239#define PF_MPLS AF_MPLS
240#define PF_CAN AF_CAN
241#define PF_TIPC AF_TIPC
242#define PF_BLUETOOTH AF_BLUETOOTH
243#define PF_IUCV AF_IUCV
244#define PF_RXRPC AF_RXRPC
245#define PF_ISDN AF_ISDN
246#define PF_PHONET AF_PHONET
247#define PF_IEEE802154 AF_IEEE802154
248#define PF_CAIF AF_CAIF
249#define PF_ALG AF_ALG
250#define PF_NFC AF_NFC
251#define PF_VSOCK AF_VSOCK
252#define PF_KCM AF_KCM
253#define PF_QIPCRTR AF_QIPCRTR
254#define PF_MAX AF_MAX
255
256
257#define SOMAXCONN 128
258
259
260
261
262
263#define MSG_OOB 1
264#define MSG_PEEK 2
265#define MSG_DONTROUTE 4
266#define MSG_TRYHARD 4
267#define MSG_CTRUNC 8
268#define MSG_PROBE 0x10
269#define MSG_TRUNC 0x20
270#define MSG_DONTWAIT 0x40
271#define MSG_EOR 0x80
272#define MSG_WAITALL 0x100
273#define MSG_FIN 0x200
274#define MSG_SYN 0x400
275#define MSG_CONFIRM 0x800
276#define MSG_RST 0x1000
277#define MSG_ERRQUEUE 0x2000
278#define MSG_NOSIGNAL 0x4000
279#define MSG_MORE 0x8000
280#define MSG_WAITFORONE 0x10000
281#define MSG_SENDPAGE_NOTLAST 0x20000
282#define MSG_BATCH 0x40000
283#define MSG_EOF MSG_FIN
284
285#define MSG_FASTOPEN 0x20000000
286#define MSG_CMSG_CLOEXEC 0x40000000
287
288
289#if defined(CONFIG_COMPAT)
290#define MSG_CMSG_COMPAT 0x80000000
291#else
292#define MSG_CMSG_COMPAT 0
293#endif
294
295
296
297#define SOL_IP 0
298
299#define SOL_TCP 6
300#define SOL_UDP 17
301#define SOL_IPV6 41
302#define SOL_ICMPV6 58
303#define SOL_SCTP 132
304#define SOL_UDPLITE 136
305#define SOL_RAW 255
306#define SOL_IPX 256
307#define SOL_AX25 257
308#define SOL_ATALK 258
309#define SOL_NETROM 259
310#define SOL_ROSE 260
311#define SOL_DECNET 261
312#define SOL_X25 262
313#define SOL_PACKET 263
314#define SOL_ATM 264
315#define SOL_AAL 265
316#define SOL_IRDA 266
317#define SOL_NETBEUI 267
318#define SOL_LLC 268
319#define SOL_DCCP 269
320#define SOL_NETLINK 270
321#define SOL_TIPC 271
322#define SOL_RXRPC 272
323#define SOL_PPPOL2TP 273
324#define SOL_BLUETOOTH 274
325#define SOL_PNPIPE 275
326#define SOL_RDS 276
327#define SOL_IUCV 277
328#define SOL_CAIF 278
329#define SOL_ALG 279
330#define SOL_NFC 280
331#define SOL_KCM 281
332
333
334#define IPX_TYPE 1
335
336extern int move_addr_to_kernel(void __user *uaddr, int ulen, struct sockaddr_storage *kaddr);
337extern int put_cmsg(struct msghdr*, int level, int type, int len, void *data);
338
339struct timespec;
340
341
342extern long __sys_recvmsg(int fd, struct user_msghdr __user *msg, unsigned flags);
343extern long __sys_sendmsg(int fd, struct user_msghdr __user *msg, unsigned flags);
344extern int __sys_recvmmsg(int fd, struct mmsghdr __user *mmsg, unsigned int vlen,
345 unsigned int flags, struct timespec *timeout);
346extern int __sys_sendmmsg(int fd, struct mmsghdr __user *mmsg,
347 unsigned int vlen, unsigned int flags);
348#endif
349