PageRenderTime 53ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/include/sys/socket.h

http://www.minix3.org/
C++ Header | 309 lines | 225 code | 40 blank | 44 comment | 3 complexity | b5a66fa0de0bf165492a09a72e3a0137 MD5 | raw file
Possible License(s): MIT, WTFPL, AGPL-1.0, BSD-3-Clause, GPL-3.0, LGPL-2.0, JSON, 0BSD
  1. #ifndef _SYS_SOCKET_H_
  2. #define _SYS_SOCKET_H_
  3. #include <sys/featuretest.h>
  4. /*
  5. * Definitions related to sockets: types, address families, options.
  6. */
  7. /*
  8. * Data types.
  9. */
  10. #include <sys/ansi.h>
  11. #ifndef sa_family_t
  12. typedef __sa_family_t sa_family_t;
  13. #define sa_family_t __sa_family_t
  14. #endif
  15. #ifndef socklen_t
  16. typedef __socklen_t socklen_t;
  17. #define socklen_t __socklen_t
  18. #endif
  19. #include <machine/ansi.h>
  20. #ifdef _BSD_SIZE_T_
  21. typedef _BSD_SIZE_T_ size_t;
  22. #undef _BSD_SIZE_T_
  23. #endif
  24. #ifdef _BSD_SSIZE_T_
  25. typedef _BSD_SSIZE_T_ ssize_t;
  26. #undef _BSD_SSIZE_T_
  27. #endif
  28. #include <sys/uio.h>
  29. /*
  30. * Socket types.
  31. */
  32. #define SOCK_STREAM 1 /* stream socket */
  33. #define SOCK_DGRAM 2 /* datagram socket */
  34. #define SOCK_RAW 3 /* raw-protocol interface */
  35. #define SOCK_RDM 4 /* reliably-delivered message */
  36. #define SOCK_SEQPACKET 5 /* sequenced packet stream */
  37. /*
  38. * Option flags per-socket.
  39. */
  40. #define SO_DEBUG 0x0001 /* turn on debugging info recording */
  41. #define SO_REUSEADDR 0x0004 /* allow local address reuse */
  42. #define SO_KEEPALIVE 0x0008 /* keep connections alive */
  43. #define SO_TYPE 0x0010 /* get socket type */
  44. #define SO_PASSCRED 0x0012
  45. #define SO_PEERCRED 0x0014
  46. #define SO_SNDBUF 0x1001 /* send buffer size */
  47. #define SO_RCVBUF 0x1002 /* receive buffer size */
  48. #define SO_ERROR 0x1007 /* get error status and clear */
  49. /*
  50. * Level number for (get/set)sockopt() to apply to socket itself.
  51. */
  52. #define SOL_SOCKET 0xffff /* options for socket level */
  53. /*
  54. * Address families.
  55. */
  56. #define AF_UNSPEC 0 /* unspecified */
  57. #define AF_LOCAL 1 /* local to host */
  58. #define AF_UNIX AF_LOCAL /* backward compatibility */
  59. #define AF_INET 2 /* internetwork: UDP, TCP, etc. */
  60. #define AF_IMPLINK 3 /* arpanet imp addresses */
  61. #define AF_PUP 4 /* pup protocols: e.g. BSP */
  62. #define AF_CHAOS 5 /* mit CHAOS protocols */
  63. #define AF_NS 6 /* XEROX NS protocols */
  64. #define AF_ISO 7 /* ISO protocols */
  65. #define AF_OSI AF_ISO
  66. #define AF_ECMA 8 /* european computer manufacturers */
  67. #define AF_DATAKIT 9 /* datakit protocols */
  68. #define AF_CCITT 10 /* CCITT protocols, X.25 etc */
  69. #define AF_SNA 11 /* IBM SNA */
  70. #define AF_DECnet 12 /* DECnet */
  71. #define AF_DLI 13 /* DEC Direct data link interface */
  72. #define AF_LAT 14 /* LAT */
  73. #define AF_HYLINK 15 /* NSC Hyperchannel */
  74. #define AF_APPLETALK 16 /* Apple Talk */
  75. #define AF_ROUTE 17 /* Internal Routing Protocol */
  76. #define AF_LINK 18 /* Link layer interface */
  77. #if defined(_NETBSD_SOURCE)
  78. #define pseudo_AF_XTP 19 /* eXpress Transfer Protocol (no AF) */
  79. #endif
  80. #define AF_COIP 20 /* connection-oriented IP, aka ST II */
  81. #define AF_CNT 21 /* Computer Network Technology */
  82. #if defined(_NETBSD_SOURCE)
  83. #define pseudo_AF_RTIP 22 /* Help Identify RTIP packets */
  84. #endif
  85. #define AF_IPX 23 /* Novell Internet Protocol */
  86. #define AF_INET6 24 /* IP version 6 */
  87. #if defined(_NETBSD_SOURCE)
  88. #define pseudo_AF_PIP 25 /* Help Identify PIP packets */
  89. #endif
  90. #define AF_ISDN 26 /* Integrated Services Digital Network*/
  91. #define AF_E164 AF_ISDN /* CCITT E.164 recommendation */
  92. #define AF_NATM 27 /* native ATM access */
  93. #define AF_ARP 28 /* (rev.) addr. res. prot. (RFC 826) */
  94. #if defined(_NETBSD_SOURCE)
  95. #define pseudo_AF_KEY 29 /* Internal key management protocol */
  96. #define pseudo_AF_HDRCMPLT 30 /* Used by BPF to not rewrite hdrs
  97. in interface output routine */
  98. #endif
  99. #define AF_BLUETOOTH 31 /* Bluetooth: HCI, SCO, L2CAP, RFCOMM */
  100. #define AF_IEEE80211 32 /* IEEE80211 */
  101. #define AF_MAX 33
  102. #ifndef gid_t
  103. typedef __gid_t gid_t; /* group id */
  104. #define gid_t __gid_t
  105. #endif
  106. #ifndef uid_t
  107. typedef __uid_t uid_t; /* user id */
  108. #define uid_t __uid_t
  109. #endif
  110. #include <sys/ucred.h>
  111. /*
  112. * Structure used by kernel to store most
  113. * addresses.
  114. */
  115. struct sockaddr
  116. {
  117. sa_family_t sa_family;
  118. char sa_data[8]; /* Big enough for sockaddr_in */
  119. };
  120. /*
  121. * RFC 2553: protocol-independent placeholder for socket addresses
  122. */
  123. #define _SS_MAXSIZE 128
  124. #define _SS_ALIGNSIZE (sizeof(__int64_t))
  125. #define _SS_PAD1SIZE (_SS_ALIGNSIZE - 1)
  126. #define _SS_PAD2SIZE (_SS_MAXSIZE - 1 - \
  127. _SS_PAD1SIZE - _SS_ALIGNSIZE)
  128. #if (_XOPEN_SOURCE - 0) >= 500 || defined(_NETBSD_SOURCE)
  129. struct sockaddr_storage {
  130. sa_family_t ss_family; /* address family */
  131. char __ss_pad1[_SS_PAD1SIZE];
  132. __int64_t __ss_align;/* force desired structure storage alignment */
  133. char __ss_pad2[_SS_PAD2SIZE];
  134. };
  135. #define sstosa(__ss) ((struct sockaddr *)(__ss))
  136. #define sstocsa(__ss) ((const struct sockaddr *)(__ss))
  137. #endif /* _XOPEN_SOURCE >= 500 || _NETBSD_SOURCE */
  138. /*
  139. * Protocol families, same as address families for now.
  140. */
  141. #define PF_UNSPEC AF_UNSPEC
  142. #define PF_LOCAL AF_LOCAL
  143. #define PF_UNIX PF_LOCAL /* backward compatibility */
  144. #define PF_FILE PF_LOCAL /* Minix compatibility */
  145. #define PF_INET AF_INET
  146. #define PF_IMPLINK AF_IMPLINK
  147. #define PF_PUP AF_PUP
  148. #define PF_CHAOS AF_CHAOS
  149. #define PF_NS AF_NS
  150. #define PF_ISO AF_ISO
  151. #define PF_OSI AF_ISO
  152. #define PF_ECMA AF_ECMA
  153. #define PF_DATAKIT AF_DATAKIT
  154. #define PF_CCITT AF_CCITT
  155. #define PF_SNA AF_SNA
  156. #define PF_DECnet AF_DECnet
  157. #define PF_DLI AF_DLI
  158. #define PF_LAT AF_LAT
  159. #define PF_HYLINK AF_HYLINK
  160. #define PF_APPLETALK AF_APPLETALK
  161. #define PF_ROUTE AF_ROUTE
  162. #define PF_LINK AF_LINK
  163. #if defined(_NETBSD_SOURCE)
  164. #define PF_XTP pseudo_AF_XTP /* really just proto family, no AF */
  165. #endif
  166. #define PF_COIP AF_COIP
  167. #define PF_CNT AF_CNT
  168. #define PF_INET6 AF_INET6
  169. #define PF_IPX AF_IPX /* same format as AF_NS */
  170. #if defined(_NETBSD_SOURCE)
  171. #define PF_RTIP pseudo_AF_RTIP /* same format as AF_INET */
  172. #define PF_PIP pseudo_AF_PIP
  173. #endif
  174. #define PF_ISDN AF_ISDN /* same as E164 */
  175. #define PF_E164 AF_E164
  176. #define PF_NATM AF_NATM
  177. #define PF_ARP AF_ARP
  178. #if defined(_NETBSD_SOURCE)
  179. #define PF_KEY pseudo_AF_KEY /* like PF_ROUTE, only for key mgmt */
  180. #endif
  181. #define PF_BLUETOOTH AF_BLUETOOTH
  182. #define PF_MAX AF_MAX
  183. /*
  184. * Message header for recvmsg and sendmsg calls.
  185. * Used value-result for recvmsg, value only for sendmsg.
  186. */
  187. struct msghdr {
  188. void *msg_name; /* optional address */
  189. socklen_t msg_namelen; /* size of address */
  190. struct iovec *msg_iov; /* scatter/gather array */
  191. int msg_iovlen; /* # elements in msg_iov */
  192. void *msg_control; /* ancillary data, see below */
  193. socklen_t msg_controllen; /* ancillary data buffer len */
  194. int msg_flags; /* flags on received message */
  195. };
  196. /*
  197. * Header for ancillary data objects in msg_control buffer.
  198. * Used for additional information with/about a datagram
  199. * not expressible by flags. The format is a sequence
  200. * of message elements headed by cmsghdr structures.
  201. */
  202. struct cmsghdr {
  203. socklen_t cmsg_len; /* data byte count, including hdr */
  204. int cmsg_level; /* originating protocol */
  205. int cmsg_type; /* protocol-specific type */
  206. /* followed by u_char cmsg_data[]; */
  207. };
  208. #define CMSG_FIRSTHDR(mhdr) \
  209. ( (mhdr)->msg_controllen >= sizeof(struct cmsghdr) ? \
  210. (struct cmsghdr *)(mhdr)->msg_control : \
  211. (struct cmsghdr *)NULL )
  212. #define CMSG_ALIGN(len) \
  213. ( (len % sizeof(long) == 0) ? \
  214. len : \
  215. len + sizeof(long) - (len % sizeof(long)) )
  216. #define CMSG_NXTHDR(mhdr, cmsg) \
  217. ( ((cmsg) == NULL) ? CMSG_FIRSTHDR(mhdr) : \
  218. (((unsigned char *)(cmsg) + CMSG_ALIGN((cmsg)->cmsg_len) \
  219. + CMSG_ALIGN(sizeof(struct cmsghdr)) > \
  220. (unsigned char *)((mhdr)->msg_control) + \
  221. (mhdr)->msg_controllen) ? \
  222. (struct cmsghdr *)NULL : \
  223. (struct cmsghdr *)((unsigned char *)(cmsg) + \
  224. CMSG_ALIGN((cmsg)->cmsg_len))) )
  225. #define CMSG_DATA(cmsg) \
  226. ( (unsigned char *)(cmsg) + CMSG_ALIGN(sizeof(struct cmsghdr)) )
  227. #define CMSG_SPACE(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + CMSG_ALIGN(l))
  228. #define CMSG_LEN(l) (CMSG_ALIGN(sizeof(struct cmsghdr)) + (l))
  229. /* "Socket"-level control message types: */
  230. #define SCM_RIGHTS 0x01
  231. #define SCM_CREDENTIALS 0x02
  232. #define SCM_SECURITY 0x04
  233. /*
  234. * Types of socket shutdown(2).
  235. */
  236. #define SHUT_RD 0 /* Disallow further receives. */
  237. #define SHUT_WR 1 /* Disallow further sends. */
  238. #define SHUT_RDWR 2 /* Disallow further sends/receives. */
  239. #include <sys/cdefs.h>
  240. __BEGIN_DECLS
  241. int __cmsg_alignbytes(void);
  242. __END_DECLS
  243. __BEGIN_DECLS
  244. int accept(int, struct sockaddr * __restrict, socklen_t * __restrict);
  245. int bind(int, const struct sockaddr *, socklen_t);
  246. int connect(int, const struct sockaddr *, socklen_t);
  247. int getpeername(int, struct sockaddr * __restrict, socklen_t * __restrict);
  248. int getsockname(int, struct sockaddr * __restrict, socklen_t * __restrict);
  249. int getsockopt(int, int, int, void *__restrict, socklen_t * __restrict);
  250. int listen(int, int);
  251. ssize_t recv(int, void *, size_t, int);
  252. ssize_t recvfrom(int, void *__restrict, size_t, int,
  253. struct sockaddr * __restrict, socklen_t * __restrict);
  254. ssize_t recvmsg(int, struct msghdr *, int);
  255. ssize_t send(int, const void *, size_t, int);
  256. ssize_t sendto(int, const void *,
  257. size_t, int, const struct sockaddr *, socklen_t);
  258. ssize_t sendmsg(int, const struct msghdr *, int);
  259. int setsockopt(int, int, int, const void *, socklen_t);
  260. int shutdown(int, int);
  261. int sockatmark(int);
  262. int socket(int, int, int);
  263. int socketpair(int, int, int, int *);
  264. __END_DECLS
  265. #define MSG_OOB 0x0001 /* process out-of-band data */
  266. #define MSG_PEEK 0x0002 /* peek at incoming message */
  267. #define MSG_DONTROUTE 0x0004 /* send without using routing tables */
  268. #define MSG_EOR 0x0008 /* complete record */
  269. #endif /* !_SYS_SOCKET_H_ */