| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 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 | */ | 
| Andrei Emeltchenko | 43d2137 | 2013-10-14 16:48:26 +0300 | [diff] [blame] | 28 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 29 | #ifndef _SYS_SOCKET_H_ | 
|  | 30 | #define _SYS_SOCKET_H_ | 
|  | 31 |  | 
|  | 32 | #include <sys/cdefs.h> | 
|  | 33 | #include <sys/types.h> | 
|  | 34 | #include <linux/socket.h> | 
|  | 35 |  | 
| Andrei Emeltchenko | 43d2137 | 2013-10-14 16:48:26 +0300 | [diff] [blame] | 36 | #include <asm/fcntl.h> | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 37 | #include <asm/socket.h> | 
|  | 38 | #include <linux/sockios.h> | 
|  | 39 | #include <linux/uio.h> | 
|  | 40 | #include <linux/types.h> | 
|  | 41 | #include <linux/compiler.h> | 
|  | 42 |  | 
| Elliott Hughes | 508d292 | 2016-07-21 16:38:43 -0700 | [diff] [blame] | 43 | #include <bits/sa_family_t.h> | 
|  | 44 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 45 | __BEGIN_DECLS | 
|  | 46 |  | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 47 | #define sockaddr_storage __kernel_sockaddr_storage | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 48 |  | 
| Elliott Hughes | a8b1eb3 | 2014-02-28 17:59:29 -0800 | [diff] [blame] | 49 | struct timespec; | 
|  | 50 |  | 
| Raghu Gandham | 6437eac | 2012-08-02 16:50:10 -0700 | [diff] [blame] | 51 | #ifdef __mips__ | 
|  | 52 | #define SOCK_DGRAM      1 | 
|  | 53 | #define SOCK_STREAM     2 | 
| Greg Hackmann | d75abb9 | 2015-08-25 17:45:46 -0700 | [diff] [blame] | 54 | #else | 
|  | 55 | #define SOCK_STREAM     1 | 
|  | 56 | #define SOCK_DGRAM      2 | 
|  | 57 | #endif | 
| Raghu Gandham | 6437eac | 2012-08-02 16:50:10 -0700 | [diff] [blame] | 58 | #define SOCK_RAW        3 | 
|  | 59 | #define SOCK_RDM        4 | 
|  | 60 | #define SOCK_SEQPACKET  5 | 
|  | 61 | #define SOCK_DCCP       6 | 
|  | 62 | #define SOCK_PACKET     10 | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 63 |  | 
| Andrei Emeltchenko | 43d2137 | 2013-10-14 16:48:26 +0300 | [diff] [blame] | 64 | #define SOCK_CLOEXEC O_CLOEXEC | 
|  | 65 | #define SOCK_NONBLOCK O_NONBLOCK | 
|  | 66 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 67 | enum { | 
| Andrei Emeltchenko | 43d2137 | 2013-10-14 16:48:26 +0300 | [diff] [blame] | 68 | SHUT_RD = 0, | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 69 | #define SHUT_RD         SHUT_RD | 
| Andrei Emeltchenko | 43d2137 | 2013-10-14 16:48:26 +0300 | [diff] [blame] | 70 | SHUT_WR, | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 71 | #define SHUT_WR         SHUT_WR | 
| Andrei Emeltchenko | 43d2137 | 2013-10-14 16:48:26 +0300 | [diff] [blame] | 72 | SHUT_RDWR | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 73 | #define SHUT_RDWR       SHUT_RDWR | 
|  | 74 | }; | 
|  | 75 |  | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 76 | struct sockaddr { | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 77 | sa_family_t sa_family; | 
|  | 78 | char sa_data[14]; | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 79 | }; | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 80 |  | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 81 | struct linger { | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 82 | int l_onoff; | 
|  | 83 | int l_linger; | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 84 | }; | 
|  | 85 |  | 
|  | 86 | struct msghdr { | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 87 | void* msg_name; | 
|  | 88 | socklen_t msg_namelen; | 
|  | 89 | struct iovec* msg_iov; | 
|  | 90 | size_t msg_iovlen; | 
|  | 91 | void* msg_control; | 
|  | 92 | size_t msg_controllen; | 
|  | 93 | int msg_flags; | 
|  | 94 | }; | 
|  | 95 |  | 
|  | 96 | struct mmsghdr { | 
|  | 97 | struct msghdr msg_hdr; | 
|  | 98 | unsigned int msg_len; | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 99 | }; | 
|  | 100 |  | 
|  | 101 | struct cmsghdr { | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 102 | size_t cmsg_len; | 
|  | 103 | int cmsg_level; | 
|  | 104 | int cmsg_type; | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 105 | }; | 
|  | 106 |  | 
| Calin Juravle | 096b4eb | 2014-06-19 18:16:17 +0100 | [diff] [blame] | 107 | #define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr((mhdr), (cmsg)) | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 108 | #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) ) | 
| Dan Albert | 268af26 | 2015-09-11 09:47:27 -0700 | [diff] [blame] | 109 | #define CMSG_DATA(cmsg) (((unsigned char*)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)))) | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 110 | #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len)) | 
|  | 111 | #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len)) | 
| Calin Juravle | f1de90b | 2014-03-19 17:40:23 +0000 | [diff] [blame] | 112 | #define CMSG_FIRSTHDR(msg) \ | 
|  | 113 | ((msg)->msg_controllen >= sizeof(struct cmsghdr) \ | 
|  | 114 | ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL) | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 115 | #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 Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 116 |  | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 117 | #if __ANDROID_API__ >= __ANDROID_API_L__ | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 118 | struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*) __INTRODUCED_IN(21); | 
| Dan Albert | 11f0e10 | 2016-09-08 16:12:09 -0700 | [diff] [blame] | 119 | #else | 
|  | 120 | /* TODO(danalbert): Move this into libandroid_support. */ | 
|  | 121 | static inline struct cmsghdr* __cmsg_nxthdr(struct msghdr* msg, struct cmsghdr* cmsg) { | 
|  | 122 | struct cmsghdr* ptr = | 
|  | 123 | __BIONIC_CAST(reinterpret_cast, struct cmsghdr*, | 
|  | 124 | (__BIONIC_CAST(reinterpret_cast, char*, cmsg) + CMSG_ALIGN(cmsg->cmsg_len))); | 
|  | 125 | size_t len = __BIONIC_CAST(reinterpret_cast, char*, ptr + 1) - | 
|  | 126 | __BIONIC_CAST(reinterpret_cast, char*, msg->msg_control); | 
|  | 127 | if (len > msg->msg_controllen) { | 
|  | 128 | return NULL; | 
|  | 129 | } | 
|  | 130 | return ptr; | 
|  | 131 | } | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 132 | #endif /* __ANDROID_API__ >= __ANDROID_API_L__ */ | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 133 |  | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 134 | #define SCM_RIGHTS 0x01 | 
|  | 135 | #define SCM_CREDENTIALS 0x02 | 
|  | 136 | #define SCM_SECURITY 0x03 | 
|  | 137 |  | 
|  | 138 | struct ucred { | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 139 | pid_t pid; | 
|  | 140 | uid_t uid; | 
|  | 141 | gid_t gid; | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 142 | }; | 
|  | 143 |  | 
|  | 144 | #define AF_UNSPEC 0 | 
|  | 145 | #define AF_UNIX 1 | 
|  | 146 | #define AF_LOCAL 1 | 
|  | 147 | #define AF_INET 2 | 
|  | 148 | #define AF_AX25 3 | 
|  | 149 | #define AF_IPX 4 | 
|  | 150 | #define AF_APPLETALK 5 | 
|  | 151 | #define AF_NETROM 6 | 
|  | 152 | #define AF_BRIDGE 7 | 
|  | 153 | #define AF_ATMPVC 8 | 
|  | 154 | #define AF_X25 9 | 
|  | 155 | #define AF_INET6 10 | 
|  | 156 | #define AF_ROSE 11 | 
|  | 157 | #define AF_DECnet 12 | 
|  | 158 | #define AF_NETBEUI 13 | 
|  | 159 | #define AF_SECURITY 14 | 
|  | 160 | #define AF_KEY 15 | 
|  | 161 | #define AF_NETLINK 16 | 
|  | 162 | #define AF_ROUTE AF_NETLINK | 
|  | 163 | #define AF_PACKET 17 | 
|  | 164 | #define AF_ASH 18 | 
|  | 165 | #define AF_ECONET 19 | 
|  | 166 | #define AF_ATMSVC 20 | 
| Elliott Hughes | d73c0b3 | 2013-01-03 16:25:47 -0800 | [diff] [blame] | 167 | #define AF_RDS 21 | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 168 | #define AF_SNA 22 | 
|  | 169 | #define AF_IRDA 23 | 
|  | 170 | #define AF_PPPOX 24 | 
|  | 171 | #define AF_WANPIPE 25 | 
|  | 172 | #define AF_LLC 26 | 
| Elliott Hughes | d73c0b3 | 2013-01-03 16:25:47 -0800 | [diff] [blame] | 173 | #define AF_CAN 29 | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 174 | #define AF_TIPC 30 | 
|  | 175 | #define AF_BLUETOOTH 31 | 
| Elliott Hughes | d73c0b3 | 2013-01-03 16:25:47 -0800 | [diff] [blame] | 176 | #define AF_IUCV 32 | 
|  | 177 | #define AF_RXRPC 33 | 
|  | 178 | #define AF_ISDN 34 | 
|  | 179 | #define AF_PHONET 35 | 
|  | 180 | #define AF_IEEE802154 36 | 
|  | 181 | #define AF_CAIF 37 | 
|  | 182 | #define AF_ALG 38 | 
| Greg Hackmann | c7ca8f3 | 2016-01-28 11:07:26 -0800 | [diff] [blame] | 183 | #define AF_NFC 39 | 
|  | 184 | #define AF_VSOCK 40 | 
| Elliott Hughes | 8d76871 | 2016-12-13 15:29:58 -0800 | [diff] [blame] | 185 | #define AF_KCM 41 | 
|  | 186 | #define AF_QIPCRTR 42 | 
|  | 187 | #define AF_MAX 43 | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 188 |  | 
|  | 189 | #define PF_UNSPEC AF_UNSPEC | 
|  | 190 | #define PF_UNIX AF_UNIX | 
|  | 191 | #define PF_LOCAL AF_LOCAL | 
|  | 192 | #define PF_INET AF_INET | 
|  | 193 | #define PF_AX25 AF_AX25 | 
|  | 194 | #define PF_IPX AF_IPX | 
|  | 195 | #define PF_APPLETALK AF_APPLETALK | 
|  | 196 | #define PF_NETROM AF_NETROM | 
|  | 197 | #define PF_BRIDGE AF_BRIDGE | 
|  | 198 | #define PF_ATMPVC AF_ATMPVC | 
|  | 199 | #define PF_X25 AF_X25 | 
|  | 200 | #define PF_INET6 AF_INET6 | 
|  | 201 | #define PF_ROSE AF_ROSE | 
|  | 202 | #define PF_DECnet AF_DECnet | 
|  | 203 | #define PF_NETBEUI AF_NETBEUI | 
|  | 204 | #define PF_SECURITY AF_SECURITY | 
|  | 205 | #define PF_KEY AF_KEY | 
|  | 206 | #define PF_NETLINK AF_NETLINK | 
|  | 207 | #define PF_ROUTE AF_ROUTE | 
|  | 208 | #define PF_PACKET AF_PACKET | 
|  | 209 | #define PF_ASH AF_ASH | 
|  | 210 | #define PF_ECONET AF_ECONET | 
|  | 211 | #define PF_ATMSVC AF_ATMSVC | 
| Elliott Hughes | d73c0b3 | 2013-01-03 16:25:47 -0800 | [diff] [blame] | 212 | #define PF_RDS AF_RDS | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 213 | #define PF_SNA AF_SNA | 
|  | 214 | #define PF_IRDA AF_IRDA | 
|  | 215 | #define PF_PPPOX AF_PPPOX | 
|  | 216 | #define PF_WANPIPE AF_WANPIPE | 
|  | 217 | #define PF_LLC AF_LLC | 
| Elliott Hughes | d73c0b3 | 2013-01-03 16:25:47 -0800 | [diff] [blame] | 218 | #define PF_CAN AF_CAN | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 219 | #define PF_TIPC AF_TIPC | 
|  | 220 | #define PF_BLUETOOTH AF_BLUETOOTH | 
| Elliott Hughes | d73c0b3 | 2013-01-03 16:25:47 -0800 | [diff] [blame] | 221 | #define PF_IUCV AF_IUCV | 
|  | 222 | #define PF_RXRPC AF_RXRPC | 
|  | 223 | #define PF_ISDN AF_ISDN | 
|  | 224 | #define PF_PHONET AF_PHONET | 
|  | 225 | #define PF_IEEE802154 AF_IEEE802154 | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 226 | #define PF_CAIF AF_CAIF | 
| Elliott Hughes | d73c0b3 | 2013-01-03 16:25:47 -0800 | [diff] [blame] | 227 | #define PF_ALG AF_ALG | 
| Greg Hackmann | c7ca8f3 | 2016-01-28 11:07:26 -0800 | [diff] [blame] | 228 | #define PF_NFC AF_NFC | 
|  | 229 | #define PF_VSOCK AF_VSOCK | 
| Elliott Hughes | 8d76871 | 2016-12-13 15:29:58 -0800 | [diff] [blame] | 230 | #define PF_KCM AF_KCM | 
|  | 231 | #define PF_QIPCRTR AF_QIPCRTR | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 232 | #define PF_MAX AF_MAX | 
|  | 233 |  | 
|  | 234 | #define SOMAXCONN 128 | 
|  | 235 |  | 
|  | 236 | #define MSG_OOB 1 | 
|  | 237 | #define MSG_PEEK 2 | 
|  | 238 | #define MSG_DONTROUTE 4 | 
|  | 239 | #define MSG_TRYHARD 4 | 
|  | 240 | #define MSG_CTRUNC 8 | 
|  | 241 | #define MSG_PROBE 0x10 | 
|  | 242 | #define MSG_TRUNC 0x20 | 
|  | 243 | #define MSG_DONTWAIT 0x40 | 
|  | 244 | #define MSG_EOR 0x80 | 
|  | 245 | #define MSG_WAITALL 0x100 | 
|  | 246 | #define MSG_FIN 0x200 | 
|  | 247 | #define MSG_SYN 0x400 | 
|  | 248 | #define MSG_CONFIRM 0x800 | 
|  | 249 | #define MSG_RST 0x1000 | 
|  | 250 | #define MSG_ERRQUEUE 0x2000 | 
|  | 251 | #define MSG_NOSIGNAL 0x4000 | 
|  | 252 | #define MSG_MORE 0x8000 | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 253 | #define MSG_WAITFORONE 0x10000 | 
| Elliott Hughes | 8d76871 | 2016-12-13 15:29:58 -0800 | [diff] [blame] | 254 | #define MSG_BATCH 0x40000 | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 255 | #define MSG_FASTOPEN 0x20000000 | 
|  | 256 | #define MSG_CMSG_CLOEXEC 0x40000000 | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 257 | #define MSG_EOF MSG_FIN | 
|  | 258 | #define MSG_CMSG_COMPAT 0 | 
|  | 259 |  | 
|  | 260 | #define SOL_IP 0 | 
|  | 261 | #define SOL_TCP 6 | 
|  | 262 | #define SOL_UDP 17 | 
|  | 263 | #define SOL_IPV6 41 | 
|  | 264 | #define SOL_ICMPV6 58 | 
|  | 265 | #define SOL_SCTP 132 | 
|  | 266 | #define SOL_RAW 255 | 
|  | 267 | #define SOL_IPX 256 | 
|  | 268 | #define SOL_AX25 257 | 
|  | 269 | #define SOL_ATALK 258 | 
|  | 270 | #define SOL_NETROM 259 | 
|  | 271 | #define SOL_ROSE 260 | 
|  | 272 | #define SOL_DECNET 261 | 
|  | 273 | #define SOL_X25 262 | 
|  | 274 | #define SOL_PACKET 263 | 
|  | 275 | #define SOL_ATM 264 | 
|  | 276 | #define SOL_AAL 265 | 
|  | 277 | #define SOL_IRDA 266 | 
|  | 278 | #define SOL_NETBEUI 267 | 
|  | 279 | #define SOL_LLC 268 | 
|  | 280 | #define SOL_DCCP 269 | 
|  | 281 | #define SOL_NETLINK 270 | 
|  | 282 | #define SOL_TIPC 271 | 
| Elliott Hughes | 8d76871 | 2016-12-13 15:29:58 -0800 | [diff] [blame] | 283 | #define SOL_RXRPC 272 | 
|  | 284 | #define SOL_PPPOL2TP 273 | 
|  | 285 | #define SOL_BLUETOOTH 274 | 
|  | 286 | #define SOL_PNPIPE 275 | 
|  | 287 | #define SOL_RDS 276 | 
|  | 288 | #define SOL_IUCV 277 | 
|  | 289 | #define SOL_CAIF 278 | 
|  | 290 | #define SOL_ALG 279 | 
|  | 291 | #define SOL_NFC 280 | 
|  | 292 | #define SOL_KCM 281 | 
| Elliott Hughes | 86ec05a | 2012-09-11 19:03:02 -0700 | [diff] [blame] | 293 |  | 
|  | 294 | #define IPX_TYPE 1 | 
|  | 295 |  | 
|  | 296 | #ifdef __i386__ | 
|  | 297 | # define __socketcall extern __attribute__((__cdecl__)) | 
|  | 298 | #else | 
|  | 299 | # define __socketcall extern | 
|  | 300 | #endif | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 301 |  | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 302 | __socketcall int accept(int, struct sockaddr*, socklen_t*); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 303 | __socketcall int accept4(int, struct sockaddr*, socklen_t*, int) __INTRODUCED_IN(21); | 
| Elliott Hughes | 2b9605f | 2016-08-16 13:37:24 -0700 | [diff] [blame] | 304 | __socketcall int bind(int, const struct sockaddr*, socklen_t); | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 305 | __socketcall int connect(int, const struct sockaddr*, socklen_t); | 
|  | 306 | __socketcall int getpeername(int, struct sockaddr*, socklen_t*); | 
|  | 307 | __socketcall int getsockname(int, struct sockaddr*, socklen_t*); | 
|  | 308 | __socketcall int getsockopt(int, int, int, void*, socklen_t*); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 309 | __socketcall int listen(int, int); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 310 | __socketcall int recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*) | 
|  | 311 | __INTRODUCED_IN(21); | 
| Elliott Hughes | 2b9605f | 2016-08-16 13:37:24 -0700 | [diff] [blame] | 312 | __socketcall ssize_t recvmsg(int, struct msghdr*, int); | 
| Josh Gao | 14adff1 | 2016-04-29 12:00:55 -0700 | [diff] [blame] | 313 | __socketcall int sendmmsg(int, const struct mmsghdr*, unsigned int, int) __INTRODUCED_IN(21); | 
| Elliott Hughes | 2b9605f | 2016-08-16 13:37:24 -0700 | [diff] [blame] | 314 | __socketcall ssize_t sendmsg(int, const struct msghdr*, int); | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 315 | __socketcall int setsockopt(int, int, int, const void*, socklen_t); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 316 | __socketcall int shutdown(int, int); | 
| Guillaume Ranquet | 6ff0c75 | 2014-02-10 13:11:29 +0100 | [diff] [blame] | 317 | __socketcall int socket(int, int, int); | 
|  | 318 | __socketcall int socketpair(int, int, int, int*); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 319 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 320 | ssize_t recv(int, void*, size_t, int) __overloadable __RENAME_CLANG(recv); | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 321 | ssize_t send(int, const void*, size_t, int) __overloadable __RENAME_CLANG(send); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 322 |  | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 323 | __socketcall ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t) | 
|  | 324 | __overloadable __RENAME_CLANG(sendto); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 325 | __socketcall ssize_t recvfrom(int, void*, size_t, int, struct sockaddr*, | 
|  | 326 | socklen_t*) __overloadable __RENAME_CLANG(recvfrom); | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 327 |  | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 328 | extern ssize_t __sendto_chk(int, const void*, size_t, size_t, int, const struct sockaddr*, | 
| Josh Gao | 2e8e5e6 | 2017-04-20 12:58:31 -0700 | [diff] [blame] | 329 | socklen_t) __INTRODUCED_IN(26); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 330 | ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, struct sockaddr*, | 
|  | 331 | socklen_t*) __INTRODUCED_IN(21); | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 332 |  | 
| Dan Albert | 658727e | 2014-10-07 11:10:36 -0700 | [diff] [blame] | 333 | #if defined(__BIONIC_FORTIFY) | 
|  | 334 |  | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 335 | #define __recvfrom_bad_size "recvfrom called with size bigger than buffer" | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 336 | #define __sendto_bad_size "sendto called with size bigger than buffer" | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 337 | #if defined(__clang__) | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 338 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 339 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 340 | ssize_t recvfrom(int fd, void* const buf __pass_object_size0, size_t len, | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 341 | int flags, struct sockaddr* src_addr, socklen_t* addr_len) | 
|  | 342 | __overloadable | 
|  | 343 | __enable_if(__bos(buf) != __BIONIC_FORTIFY_UNKNOWN_SIZE && | 
|  | 344 | __bos(buf) < len, "selected when the buffer is too small") | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 345 | __errorattr(__recvfrom_bad_size); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 346 |  | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 347 | __BIONIC_FORTIFY_INLINE | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 348 | ssize_t recvfrom(int fd, void* const buf __pass_object_size0, size_t len, | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 349 | int flags, struct sockaddr* src_addr, socklen_t* addr_len) | 
|  | 350 | __overloadable { | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 351 | size_t bos = __bos0(buf); | 
|  | 352 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 353 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 354 | return __call_bypassing_fortify(recvfrom)(fd, buf, len, flags, src_addr, | 
|  | 355 | addr_len); | 
|  | 356 | } | 
|  | 357 |  | 
|  | 358 | return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len); | 
|  | 359 | } | 
|  | 360 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ | 
|  | 361 |  | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 362 | #if __ANDROID_API__ >= __ANDROID_API_N_MR1__ | 
|  | 363 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
|  | 364 | ssize_t sendto(int fd, const void* buf, size_t len, int flags, | 
|  | 365 | const struct sockaddr* dest_addr, socklen_t addr_len) | 
|  | 366 | __overloadable | 
|  | 367 | __enable_if(__bos0(buf) != __BIONIC_FORTIFY_UNKNOWN_SIZE && | 
|  | 368 | __bos0(buf) < len, "selected when the buffer is too small") | 
|  | 369 | __errorattr(__sendto_bad_size); | 
|  | 370 |  | 
|  | 371 | __BIONIC_FORTIFY_INLINE | 
|  | 372 | ssize_t sendto(int fd, const void* const buf __pass_object_size0, size_t len, | 
|  | 373 | int flags, const struct sockaddr* dest_addr, socklen_t addr_len) | 
|  | 374 | __overloadable { | 
|  | 375 | size_t bos = __bos0(buf); | 
|  | 376 |  | 
|  | 377 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 378 | return __call_bypassing_fortify(sendto)(fd, buf, len, flags, dest_addr, | 
|  | 379 | addr_len); | 
|  | 380 | } | 
|  | 381 |  | 
|  | 382 | return __sendto_chk(fd, buf, len, bos, flags, dest_addr, addr_len); | 
|  | 383 | } | 
|  | 384 |  | 
|  | 385 | __BIONIC_ERROR_FUNCTION_VISIBILITY | 
|  | 386 | ssize_t send(int socket, const void* buf, size_t len, int flags) | 
|  | 387 | __overloadable | 
|  | 388 | __enable_if(__bos0(buf) != __BIONIC_FORTIFY_UNKNOWN_SIZE && | 
|  | 389 | __bos0(buf) < len, "selected when the buffer is too small") | 
|  | 390 | __errorattr("send called with size bigger than buffer"); | 
|  | 391 | #endif /* __ANDROID_API__ >= __ANDROID_API_N_MR1__ */ | 
|  | 392 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 393 | #else /* defined(__clang__) */ | 
|  | 394 | ssize_t __recvfrom_real(int, void*, size_t, int, struct sockaddr*, socklen_t*) __RENAME(recvfrom); | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 395 | __errordecl(__recvfrom_error, __recvfrom_bad_size); | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 396 |  | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 397 | extern ssize_t __sendto_real(int, const void*, size_t, int, const struct sockaddr*, socklen_t) | 
|  | 398 | __RENAME(sendto); | 
|  | 399 | __errordecl(__sendto_error, __sendto_bad_size); | 
|  | 400 |  | 
| George Burgess IV | 7cc779f | 2017-02-09 00:00:31 -0800 | [diff] [blame] | 401 | #if __ANDROID_API__ >= __ANDROID_API_N__ | 
|  | 402 | __BIONIC_FORTIFY_INLINE | 
|  | 403 | ssize_t recvfrom(int fd, void* buf, size_t len, int flags, | 
|  | 404 | struct sockaddr* src_addr, socklen_t* addr_len) { | 
|  | 405 | size_t bos = __bos0(buf); | 
|  | 406 |  | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 407 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
| Elliott Hughes | 247dc91 | 2014-03-10 17:17:01 -0700 | [diff] [blame] | 408 | return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len); | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 409 | } | 
|  | 410 |  | 
|  | 411 | if (__builtin_constant_p(len) && (len <= bos)) { | 
| Elliott Hughes | 247dc91 | 2014-03-10 17:17:01 -0700 | [diff] [blame] | 412 | return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len); | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 413 | } | 
|  | 414 |  | 
|  | 415 | if (__builtin_constant_p(len) && (len > bos)) { | 
|  | 416 | __recvfrom_error(); | 
|  | 417 | } | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 418 |  | 
| Elliott Hughes | 247dc91 | 2014-03-10 17:17:01 -0700 | [diff] [blame] | 419 | return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len); | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 420 | } | 
| Elliott Hughes | 5bc78c8 | 2016-11-16 11:35:43 -0800 | [diff] [blame] | 421 | #endif /* __ANDROID_API__ >= __ANDROID_API_N__ */ | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 422 |  | 
|  | 423 | #if __ANDROID_API__ >= __ANDROID_API_N_MR1__ | 
|  | 424 | __BIONIC_FORTIFY_INLINE | 
|  | 425 | ssize_t sendto(int fd, const void* buf, size_t len, int flags, | 
|  | 426 | const struct sockaddr* dest_addr, socklen_t addr_len) { | 
|  | 427 | size_t bos = __bos0(buf); | 
|  | 428 |  | 
|  | 429 | if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) { | 
|  | 430 | return __sendto_real(fd, buf, len, flags, dest_addr, addr_len); | 
|  | 431 | } | 
|  | 432 |  | 
|  | 433 | if (__builtin_constant_p(len) && (len <= bos)) { | 
|  | 434 | return __sendto_real(fd, buf, len, flags, dest_addr, addr_len); | 
|  | 435 | } | 
|  | 436 |  | 
|  | 437 | if (__builtin_constant_p(len) && (len > bos)) { | 
|  | 438 | __sendto_error(); | 
|  | 439 | } | 
|  | 440 |  | 
|  | 441 | return __sendto_chk(fd, buf, len, bos, flags, dest_addr, addr_len); | 
|  | 442 | } | 
|  | 443 | #endif /* __ANDROID_API__ >= __ANDROID_API_N_MR1__ */ | 
|  | 444 |  | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 445 | #endif /* defined(__clang__) */ | 
|  | 446 | #undef __recvfrom_bad_size | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 447 | #undef __sendto_bad_size | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 448 |  | 
|  | 449 | __BIONIC_FORTIFY_INLINE | 
| George Burgess IV | 156d5a8 | 2017-02-10 13:56:22 -0800 | [diff] [blame] | 450 | ssize_t recv(int socket, void* const buf __pass_object_size0, size_t len, | 
|  | 451 | int flags) __overloadable { | 
| Elliott Hughes | 247dc91 | 2014-03-10 17:17:01 -0700 | [diff] [blame] | 452 | return recvfrom(socket, buf, len, flags, NULL, 0); | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 453 | } | 
|  | 454 |  | 
| Daniel Micay | 95b59c5 | 2017-02-13 17:27:59 -0800 | [diff] [blame] | 455 | __BIONIC_FORTIFY_INLINE | 
|  | 456 | ssize_t send(int socket, const void* const buf __pass_object_size0, size_t len, int flags) | 
|  | 457 | __overloadable { | 
|  | 458 | return sendto(socket, buf, len, flags, NULL, 0); | 
|  | 459 | } | 
|  | 460 |  | 
| Nick Kralevich | 60f4f9a | 2013-09-24 16:32:07 -0700 | [diff] [blame] | 461 | #endif /* __BIONIC_FORTIFY */ | 
|  | 462 |  | 
| The Android Open Source Project | 1dc9e47 | 2009-03-03 19:28:35 -0800 | [diff] [blame] | 463 | #undef __socketcall | 
|  | 464 |  | 
|  | 465 | __END_DECLS | 
|  | 466 |  | 
|  | 467 | #endif /* _SYS_SOCKET_H */ |