1/*
2 * Copyright (C) 2008 The Android Open Source Project
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 *  * Redistributions of source code must retain the above copyright
9 *    notice, this list of conditions and the following disclaimer.
10 *  * Redistributions in binary form must reproduce the above copyright
11 *    notice, this list of conditions and the following disclaimer in
12 *    the documentation and/or other materials provided with the
13 *    distribution.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
16 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
17 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
18 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
19 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
21 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
22 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
23 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
24 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
25 * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
26 * SUCH DAMAGE.
27 */
28#ifndef _SYS_SOCKET_H_
29#define _SYS_SOCKET_H_
30
31#include <sys/cdefs.h>
32#include <sys/types.h>
33#include <linux/socket.h>
34
35#include <asm/socket.h>
36#include <linux/sockios.h>
37#include <linux/uio.h>
38#include <linux/types.h>
39#include <linux/compiler.h>
40
41__BEGIN_DECLS
42
43#define sockaddr_storage __kernel_sockaddr_storage
44typedef __sa_family_t sa_family_t;
45typedef int socklen_t;
46
47#ifdef __mips__
48#define SOCK_DGRAM      1
49#define SOCK_STREAM     2
50#define SOCK_RAW        3
51#define SOCK_RDM        4
52#define SOCK_SEQPACKET  5
53#define SOCK_DCCP       6
54#define SOCK_PACKET     10
55#else
56#define SOCK_STREAM      1
57#define SOCK_DGRAM       2
58#define SOCK_RAW         3
59#define SOCK_RDM         4
60#define SOCK_SEQPACKET   5
61#define SOCK_PACKET      10
62#endif
63
64/* BIONIC: second argument to shutdown() */
65enum {
66    SHUT_RD = 0,        /* no more receptions */
67#define SHUT_RD         SHUT_RD
68    SHUT_WR,            /* no more transmissions */
69#define SHUT_WR         SHUT_WR
70    SHUT_RDWR           /* no more receptions or transmissions */
71#define SHUT_RDWR       SHUT_RDWR
72};
73
74struct sockaddr {
75 sa_family_t sa_family;
76 char sa_data[14];
77};
78
79struct linger {
80 int l_onoff;
81 int l_linger;
82};
83
84struct msghdr {
85 void * msg_name;
86 int msg_namelen;
87 struct iovec * msg_iov;
88 __kernel_size_t msg_iovlen;
89 void * msg_control;
90 __kernel_size_t msg_controllen;
91 unsigned msg_flags;
92};
93
94struct cmsghdr {
95 __kernel_size_t cmsg_len;
96 int cmsg_level;
97 int cmsg_type;
98};
99
100#define __CMSG_NXTHDR(ctl, len, cmsg) __cmsg_nxthdr((ctl),(len),(cmsg))
101#define CMSG_NXTHDR(mhdr, cmsg) cmsg_nxthdr((mhdr), (cmsg))
102#define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
103#define CMSG_DATA(cmsg) ((void *)((char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
104#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
105#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
106#define __CMSG_FIRSTHDR(ctl,len) ((len) >= sizeof(struct cmsghdr) ?   (struct cmsghdr *)(ctl) :   (struct cmsghdr *)NULL)
107#define CMSG_FIRSTHDR(msg) __CMSG_FIRSTHDR((msg)->msg_control, (msg)->msg_controllen)
108#define CMSG_OK(mhdr, cmsg) ((cmsg)->cmsg_len >= sizeof(struct cmsghdr) &&   (cmsg)->cmsg_len <= (unsigned long)   ((mhdr)->msg_controllen -   ((char *)(cmsg) - (char *)(mhdr)->msg_control)))
109
110#ifdef __GNUC__
111#define __KINLINE static __inline__
112#elif defined(__cplusplus)
113#define __KINLINE static inline
114#else
115#define __KINLINE static
116#endif
117
118__KINLINE struct cmsghdr * __cmsg_nxthdr(void *__ctl, __kernel_size_t __size, struct cmsghdr *__cmsg) {
119 struct cmsghdr * __ptr;
120 __ptr = (struct cmsghdr*)(((unsigned char *) __cmsg) + CMSG_ALIGN(__cmsg->cmsg_len));
121 if ((unsigned long)((char*)(__ptr+1) - (char *) __ctl) > __size)
122 return (struct cmsghdr *)0;
123 return __ptr;
124}
125
126__KINLINE struct cmsghdr * cmsg_nxthdr (struct msghdr *__msg, struct cmsghdr *__cmsg) {
127 return __cmsg_nxthdr(__msg->msg_control, __msg->msg_controllen, __cmsg);
128}
129
130#define SCM_RIGHTS 0x01
131#define SCM_CREDENTIALS 0x02
132#define SCM_SECURITY 0x03
133
134struct ucred {
135 __u32 pid;
136 __u32 uid;
137 __u32 gid;
138};
139
140#define AF_UNSPEC 0
141#define AF_UNIX 1
142#define AF_LOCAL 1
143#define AF_INET 2
144#define AF_AX25 3
145#define AF_IPX 4
146#define AF_APPLETALK 5
147#define AF_NETROM 6
148#define AF_BRIDGE 7
149#define AF_ATMPVC 8
150#define AF_X25 9
151#define AF_INET6 10
152#define AF_ROSE 11
153#define AF_DECnet 12
154#define AF_NETBEUI 13
155#define AF_SECURITY 14
156#define AF_KEY 15
157#define AF_NETLINK 16
158#define AF_ROUTE AF_NETLINK
159#define AF_PACKET 17
160#define AF_ASH 18
161#define AF_ECONET 19
162#define AF_ATMSVC 20
163#define AF_SNA 22
164#define AF_IRDA 23
165#define AF_PPPOX 24
166#define AF_WANPIPE 25
167#define AF_LLC 26
168#define AF_TIPC 30
169#define AF_BLUETOOTH 31
170#define AF_CAIF 38
171#define AF_MAX 39
172
173#define PF_UNSPEC AF_UNSPEC
174#define PF_UNIX AF_UNIX
175#define PF_LOCAL AF_LOCAL
176#define PF_INET AF_INET
177#define PF_AX25 AF_AX25
178#define PF_IPX AF_IPX
179#define PF_APPLETALK AF_APPLETALK
180#define PF_NETROM AF_NETROM
181#define PF_BRIDGE AF_BRIDGE
182#define PF_ATMPVC AF_ATMPVC
183#define PF_X25 AF_X25
184#define PF_INET6 AF_INET6
185#define PF_ROSE AF_ROSE
186#define PF_DECnet AF_DECnet
187#define PF_NETBEUI AF_NETBEUI
188#define PF_SECURITY AF_SECURITY
189#define PF_KEY AF_KEY
190#define PF_NETLINK AF_NETLINK
191#define PF_ROUTE AF_ROUTE
192#define PF_PACKET AF_PACKET
193#define PF_ASH AF_ASH
194#define PF_ECONET AF_ECONET
195#define PF_ATMSVC AF_ATMSVC
196#define PF_SNA AF_SNA
197#define PF_IRDA AF_IRDA
198#define PF_PPPOX AF_PPPOX
199#define PF_WANPIPE AF_WANPIPE
200#define PF_LLC AF_LLC
201#define PF_TIPC AF_TIPC
202#define PF_BLUETOOTH AF_BLUETOOTH
203#define PF_CAIF AF_CAIF
204#define PF_MAX AF_MAX
205
206#define SOMAXCONN 128
207
208#define MSG_OOB 1
209#define MSG_PEEK 2
210#define MSG_DONTROUTE 4
211#define MSG_TRYHARD 4
212#define MSG_CTRUNC 8
213#define MSG_PROBE 0x10
214#define MSG_TRUNC 0x20
215#define MSG_DONTWAIT 0x40
216#define MSG_EOR 0x80
217#define MSG_WAITALL 0x100
218#define MSG_FIN 0x200
219#define MSG_SYN 0x400
220#define MSG_CONFIRM 0x800
221#define MSG_RST 0x1000
222#define MSG_ERRQUEUE 0x2000
223#define MSG_NOSIGNAL 0x4000
224#define MSG_MORE 0x8000
225#define MSG_EOF MSG_FIN
226#define MSG_CMSG_COMPAT 0
227
228#define SOL_IP 0
229#define SOL_TCP 6
230#define SOL_UDP 17
231#define SOL_IPV6 41
232#define SOL_ICMPV6 58
233#define SOL_SCTP 132
234#define SOL_RAW 255
235#define SOL_IPX 256
236#define SOL_AX25 257
237#define SOL_ATALK 258
238#define SOL_NETROM 259
239#define SOL_ROSE 260
240#define SOL_DECNET 261
241#define SOL_X25 262
242#define SOL_PACKET 263
243#define SOL_ATM 264
244#define SOL_AAL 265
245#define SOL_IRDA 266
246#define SOL_NETBEUI 267
247#define SOL_LLC 268
248#define SOL_DCCP 269
249#define SOL_NETLINK 270
250#define SOL_TIPC 271
251
252#define IPX_TYPE 1
253
254#ifdef __i386__
255# define __socketcall extern __attribute__((__cdecl__))
256#else
257# define __socketcall extern
258#endif
259
260__socketcall int socket(int, int, int);
261__socketcall int bind(int, const struct sockaddr *, int);
262__socketcall int connect(int, const struct sockaddr *, socklen_t);
263__socketcall int listen(int, int);
264__socketcall int accept(int, struct sockaddr *, socklen_t *);
265__socketcall int getsockname(int, struct sockaddr *, socklen_t *);
266__socketcall int getpeername(int, struct sockaddr *, socklen_t *);
267__socketcall int socketpair(int, int, int, int *);
268__socketcall int shutdown(int, int);
269__socketcall int setsockopt(int, int, int, const void *, socklen_t);
270__socketcall int getsockopt(int, int, int, void *, socklen_t *);
271__socketcall int sendmsg(int, const struct msghdr *, unsigned int);
272__socketcall int recvmsg(int, struct msghdr *, unsigned int);
273
274extern  ssize_t  send(int, const void *, size_t, unsigned int);
275extern  ssize_t  recv(int, void *, size_t, unsigned int);
276
277__socketcall ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);
278__socketcall ssize_t recvfrom(int, void *, size_t, unsigned int, const struct sockaddr *, socklen_t *);
279
280#undef __socketcall
281
282__END_DECLS
283
284#endif /* _SYS_SOCKET_H */
285