socket.h 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415
  1. #ifndef _SYS_SOCKET_H
  2. #define _SYS_SOCKET_H
  3. #ifdef __cplusplus
  4. extern "C" {
  5. #endif
  6. #include <features.h>
  7. #define __NEED_socklen_t
  8. #define __NEED_sa_family_t
  9. #define __NEED_size_t
  10. #define __NEED_ssize_t
  11. #define __NEED_uid_t
  12. #define __NEED_pid_t
  13. #define __NEED_gid_t
  14. #define __NEED_struct_iovec
  15. #include <bits/alltypes.h>
  16. #include <bits/socket.h>
  17. struct msghdr {
  18. void *msg_name;
  19. socklen_t msg_namelen;
  20. struct iovec *msg_iov;
  21. #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
  22. int __pad1;
  23. #endif
  24. int msg_iovlen;
  25. #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
  26. int __pad1;
  27. #endif
  28. void *msg_control;
  29. #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
  30. int __pad2;
  31. #endif
  32. socklen_t msg_controllen;
  33. #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
  34. int __pad2;
  35. #endif
  36. int msg_flags;
  37. };
  38. struct cmsghdr {
  39. #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __BIG_ENDIAN
  40. int __pad1;
  41. #endif
  42. socklen_t cmsg_len;
  43. #if __LONG_MAX > 0x7fffffff && __BYTE_ORDER == __LITTLE_ENDIAN
  44. int __pad1;
  45. #endif
  46. int cmsg_level;
  47. int cmsg_type;
  48. };
  49. #ifdef _GNU_SOURCE
  50. struct ucred {
  51. pid_t pid;
  52. uid_t uid;
  53. gid_t gid;
  54. };
  55. struct mmsghdr {
  56. struct msghdr msg_hdr;
  57. unsigned int msg_len;
  58. };
  59. struct timespec;
  60. int sendmmsg (int, struct mmsghdr *, unsigned int, unsigned int);
  61. int recvmmsg (int, struct mmsghdr *, unsigned int, unsigned int, struct timespec *);
  62. #endif
  63. struct linger {
  64. int l_onoff;
  65. int l_linger;
  66. };
  67. #define SHUT_RD 0
  68. #define SHUT_WR 1
  69. #define SHUT_RDWR 2
  70. #ifndef SOCK_STREAM
  71. #define SOCK_STREAM 1
  72. #define SOCK_DGRAM 2
  73. #endif
  74. #define SOCK_RAW 3
  75. #define SOCK_RDM 4
  76. #define SOCK_SEQPACKET 5
  77. #define SOCK_DCCP 6
  78. #define SOCK_PACKET 10
  79. #ifndef SOCK_CLOEXEC
  80. #define SOCK_CLOEXEC 02000000
  81. #define SOCK_NONBLOCK 04000
  82. #endif
  83. #define PF_UNSPEC 0
  84. #define PF_LOCAL 1
  85. #define PF_UNIX PF_LOCAL
  86. #define PF_FILE PF_LOCAL
  87. #define PF_INET 2
  88. #define PF_AX25 3
  89. #define PF_IPX 4
  90. #define PF_APPLETALK 5
  91. #define PF_NETROM 6
  92. #define PF_BRIDGE 7
  93. #define PF_ATMPVC 8
  94. #define PF_X25 9
  95. #define PF_INET6 10
  96. #define PF_ROSE 11
  97. #define PF_DECnet 12
  98. #define PF_NETBEUI 13
  99. #define PF_SECURITY 14
  100. #define PF_KEY 15
  101. #define PF_NETLINK 16
  102. #define PF_ROUTE PF_NETLINK
  103. #define PF_PACKET 17
  104. #define PF_ASH 18
  105. #define PF_ECONET 19
  106. #define PF_ATMSVC 20
  107. #define PF_RDS 21
  108. #define PF_SNA 22
  109. #define PF_IRDA 23
  110. #define PF_PPPOX 24
  111. #define PF_WANPIPE 25
  112. #define PF_LLC 26
  113. #define PF_IB 27
  114. #define PF_MPLS 28
  115. #define PF_CAN 29
  116. #define PF_TIPC 30
  117. #define PF_BLUETOOTH 31
  118. #define PF_IUCV 32
  119. #define PF_RXRPC 33
  120. #define PF_ISDN 34
  121. #define PF_PHONET 35
  122. #define PF_IEEE802154 36
  123. #define PF_CAIF 37
  124. #define PF_ALG 38
  125. #define PF_NFC 39
  126. #define PF_VSOCK 40
  127. #define PF_KCM 41
  128. #define PF_QIPCRTR 42
  129. #define PF_SMC 43
  130. #define PF_XDP 44
  131. #define PF_MAX 45
  132. #define AF_UNSPEC PF_UNSPEC
  133. #define AF_LOCAL PF_LOCAL
  134. #define AF_UNIX AF_LOCAL
  135. #define AF_FILE AF_LOCAL
  136. #define AF_INET PF_INET
  137. #define AF_AX25 PF_AX25
  138. #define AF_IPX PF_IPX
  139. #define AF_APPLETALK PF_APPLETALK
  140. #define AF_NETROM PF_NETROM
  141. #define AF_BRIDGE PF_BRIDGE
  142. #define AF_ATMPVC PF_ATMPVC
  143. #define AF_X25 PF_X25
  144. #define AF_INET6 PF_INET6
  145. #define AF_ROSE PF_ROSE
  146. #define AF_DECnet PF_DECnet
  147. #define AF_NETBEUI PF_NETBEUI
  148. #define AF_SECURITY PF_SECURITY
  149. #define AF_KEY PF_KEY
  150. #define AF_NETLINK PF_NETLINK
  151. #define AF_ROUTE PF_ROUTE
  152. #define AF_PACKET PF_PACKET
  153. #define AF_ASH PF_ASH
  154. #define AF_ECONET PF_ECONET
  155. #define AF_ATMSVC PF_ATMSVC
  156. #define AF_RDS PF_RDS
  157. #define AF_SNA PF_SNA
  158. #define AF_IRDA PF_IRDA
  159. #define AF_PPPOX PF_PPPOX
  160. #define AF_WANPIPE PF_WANPIPE
  161. #define AF_LLC PF_LLC
  162. #define AF_IB PF_IB
  163. #define AF_MPLS PF_MPLS
  164. #define AF_CAN PF_CAN
  165. #define AF_TIPC PF_TIPC
  166. #define AF_BLUETOOTH PF_BLUETOOTH
  167. #define AF_IUCV PF_IUCV
  168. #define AF_RXRPC PF_RXRPC
  169. #define AF_ISDN PF_ISDN
  170. #define AF_PHONET PF_PHONET
  171. #define AF_IEEE802154 PF_IEEE802154
  172. #define AF_CAIF PF_CAIF
  173. #define AF_ALG PF_ALG
  174. #define AF_NFC PF_NFC
  175. #define AF_VSOCK PF_VSOCK
  176. #define AF_KCM PF_KCM
  177. #define AF_QIPCRTR PF_QIPCRTR
  178. #define AF_SMC PF_SMC
  179. #define AF_XDP PF_XDP
  180. #define AF_MAX PF_MAX
  181. #ifndef SO_DEBUG
  182. #define SO_DEBUG 1
  183. #define SO_REUSEADDR 2
  184. #define SO_TYPE 3
  185. #define SO_ERROR 4
  186. #define SO_DONTROUTE 5
  187. #define SO_BROADCAST 6
  188. #define SO_SNDBUF 7
  189. #define SO_RCVBUF 8
  190. #define SO_KEEPALIVE 9
  191. #define SO_OOBINLINE 10
  192. #define SO_NO_CHECK 11
  193. #define SO_PRIORITY 12
  194. #define SO_LINGER 13
  195. #define SO_BSDCOMPAT 14
  196. #define SO_REUSEPORT 15
  197. #define SO_PASSCRED 16
  198. #define SO_PEERCRED 17
  199. #define SO_RCVLOWAT 18
  200. #define SO_SNDLOWAT 19
  201. #define SO_ACCEPTCONN 30
  202. #define SO_PEERSEC 31
  203. #define SO_SNDBUFFORCE 32
  204. #define SO_RCVBUFFORCE 33
  205. #define SO_PROTOCOL 38
  206. #define SO_DOMAIN 39
  207. #endif
  208. #ifndef SO_RCVTIMEO
  209. #if __LONG_MAX == 0x7fffffff
  210. #define SO_RCVTIMEO 66
  211. #define SO_SNDTIMEO 67
  212. #else
  213. #define SO_RCVTIMEO 20
  214. #define SO_SNDTIMEO 21
  215. #endif
  216. #endif
  217. #ifndef SO_TIMESTAMP
  218. #if __LONG_MAX == 0x7fffffff
  219. #define SO_TIMESTAMP 63
  220. #define SO_TIMESTAMPNS 64
  221. #define SO_TIMESTAMPING 65
  222. #else
  223. #define SO_TIMESTAMP 29
  224. #define SO_TIMESTAMPNS 35
  225. #define SO_TIMESTAMPING 37
  226. #endif
  227. #endif
  228. #define SO_SECURITY_AUTHENTICATION 22
  229. #define SO_SECURITY_ENCRYPTION_TRANSPORT 23
  230. #define SO_SECURITY_ENCRYPTION_NETWORK 24
  231. #define SO_BINDTODEVICE 25
  232. #define SO_ATTACH_FILTER 26
  233. #define SO_DETACH_FILTER 27
  234. #define SO_GET_FILTER SO_ATTACH_FILTER
  235. #define SO_PEERNAME 28
  236. #define SCM_TIMESTAMP SO_TIMESTAMP
  237. #define SO_PASSSEC 34
  238. #define SCM_TIMESTAMPNS SO_TIMESTAMPNS
  239. #define SO_MARK 36
  240. #define SCM_TIMESTAMPING SO_TIMESTAMPING
  241. #define SO_RXQ_OVFL 40
  242. #define SO_WIFI_STATUS 41
  243. #define SCM_WIFI_STATUS SO_WIFI_STATUS
  244. #define SO_PEEK_OFF 42
  245. #define SO_NOFCS 43
  246. #define SO_LOCK_FILTER 44
  247. #define SO_SELECT_ERR_QUEUE 45
  248. #define SO_BUSY_POLL 46
  249. #define SO_MAX_PACING_RATE 47
  250. #define SO_BPF_EXTENSIONS 48
  251. #define SO_INCOMING_CPU 49
  252. #define SO_ATTACH_BPF 50
  253. #define SO_DETACH_BPF SO_DETACH_FILTER
  254. #define SO_ATTACH_REUSEPORT_CBPF 51
  255. #define SO_ATTACH_REUSEPORT_EBPF 52
  256. #define SO_CNX_ADVICE 53
  257. #define SCM_TIMESTAMPING_OPT_STATS 54
  258. #define SO_MEMINFO 55
  259. #define SO_INCOMING_NAPI_ID 56
  260. #define SO_COOKIE 57
  261. #define SCM_TIMESTAMPING_PKTINFO 58
  262. #define SO_PEERGROUPS 59
  263. #define SO_ZEROCOPY 60
  264. #define SO_TXTIME 61
  265. #define SCM_TXTIME SO_TXTIME
  266. #define SO_BINDTOIFINDEX 62
  267. #define SO_DETACH_REUSEPORT_BPF 68
  268. #define SO_PREFER_BUSY_POLL 69
  269. #define SO_BUSY_POLL_BUDGET 70
  270. #ifndef SOL_SOCKET
  271. #define SOL_SOCKET 1
  272. #endif
  273. #define SOL_IP 0
  274. #define SOL_IPV6 41
  275. #define SOL_ICMPV6 58
  276. #define SOL_RAW 255
  277. #define SOL_DECNET 261
  278. #define SOL_X25 262
  279. #define SOL_PACKET 263
  280. #define SOL_ATM 264
  281. #define SOL_AAL 265
  282. #define SOL_IRDA 266
  283. #define SOL_NETBEUI 267
  284. #define SOL_LLC 268
  285. #define SOL_DCCP 269
  286. #define SOL_NETLINK 270
  287. #define SOL_TIPC 271
  288. #define SOL_RXRPC 272
  289. #define SOL_PPPOL2TP 273
  290. #define SOL_BLUETOOTH 274
  291. #define SOL_PNPIPE 275
  292. #define SOL_RDS 276
  293. #define SOL_IUCV 277
  294. #define SOL_CAIF 278
  295. #define SOL_ALG 279
  296. #define SOL_NFC 280
  297. #define SOL_KCM 281
  298. #define SOL_TLS 282
  299. #define SOL_XDP 283
  300. #define SOMAXCONN 128
  301. #define MSG_OOB 0x0001
  302. #define MSG_PEEK 0x0002
  303. #define MSG_DONTROUTE 0x0004
  304. #define MSG_CTRUNC 0x0008
  305. #define MSG_PROXY 0x0010
  306. #define MSG_TRUNC 0x0020
  307. #define MSG_DONTWAIT 0x0040
  308. #define MSG_EOR 0x0080
  309. #define MSG_WAITALL 0x0100
  310. #define MSG_FIN 0x0200
  311. #define MSG_SYN 0x0400
  312. #define MSG_CONFIRM 0x0800
  313. #define MSG_RST 0x1000
  314. #define MSG_ERRQUEUE 0x2000
  315. #define MSG_NOSIGNAL 0x4000
  316. #define MSG_MORE 0x8000
  317. #define MSG_WAITFORONE 0x10000
  318. #define MSG_BATCH 0x40000
  319. #define MSG_ZEROCOPY 0x4000000
  320. #define MSG_FASTOPEN 0x20000000
  321. #define MSG_CMSG_CLOEXEC 0x40000000
  322. #define __CMSG_LEN(cmsg) (((cmsg)->cmsg_len + sizeof(long) - 1) & ~(long)(sizeof(long) - 1))
  323. #define __CMSG_NEXT(cmsg) ((unsigned char *)(cmsg) + __CMSG_LEN(cmsg))
  324. #define __MHDR_END(mhdr) ((unsigned char *)(mhdr)->msg_control + (mhdr)->msg_controllen)
  325. #define CMSG_DATA(cmsg) ((unsigned char *) (((struct cmsghdr *)(cmsg)) + 1))
  326. #define CMSG_NXTHDR(mhdr, cmsg) ((cmsg)->cmsg_len < sizeof (struct cmsghdr) || \
  327. __CMSG_LEN(cmsg) + sizeof(struct cmsghdr) >= __MHDR_END(mhdr) - (unsigned char *)(cmsg) \
  328. ? 0 : (struct cmsghdr *)__CMSG_NEXT(cmsg))
  329. #define CMSG_FIRSTHDR(mhdr) ((size_t) (mhdr)->msg_controllen >= sizeof (struct cmsghdr) ? (struct cmsghdr *) (mhdr)->msg_control : (struct cmsghdr *) 0)
  330. #define CMSG_ALIGN(len) (((len) + sizeof (size_t) - 1) & (size_t) ~(sizeof (size_t) - 1))
  331. #define CMSG_SPACE(len) (CMSG_ALIGN (len) + CMSG_ALIGN (sizeof (struct cmsghdr)))
  332. #define CMSG_LEN(len) (CMSG_ALIGN (sizeof (struct cmsghdr)) + (len))
  333. #define SCM_RIGHTS 0x01
  334. #define SCM_CREDENTIALS 0x02
  335. struct sockaddr {
  336. sa_family_t sa_family;
  337. char sa_data[14];
  338. };
  339. struct sockaddr_storage {
  340. sa_family_t ss_family;
  341. char __ss_padding[128-sizeof(long)-sizeof(sa_family_t)];
  342. unsigned long __ss_align;
  343. };
  344. int socket (int, int, int);
  345. int socketpair (int, int, int, int [2]);
  346. int shutdown (int, int);
  347. int bind (int, const struct sockaddr *, socklen_t);
  348. int connect (int, const struct sockaddr *, socklen_t);
  349. int listen (int, int);
  350. int accept (int, struct sockaddr *__restrict, socklen_t *__restrict);
  351. int accept4(int, struct sockaddr *__restrict, socklen_t *__restrict, int);
  352. int getsockname (int, struct sockaddr *__restrict, socklen_t *__restrict);
  353. int getpeername (int, struct sockaddr *__restrict, socklen_t *__restrict);
  354. ssize_t send (int, const void *, size_t, int);
  355. ssize_t recv (int, void *, size_t, int);
  356. ssize_t sendto (int, const void *, size_t, int, const struct sockaddr *, socklen_t);
  357. ssize_t recvfrom (int, void *__restrict, size_t, int, struct sockaddr *__restrict, socklen_t *__restrict);
  358. ssize_t sendmsg (int, const struct msghdr *, int);
  359. ssize_t recvmsg (int, struct msghdr *, int);
  360. int getsockopt (int, int, int, void *__restrict, socklen_t *__restrict);
  361. int setsockopt (int, int, int, const void *, socklen_t);
  362. int sockatmark (int);
  363. #if _REDIR_TIME64
  364. #ifdef _GNU_SOURCE
  365. __REDIR(recvmmsg, __recvmmsg_time64);
  366. #endif
  367. #endif
  368. #ifdef __cplusplus
  369. }
  370. #endif
  371. #endif