blob: 821c483641f8dc997d9badbcf4585de2b72c7da3 [file] [log] [blame]
The Android Open Source Project1dc9e472009-03-03 19:28:35 -08001/*
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 */
Andrei Emeltchenko43d21372013-10-14 16:48:26 +030028
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080029#ifndef _SYS_SOCKET_H_
30#define _SYS_SOCKET_H_
31
32#include <sys/cdefs.h>
33#include <sys/types.h>
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080034
Andrei Emeltchenko43d21372013-10-14 16:48:26 +030035#include <asm/fcntl.h>
Elliott Hughes86ec05a2012-09-11 19:03:02 -070036#include <asm/socket.h>
37#include <linux/sockios.h>
38#include <linux/uio.h>
39#include <linux/types.h>
40#include <linux/compiler.h>
41
Elliott Hughes508d2922016-07-21 16:38:43 -070042#include <bits/sa_family_t.h>
43
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080044__BEGIN_DECLS
45
Elliott Hughesa8b1eb32014-02-28 17:59:29 -080046struct timespec;
47
Greg Hackmannd75abb92015-08-25 17:45:46 -070048#define SOCK_STREAM 1
49#define SOCK_DGRAM 2
Raghu Gandham6437eac2012-08-02 16:50:10 -070050#define SOCK_RAW 3
51#define SOCK_RDM 4
52#define SOCK_SEQPACKET 5
53#define SOCK_DCCP 6
54#define SOCK_PACKET 10
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080055
Andrei Emeltchenko43d21372013-10-14 16:48:26 +030056#define SOCK_CLOEXEC O_CLOEXEC
57#define SOCK_NONBLOCK O_NONBLOCK
58
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080059enum {
Andrei Emeltchenko43d21372013-10-14 16:48:26 +030060 SHUT_RD = 0,
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080061#define SHUT_RD SHUT_RD
Andrei Emeltchenko43d21372013-10-14 16:48:26 +030062 SHUT_WR,
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080063#define SHUT_WR SHUT_WR
Andrei Emeltchenko43d21372013-10-14 16:48:26 +030064 SHUT_RDWR
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080065#define SHUT_RDWR SHUT_RDWR
66};
67
Elliott Hughes86ec05a2012-09-11 19:03:02 -070068struct sockaddr {
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +010069 sa_family_t sa_family;
70 char sa_data[14];
Elliott Hughes86ec05a2012-09-11 19:03:02 -070071};
The Android Open Source Project1dc9e472009-03-03 19:28:35 -080072
zijunzhao4e274fa2023-05-25 18:48:38 +000073#pragma clang diagnostic push
74#pragma clang diagnostic ignored "-Wnullability-completeness"
Colin Crossd2750672021-06-29 12:52:26 -070075struct sockaddr_storage {
76 union {
77 struct {
78 sa_family_t ss_family;
79 char __data[128 - sizeof(sa_family_t)];
80 };
81 void* __align;
82 };
83};
84
Elliott Hughes86ec05a2012-09-11 19:03:02 -070085struct linger {
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +010086 int l_onoff;
87 int l_linger;
Elliott Hughes86ec05a2012-09-11 19:03:02 -070088};
89
90struct msghdr {
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +010091 void* msg_name;
92 socklen_t msg_namelen;
93 struct iovec* msg_iov;
94 size_t msg_iovlen;
95 void* msg_control;
96 size_t msg_controllen;
97 int msg_flags;
98};
99
100struct mmsghdr {
101 struct msghdr msg_hdr;
102 unsigned int msg_len;
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700103};
104
105struct cmsghdr {
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +0100106 size_t cmsg_len;
107 int cmsg_level;
108 int cmsg_type;
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700109};
110
zijunzhao4e274fa2023-05-25 18:48:38 +0000111#pragma clang diagnostic pop
112
Calin Juravle096b4eb2014-06-19 18:16:17 +0100113#define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr((mhdr), (cmsg))
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700114#define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
Dan Albert268af262015-09-11 09:47:27 -0700115#define CMSG_DATA(cmsg) (((unsigned char*)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700116#define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
117#define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
Calin Juravlef1de90b2014-03-19 17:40:23 +0000118#define CMSG_FIRSTHDR(msg) \
119 ((msg)->msg_controllen >= sizeof(struct cmsghdr) \
120 ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +0100121#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)))
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700122
zijunzhao4e274fa2023-05-25 18:48:38 +0000123struct cmsghdr* _Nullable __cmsg_nxthdr(struct msghdr* _Nonnull __msg, struct cmsghdr* _Nonnull __cmsg) __INTRODUCED_IN(21);
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700124
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700125#define SCM_RIGHTS 0x01
126#define SCM_CREDENTIALS 0x02
127#define SCM_SECURITY 0x03
128
129struct ucred {
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +0100130 pid_t pid;
131 uid_t uid;
132 gid_t gid;
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700133};
134
135#define AF_UNSPEC 0
136#define AF_UNIX 1
137#define AF_LOCAL 1
138#define AF_INET 2
139#define AF_AX25 3
140#define AF_IPX 4
141#define AF_APPLETALK 5
142#define AF_NETROM 6
143#define AF_BRIDGE 7
144#define AF_ATMPVC 8
145#define AF_X25 9
146#define AF_INET6 10
147#define AF_ROSE 11
148#define AF_DECnet 12
149#define AF_NETBEUI 13
150#define AF_SECURITY 14
151#define AF_KEY 15
152#define AF_NETLINK 16
153#define AF_ROUTE AF_NETLINK
154#define AF_PACKET 17
155#define AF_ASH 18
156#define AF_ECONET 19
157#define AF_ATMSVC 20
Elliott Hughesd73c0b32013-01-03 16:25:47 -0800158#define AF_RDS 21
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700159#define AF_SNA 22
160#define AF_IRDA 23
161#define AF_PPPOX 24
162#define AF_WANPIPE 25
163#define AF_LLC 26
Elliott Hughesd73c0b32013-01-03 16:25:47 -0800164#define AF_CAN 29
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700165#define AF_TIPC 30
166#define AF_BLUETOOTH 31
Elliott Hughesd73c0b32013-01-03 16:25:47 -0800167#define AF_IUCV 32
168#define AF_RXRPC 33
169#define AF_ISDN 34
170#define AF_PHONET 35
171#define AF_IEEE802154 36
172#define AF_CAIF 37
173#define AF_ALG 38
Greg Hackmannc7ca8f32016-01-28 11:07:26 -0800174#define AF_NFC 39
175#define AF_VSOCK 40
Elliott Hughes8d768712016-12-13 15:29:58 -0800176#define AF_KCM 41
177#define AF_QIPCRTR 42
178#define AF_MAX 43
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700179
180#define PF_UNSPEC AF_UNSPEC
181#define PF_UNIX AF_UNIX
182#define PF_LOCAL AF_LOCAL
183#define PF_INET AF_INET
184#define PF_AX25 AF_AX25
185#define PF_IPX AF_IPX
186#define PF_APPLETALK AF_APPLETALK
187#define PF_NETROM AF_NETROM
188#define PF_BRIDGE AF_BRIDGE
189#define PF_ATMPVC AF_ATMPVC
190#define PF_X25 AF_X25
191#define PF_INET6 AF_INET6
192#define PF_ROSE AF_ROSE
193#define PF_DECnet AF_DECnet
194#define PF_NETBEUI AF_NETBEUI
195#define PF_SECURITY AF_SECURITY
196#define PF_KEY AF_KEY
197#define PF_NETLINK AF_NETLINK
198#define PF_ROUTE AF_ROUTE
199#define PF_PACKET AF_PACKET
200#define PF_ASH AF_ASH
201#define PF_ECONET AF_ECONET
202#define PF_ATMSVC AF_ATMSVC
Elliott Hughesd73c0b32013-01-03 16:25:47 -0800203#define PF_RDS AF_RDS
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700204#define PF_SNA AF_SNA
205#define PF_IRDA AF_IRDA
206#define PF_PPPOX AF_PPPOX
207#define PF_WANPIPE AF_WANPIPE
208#define PF_LLC AF_LLC
Elliott Hughesd73c0b32013-01-03 16:25:47 -0800209#define PF_CAN AF_CAN
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700210#define PF_TIPC AF_TIPC
211#define PF_BLUETOOTH AF_BLUETOOTH
Elliott Hughesd73c0b32013-01-03 16:25:47 -0800212#define PF_IUCV AF_IUCV
213#define PF_RXRPC AF_RXRPC
214#define PF_ISDN AF_ISDN
215#define PF_PHONET AF_PHONET
216#define PF_IEEE802154 AF_IEEE802154
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700217#define PF_CAIF AF_CAIF
Elliott Hughesd73c0b32013-01-03 16:25:47 -0800218#define PF_ALG AF_ALG
Greg Hackmannc7ca8f32016-01-28 11:07:26 -0800219#define PF_NFC AF_NFC
220#define PF_VSOCK AF_VSOCK
Elliott Hughes8d768712016-12-13 15:29:58 -0800221#define PF_KCM AF_KCM
222#define PF_QIPCRTR AF_QIPCRTR
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700223#define PF_MAX AF_MAX
224
225#define SOMAXCONN 128
226
227#define MSG_OOB 1
228#define MSG_PEEK 2
229#define MSG_DONTROUTE 4
230#define MSG_TRYHARD 4
231#define MSG_CTRUNC 8
232#define MSG_PROBE 0x10
233#define MSG_TRUNC 0x20
234#define MSG_DONTWAIT 0x40
235#define MSG_EOR 0x80
236#define MSG_WAITALL 0x100
237#define MSG_FIN 0x200
238#define MSG_SYN 0x400
239#define MSG_CONFIRM 0x800
240#define MSG_RST 0x1000
241#define MSG_ERRQUEUE 0x2000
242#define MSG_NOSIGNAL 0x4000
243#define MSG_MORE 0x8000
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +0100244#define MSG_WAITFORONE 0x10000
Elliott Hughes8d768712016-12-13 15:29:58 -0800245#define MSG_BATCH 0x40000
Guillaume Ranquet6ff0c752014-02-10 13:11:29 +0100246#define MSG_FASTOPEN 0x20000000
247#define MSG_CMSG_CLOEXEC 0x40000000
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700248#define MSG_EOF MSG_FIN
249#define MSG_CMSG_COMPAT 0
250
251#define SOL_IP 0
252#define SOL_TCP 6
253#define SOL_UDP 17
254#define SOL_IPV6 41
255#define SOL_ICMPV6 58
256#define SOL_SCTP 132
257#define SOL_RAW 255
258#define SOL_IPX 256
259#define SOL_AX25 257
260#define SOL_ATALK 258
261#define SOL_NETROM 259
262#define SOL_ROSE 260
263#define SOL_DECNET 261
264#define SOL_X25 262
265#define SOL_PACKET 263
266#define SOL_ATM 264
267#define SOL_AAL 265
268#define SOL_IRDA 266
269#define SOL_NETBEUI 267
270#define SOL_LLC 268
271#define SOL_DCCP 269
272#define SOL_NETLINK 270
273#define SOL_TIPC 271
Elliott Hughes8d768712016-12-13 15:29:58 -0800274#define SOL_RXRPC 272
275#define SOL_PPPOL2TP 273
276#define SOL_BLUETOOTH 274
277#define SOL_PNPIPE 275
278#define SOL_RDS 276
279#define SOL_IUCV 277
280#define SOL_CAIF 278
281#define SOL_ALG 279
282#define SOL_NFC 280
283#define SOL_KCM 281
Elliott Hughes062eac82018-08-27 11:27:06 -0700284#define SOL_TLS 282
Elliott Hughes86ec05a2012-09-11 19:03:02 -0700285
286#define IPX_TYPE 1
287
288#ifdef __i386__
289# define __socketcall extern __attribute__((__cdecl__))
290#else
291# define __socketcall extern
292#endif
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800293
zijunzhao4e274fa2023-05-25 18:48:38 +0000294__socketcall int accept(int __fd, struct sockaddr* _Nullable __addr, socklen_t* _Nullable __addr_length);
295__socketcall int accept4(int __fd, struct sockaddr* _Nullable __addr, socklen_t* _Nullable __addr_length, int __flags) __INTRODUCED_IN(21);
296__socketcall int bind(int __fd, const struct sockaddr* _Nonnull __addr, socklen_t __addr_length);
297__socketcall int connect(int __fd, const struct sockaddr* _Nonnull __addr, socklen_t __addr_length);
298__socketcall int getpeername(int __fd, struct sockaddr* _Nonnull __addr, socklen_t* _Nonnull __addr_length);
299__socketcall int getsockname(int __fd, struct sockaddr* _Nonnull __addr, socklen_t* _Nonnull __addr_length);
300__socketcall int getsockopt(int __fd, int __level, int __option, void* _Nullable __value, socklen_t* _Nonnull __value_length);
Elliott Hughesff26a162017-08-17 22:34:21 +0000301__socketcall int listen(int __fd, int __backlog);
zijunzhao4e274fa2023-05-25 18:48:38 +0000302__socketcall int recvmmsg(int __fd, struct mmsghdr* _Nonnull __msgs, unsigned int __msg_count, int __flags, const struct timespec* _Nullable __timeout)
Josh Gao14adff12016-04-29 12:00:55 -0700303 __INTRODUCED_IN(21);
zijunzhao4e274fa2023-05-25 18:48:38 +0000304__socketcall ssize_t recvmsg(int __fd, struct msghdr* _Nonnull __msg, int __flags);
305__socketcall int sendmmsg(int __fd, const struct mmsghdr* _Nonnull __msgs, unsigned int __msg_count, int __flags) __INTRODUCED_IN(21);
306__socketcall ssize_t sendmsg(int __fd, const struct msghdr* _Nonnull __msg, int __flags);
307__socketcall int setsockopt(int __fd, int __level, int __option, const void* _Nullable __value, socklen_t __value_length);
Elliott Hughesff26a162017-08-17 22:34:21 +0000308__socketcall int shutdown(int __fd, int __how);
309__socketcall int socket(int __af, int __type, int __protocol);
zijunzhao4e274fa2023-05-25 18:48:38 +0000310__socketcall int socketpair(int __af, int __type, int __protocol, int __fds[_Nonnull 2]);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800311
zijunzhao4e274fa2023-05-25 18:48:38 +0000312ssize_t recv(int __fd, void* _Nullable __buf, size_t __n, int __flags);
313ssize_t send(int __fd, const void* _Nonnull __buf, size_t __n, int __flags);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800314
zijunzhao4e274fa2023-05-25 18:48:38 +0000315__socketcall ssize_t sendto(int __fd, const void* _Nonnull __buf, size_t __n, int __flags, const struct sockaddr* _Nullable __dst_addr, socklen_t __dst_addr_length);
316__socketcall ssize_t recvfrom(int __fd, void* _Nullable __buf, size_t __n, int __flags, struct sockaddr* _Nullable __src_addr, socklen_t* _Nullable __src_addr_length);
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800317
George Burgess IVb97049c2017-07-24 15:05:05 -0700318#if defined(__BIONIC_INCLUDE_FORTIFY_HEADERS)
319#include <bits/fortify/socket.h>
320#endif
Nick Kralevich60f4f9a2013-09-24 16:32:07 -0700321
The Android Open Source Project1dc9e472009-03-03 19:28:35 -0800322#undef __socketcall
323
324__END_DECLS
325
Elliott Hughesff26a162017-08-17 22:34:21 +0000326#endif