PageRenderTime 28ms CodeModel.GetById 6ms RepoModel.GetById 0ms app.codeStats 0ms

/nuttx/include/sys/socket.h

https://gitlab.com/BlueCabbage/NuttX
C Header | 234 lines | 113 code | 32 blank | 89 comment | 0 complexity | ee44a85d2eda069912daeb883d0c0581 MD5 | raw file
  1. /****************************************************************************
  2. * include/sys/socket.h
  3. *
  4. * Copyright (C) 2007, 2009, 2011 Gregory Nutt. All rights reserved.
  5. * Author: Gregory Nutt <gnutt@nuttx.org>
  6. *
  7. * Redistribution and use in source and binary forms, with or without
  8. * modification, are permitted provided that the following conditions
  9. * are met:
  10. *
  11. * 1. Redistributions of source code must retain the above copyright
  12. * notice, this list of conditions and the following disclaimer.
  13. * 2. Redistributions in binary form must reproduce the above copyright
  14. * notice, this list of conditions and the following disclaimer in
  15. * the documentation and/or other materials provided with the
  16. * distribution.
  17. * 3. Neither the name NuttX nor the names of its contributors may be
  18. * used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  22. * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  23. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  24. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
  25. * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  26. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  27. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  28. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  29. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  30. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
  31. * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
  32. * POSSIBILITY OF SUCH DAMAGE.
  33. *
  34. ****************************************************************************/
  35. #ifndef __INCLUDE_SYS_SOCKET_H
  36. #define __INCLUDE_SYS_SOCKET_H
  37. /****************************************************************************
  38. * Included Files
  39. ****************************************************************************/
  40. #include <sys/types.h>
  41. /****************************************************************************
  42. * Definitions
  43. ****************************************************************************/
  44. /* The socket()domain parameter specifies a communication domain; this selects
  45. * the protocol family which will be used for communication.
  46. */
  47. /* Protocol families */
  48. #define PF_UNSPEC 0 /* Protocol family unspecified */
  49. #define PF_UNIX 1 /* Local communication */
  50. #define PF_LOCAL 1 /* Local communication */
  51. #define PF_INET 2 /* IPv4 Internet protocols */
  52. #define PF_INET6 3 /* IPv6 Internet protocols */
  53. #define PF_IPX 4 /* IPX - Novell protocols */
  54. #define PF_NETLINK 5 /* Kernel user interface device */
  55. #define PF_X25 6 /* ITU-T X.25 / ISO-8208 protocol */
  56. #define PF_AX25 7 /* Amateur radio AX.25 protocol */
  57. #define PF_ATMPVC 8 /* Access to raw ATM PVCs */
  58. #define PF_APPLETALK 9 /* Appletalk */
  59. #define PF_PACKET 10 /* Low level packet interface */
  60. /* Address families */
  61. #define AF_UNSPEC PF_UNSPEC
  62. #define AF_UNIX PF_UNIX
  63. #define AF_LOCAL PF_LOCAL
  64. #define AF_INET PF_INET
  65. #define AF_INET6 PF_INET6
  66. #define AF_IPX PF_IPX
  67. #define AF_NETLINK PF_NETLINK
  68. #define AF_X25 PF_X25
  69. #define AF_AX25 PF_AX25
  70. #define AF_ATMPVC PF_ATMPVC
  71. #define AF_APPLETALK PF_APPLETALK
  72. #define AF_PACKET PF_PACKET
  73. /* The socket created by socket() has the indicated type, which specifies
  74. * the communication semantics.
  75. */
  76. #define SOCK_STREAM 0 /* Provides sequenced, reliable, two-way, connection-based byte streams.
  77. * An out-of-band data transmission mechanism may be supported. */
  78. #define SOCK_DGRAM 1 /* Supports datagrams (connectionless, unreliable messages of a fixed
  79. * maximum length). */
  80. #define SOCK_SEQPACKET 2 /* Provides a sequenced, reliable, two-way connection-based data
  81. * transmission path for datagrams of fixed maximum length; a consumer
  82. * is required to read an entire packet with each read system call. */
  83. #define SOCK_RAW 3 /* Provides raw network protocol access. */
  84. #define SOCK_RDM 4 /* Provides a reliable datagram layer that does not guarantee ordering. */
  85. #define SOCK_PACKET 5 /* Obsolete and should not be used in new programs */
  86. /* Bits in the FLAGS argument to `send', `recv', et al. These are the bits
  87. * recognized by Linus, not all are supported by NuttX.
  88. */
  89. #define MSG_OOB 0x0001 /* Process out-of-band data. */
  90. #define MSG_PEEK 0x0002 /* Peek at incoming messages. */
  91. #define MSG_DONTROUTE 0x0004 /* Don't use local routing. */
  92. #define MSG_CTRUNC 0x0008 /* Control data lost before delivery. */
  93. #define MSG_PROXY 0x0010 /* Supply or ask second address. */
  94. #define MSG_TRUNC 0x0020
  95. #define MSG_DONTWAIT 0x0040 /* Enable nonblocking IO. */
  96. #define MSG_EOR 0x0080 /* End of record. */
  97. #define MSG_WAITALL 0x0100 /* Wait for a full request. */
  98. #define MSG_FIN 0x0200
  99. #define MSG_SYN 0x0400
  100. #define MSG_CONFIRM 0x0800 /* Confirm path validity. */
  101. #define MSG_RST 0x1000
  102. #define MSG_ERRQUEUE 0x2000 /* Fetch message from error queue. */
  103. #define MSG_NOSIGNAL 0x4000 /* Do not generate SIGPIPE. */
  104. #define MSG_MORE 0x8000 /* Sender will send more. */
  105. /* Socket options */
  106. #define SO_DEBUG 0 /* Enables recording of debugging information (get/set).
  107. * arg: pointer to integer containing a boolean value */
  108. #define SO_ACCEPTCONN 1 /* Reports whether socket listening is enabled (get only).
  109. * arg: pointer to integer containing a boolean value */
  110. #define SO_BROADCAST 2 /* Permits sending of broadcast messages (get/set).
  111. * arg: pointer to integer containing a boolean value */
  112. #define SO_REUSEADDR 3 /* Allow reuse of local addresses (get/set)
  113. * arg: pointer to integer containing a boolean value */
  114. #define SO_KEEPALIVE 4 /* Keeps connections active by enabling the periodic transmission
  115. * of messages (get/set).
  116. * arg: pointer to integer containing a boolean value */
  117. #define SO_LINGER 5 /* Lingers on a close() if data is present (get/set)
  118. * arg: struct linger */
  119. #define SO_OOBINLINE 6 /* Leaves received out-of-band data (data marked urgent) inline
  120. * (get/set) arg: pointer to integer containing a boolean value */
  121. #define SO_SNDBUF 7 /* Sets send buffer size. arg: integer value (get/set). */
  122. #define SO_RCVBUF 8 /* Sets receive buffer size. arg: integer value (get/set). */
  123. #define SO_ERROR 9 /* Reports and clears error status (get only). arg: returns
  124. * an integer value */
  125. #define SO_TYPE 10 /* Reports the socket type (get only). return: int */
  126. #define SO_DONTROUTE 11 /* Requests that outgoing messages bypass standard routing (get/set)
  127. * arg: pointer to integer containing a boolean value */
  128. #define SO_RCVLOWAT 12 /* Sets the minimum number of bytes to process for socket input
  129. * (get/set). arg: integer value */
  130. #define SO_RCVTIMEO 13 /* Sets the timeout value that specifies the maximum amount of time
  131. * an input function waits until it completes (get/set).
  132. * arg: struct timeval */
  133. #define SO_SNDLOWAT 14 /* Sets the minimum number of bytes to process for socket output
  134. * (get/set). arg: integer value */
  135. #define SO_SNDTIMEO 15 /* Sets the timeout value specifying the amount of time that an
  136. * output function blocks because flow control prevents data from
  137. * being sent(get/set). arg: struct timeval */
  138. /* Protocol levels supported by get/setsockopt(): */
  139. #define SOL_SOCKET 0 /* Only socket-level options supported */
  140. /****************************************************************************
  141. * Type Definitions
  142. ****************************************************************************/
  143. /* sockaddr_storage structure. This structure must be (1) large enough to
  144. * accommodate all supported protocol-specific address structures, and (2)
  145. * aligned at an appropriate boundary so that pointers to it can be cast
  146. * as pointers to protocol-specific address structures and used to access
  147. * the fields of those structures without alignment problems
  148. */
  149. #ifdef CONFIG_NET_IPv6
  150. struct sockaddr_storage
  151. {
  152. sa_family_t ss_family; /* Address family */
  153. char ss_data[18]; /* 18-bytes of address data */
  154. };
  155. #else
  156. struct sockaddr_storage
  157. {
  158. sa_family_t ss_family; /* Address family */
  159. char ss_data[14]; /* 14-bytes of address data */
  160. };
  161. #endif
  162. /* The sockaddr structure is used to define a socket address which is used
  163. * in the bind(), connect(), getpeername(), getsockname(), recvfrom(), and
  164. * sendto() functions.
  165. */
  166. struct sockaddr
  167. {
  168. sa_family_t sa_family; /* Address family: See AF_* definitions */
  169. char sa_data[14]; /* 14-bytes of address data */
  170. };
  171. /****************************************************************************
  172. * Public Function Prototypes
  173. ****************************************************************************/
  174. #undef EXTERN
  175. #if defined(__cplusplus)
  176. #define EXTERN extern "C"
  177. extern "C" {
  178. #else
  179. #define EXTERN extern
  180. #endif
  181. EXTERN int socket(int domain, int type, int protocol);
  182. EXTERN int bind(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen);
  183. EXTERN int connect(int sockfd, FAR const struct sockaddr *addr, socklen_t addrlen);
  184. EXTERN int listen(int sockfd, int backlog);
  185. EXTERN int accept(int sockfd, struct sockaddr *addr, socklen_t *addrlen);
  186. EXTERN ssize_t send(int sockfd, FAR const void *buf, size_t len, int flags);
  187. EXTERN ssize_t sendto(int sockfd, FAR const void *buf, size_t len, int flags,
  188. FAR const struct sockaddr *to, socklen_t tolen);
  189. EXTERN ssize_t recv(int sockfd, FAR void *buf, size_t len, int flags);
  190. EXTERN ssize_t recvfrom(int sockfd, FAR void *buf, size_t len, int flags,
  191. FAR struct sockaddr *from, FAR socklen_t *fromlen);
  192. EXTERN int setsockopt(int sockfd, int level, int option,
  193. FAR const void *value, socklen_t value_len);
  194. EXTERN int getsockopt(int sockfd, int level, int option,
  195. FAR void *value, FAR socklen_t *value_len);
  196. EXTERN int getsockname(int sockfd, FAR struct sockaddr *addr,
  197. FAR socklen_t *addrlen);
  198. #undef EXTERN
  199. #if defined(__cplusplus)
  200. }
  201. #endif
  202. #endif /* __INCLUDE_SYS_SOCKET_H */