PageRenderTime 67ms CodeModel.GetById 27ms RepoModel.GetById 1ms app.codeStats 0ms

/libc/include/sys/socket.h

https://github.com/CyanogenMod/android_bionic
C Header | 332 lines | 265 code | 40 blank | 27 comment | 7 complexity | 637c2c676576bb6331344c7b0514a785 MD5 | raw file
Possible License(s): BSD-3-Clause
  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. #include <sys/cdefs.h>
  31. #include <sys/types.h>
  32. #include <linux/socket.h>
  33. #include <asm/fcntl.h>
  34. #include <asm/socket.h>
  35. #include <linux/sockios.h>
  36. #include <linux/uio.h>
  37. #include <linux/types.h>
  38. #include <linux/compiler.h>
  39. __BEGIN_DECLS
  40. #define sockaddr_storage __kernel_sockaddr_storage
  41. typedef unsigned short sa_family_t;
  42. struct timespec;
  43. #ifdef __mips__
  44. #define SOCK_DGRAM 1
  45. #define SOCK_STREAM 2
  46. #else
  47. #define SOCK_STREAM 1
  48. #define SOCK_DGRAM 2
  49. #endif
  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. #define SOCK_CLOEXEC O_CLOEXEC
  56. #define SOCK_NONBLOCK O_NONBLOCK
  57. enum {
  58. SHUT_RD = 0,
  59. #define SHUT_RD SHUT_RD
  60. SHUT_WR,
  61. #define SHUT_WR SHUT_WR
  62. SHUT_RDWR
  63. #define SHUT_RDWR SHUT_RDWR
  64. };
  65. struct sockaddr {
  66. sa_family_t sa_family;
  67. char sa_data[14];
  68. };
  69. struct linger {
  70. int l_onoff;
  71. int l_linger;
  72. };
  73. struct msghdr {
  74. void* msg_name;
  75. socklen_t msg_namelen;
  76. struct iovec* msg_iov;
  77. size_t msg_iovlen;
  78. void* msg_control;
  79. size_t msg_controllen;
  80. int msg_flags;
  81. };
  82. struct mmsghdr {
  83. struct msghdr msg_hdr;
  84. unsigned int msg_len;
  85. };
  86. struct cmsghdr {
  87. size_t cmsg_len;
  88. int cmsg_level;
  89. int cmsg_type;
  90. };
  91. #define CMSG_NXTHDR(mhdr, cmsg) __cmsg_nxthdr((mhdr), (cmsg))
  92. #define CMSG_ALIGN(len) ( ((len)+sizeof(long)-1) & ~(sizeof(long)-1) )
  93. #define CMSG_DATA(cmsg) (((unsigned char*)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr))))
  94. #define CMSG_SPACE(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(len))
  95. #define CMSG_LEN(len) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (len))
  96. #define CMSG_FIRSTHDR(msg) \
  97. ((msg)->msg_controllen >= sizeof(struct cmsghdr) \
  98. ? (struct cmsghdr*) (msg)->msg_control : (struct cmsghdr*) NULL)
  99. #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)))
  100. struct cmsghdr* __cmsg_nxthdr(struct msghdr*, struct cmsghdr*);
  101. #define SCM_RIGHTS 0x01
  102. #define SCM_CREDENTIALS 0x02
  103. #define SCM_SECURITY 0x03
  104. struct ucred {
  105. pid_t pid;
  106. uid_t uid;
  107. gid_t gid;
  108. };
  109. #define AF_UNSPEC 0
  110. #define AF_UNIX 1
  111. #define AF_LOCAL 1
  112. #define AF_INET 2
  113. #define AF_AX25 3
  114. #define AF_IPX 4
  115. #define AF_APPLETALK 5
  116. #define AF_NETROM 6
  117. #define AF_BRIDGE 7
  118. #define AF_ATMPVC 8
  119. #define AF_X25 9
  120. #define AF_INET6 10
  121. #define AF_ROSE 11
  122. #define AF_DECnet 12
  123. #define AF_NETBEUI 13
  124. #define AF_SECURITY 14
  125. #define AF_KEY 15
  126. #define AF_NETLINK 16
  127. #define AF_ROUTE AF_NETLINK
  128. #define AF_PACKET 17
  129. #define AF_ASH 18
  130. #define AF_ECONET 19
  131. #define AF_ATMSVC 20
  132. #define AF_RDS 21
  133. #define AF_SNA 22
  134. #define AF_IRDA 23
  135. #define AF_PPPOX 24
  136. #define AF_WANPIPE 25
  137. #define AF_LLC 26
  138. #define AF_CAN 29
  139. #define AF_TIPC 30
  140. #define AF_BLUETOOTH 31
  141. #define AF_IUCV 32
  142. #define AF_RXRPC 33
  143. #define AF_ISDN 34
  144. #define AF_PHONET 35
  145. #define AF_IEEE802154 36
  146. #define AF_CAIF 37
  147. #define AF_ALG 38
  148. #define AF_NFC 39
  149. #define AF_VSOCK 40
  150. #define AF_MAX 41
  151. #define PF_UNSPEC AF_UNSPEC
  152. #define PF_UNIX AF_UNIX
  153. #define PF_LOCAL AF_LOCAL
  154. #define PF_INET AF_INET
  155. #define PF_AX25 AF_AX25
  156. #define PF_IPX AF_IPX
  157. #define PF_APPLETALK AF_APPLETALK
  158. #define PF_NETROM AF_NETROM
  159. #define PF_BRIDGE AF_BRIDGE
  160. #define PF_ATMPVC AF_ATMPVC
  161. #define PF_X25 AF_X25
  162. #define PF_INET6 AF_INET6
  163. #define PF_ROSE AF_ROSE
  164. #define PF_DECnet AF_DECnet
  165. #define PF_NETBEUI AF_NETBEUI
  166. #define PF_SECURITY AF_SECURITY
  167. #define PF_KEY AF_KEY
  168. #define PF_NETLINK AF_NETLINK
  169. #define PF_ROUTE AF_ROUTE
  170. #define PF_PACKET AF_PACKET
  171. #define PF_ASH AF_ASH
  172. #define PF_ECONET AF_ECONET
  173. #define PF_ATMSVC AF_ATMSVC
  174. #define PF_RDS AF_RDS
  175. #define PF_SNA AF_SNA
  176. #define PF_IRDA AF_IRDA
  177. #define PF_PPPOX AF_PPPOX
  178. #define PF_WANPIPE AF_WANPIPE
  179. #define PF_LLC AF_LLC
  180. #define PF_CAN AF_CAN
  181. #define PF_TIPC AF_TIPC
  182. #define PF_BLUETOOTH AF_BLUETOOTH
  183. #define PF_IUCV AF_IUCV
  184. #define PF_RXRPC AF_RXRPC
  185. #define PF_ISDN AF_ISDN
  186. #define PF_PHONET AF_PHONET
  187. #define PF_IEEE802154 AF_IEEE802154
  188. #define PF_CAIF AF_CAIF
  189. #define PF_ALG AF_ALG
  190. #define PF_NFC AF_NFC
  191. #define PF_VSOCK AF_VSOCK
  192. #define PF_MAX AF_MAX
  193. #define SOMAXCONN 128
  194. #define MSG_OOB 1
  195. #define MSG_PEEK 2
  196. #define MSG_DONTROUTE 4
  197. #define MSG_TRYHARD 4
  198. #define MSG_CTRUNC 8
  199. #define MSG_PROBE 0x10
  200. #define MSG_TRUNC 0x20
  201. #define MSG_DONTWAIT 0x40
  202. #define MSG_EOR 0x80
  203. #define MSG_WAITALL 0x100
  204. #define MSG_FIN 0x200
  205. #define MSG_SYN 0x400
  206. #define MSG_CONFIRM 0x800
  207. #define MSG_RST 0x1000
  208. #define MSG_ERRQUEUE 0x2000
  209. #define MSG_NOSIGNAL 0x4000
  210. #define MSG_MORE 0x8000
  211. #define MSG_WAITFORONE 0x10000
  212. #define MSG_FASTOPEN 0x20000000
  213. #define MSG_CMSG_CLOEXEC 0x40000000
  214. #define MSG_EOF MSG_FIN
  215. #define MSG_CMSG_COMPAT 0
  216. #define SOL_IP 0
  217. #define SOL_TCP 6
  218. #define SOL_UDP 17
  219. #define SOL_IPV6 41
  220. #define SOL_ICMPV6 58
  221. #define SOL_SCTP 132
  222. #define SOL_RAW 255
  223. #define SOL_IPX 256
  224. #define SOL_AX25 257
  225. #define SOL_ATALK 258
  226. #define SOL_NETROM 259
  227. #define SOL_ROSE 260
  228. #define SOL_DECNET 261
  229. #define SOL_X25 262
  230. #define SOL_PACKET 263
  231. #define SOL_ATM 264
  232. #define SOL_AAL 265
  233. #define SOL_IRDA 266
  234. #define SOL_NETBEUI 267
  235. #define SOL_LLC 268
  236. #define SOL_DCCP 269
  237. #define SOL_NETLINK 270
  238. #define SOL_TIPC 271
  239. #define IPX_TYPE 1
  240. #ifdef __i386__
  241. # define __socketcall extern __attribute__((__cdecl__))
  242. #else
  243. # define __socketcall extern
  244. #endif
  245. __socketcall int accept(int, struct sockaddr*, socklen_t*);
  246. __socketcall int accept4(int, struct sockaddr*, socklen_t*, int);
  247. __socketcall int bind(int, const struct sockaddr*, int);
  248. __socketcall int connect(int, const struct sockaddr*, socklen_t);
  249. __socketcall int getpeername(int, struct sockaddr*, socklen_t*);
  250. __socketcall int getsockname(int, struct sockaddr*, socklen_t*);
  251. __socketcall int getsockopt(int, int, int, void*, socklen_t*);
  252. __socketcall int listen(int, int);
  253. __socketcall int recvmmsg(int, struct mmsghdr*, unsigned int, int, const struct timespec*);
  254. __socketcall int recvmsg(int, struct msghdr*, int);
  255. __socketcall int sendmmsg(int, const struct mmsghdr*, unsigned int, int);
  256. __socketcall int sendmsg(int, const struct msghdr*, int);
  257. __socketcall int setsockopt(int, int, int, const void*, socklen_t);
  258. __socketcall int shutdown(int, int);
  259. __socketcall int socket(int, int, int);
  260. __socketcall int socketpair(int, int, int, int*);
  261. extern ssize_t send(int, const void*, size_t, int);
  262. extern ssize_t recv(int, void*, size_t, int);
  263. __socketcall ssize_t sendto(int, const void*, size_t, int, const struct sockaddr*, socklen_t);
  264. __socketcall ssize_t recvfrom(int, void*, size_t, int, const struct sockaddr*, socklen_t*);
  265. __errordecl(__recvfrom_error, "recvfrom called with size bigger than buffer");
  266. extern ssize_t __recvfrom_chk(int, void*, size_t, size_t, int, const struct sockaddr*, socklen_t*);
  267. extern ssize_t __recvfrom_real(int, void*, size_t, int, const struct sockaddr*, socklen_t*) __RENAME(recvfrom);
  268. #if defined(__BIONIC_FORTIFY)
  269. __BIONIC_FORTIFY_INLINE
  270. ssize_t recvfrom(int fd, void* buf, size_t len, int flags, const struct sockaddr* src_addr, socklen_t* addr_len) {
  271. size_t bos = __bos0(buf);
  272. #if !defined(__clang__)
  273. if (bos == __BIONIC_FORTIFY_UNKNOWN_SIZE) {
  274. return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len);
  275. }
  276. if (__builtin_constant_p(len) && (len <= bos)) {
  277. return __recvfrom_real(fd, buf, len, flags, src_addr, addr_len);
  278. }
  279. if (__builtin_constant_p(len) && (len > bos)) {
  280. __recvfrom_error();
  281. }
  282. #endif
  283. return __recvfrom_chk(fd, buf, len, bos, flags, src_addr, addr_len);
  284. }
  285. __BIONIC_FORTIFY_INLINE
  286. ssize_t recv(int socket, void* buf, size_t len, int flags) {
  287. return recvfrom(socket, buf, len, flags, NULL, 0);
  288. }
  289. #endif /* __BIONIC_FORTIFY */
  290. #undef __socketcall
  291. __END_DECLS
  292. #endif /* _SYS_SOCKET_H */