socket.h 9.3 KB

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