socket.h 8.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211
  1. #ifndef _SYS_SOCKET_H_
  2. /*
  3. * Copyright (C) 2001-2005 by egnite Software GmbH. 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. *
  9. * 1. Redistributions of source code must retain the above copyright
  10. * notice, this list of conditions and the following disclaimer.
  11. * 2. Redistributions in binary form must reproduce the above copyright
  12. * notice, this list of conditions and the following disclaimer in the
  13. * documentation and/or other materials provided with the distribution.
  14. * 3. Neither the name of the copyright holders nor the names of
  15. * contributors may be used to endorse or promote products derived
  16. * from this software without specific prior written permission.
  17. *
  18. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  19. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  20. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  21. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  22. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  23. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  24. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  25. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  26. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  27. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  28. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  29. * SUCH DAMAGE.
  30. *
  31. * For additional information see http://www.ethernut.de/
  32. *
  33. * -
  34. * Portions Copyright (c) 1983, 1993 by
  35. * The Regents of the University of California. All rights reserved.
  36. *
  37. * Redistribution and use in source and binary forms, with or without
  38. * modification, are permitted provided that the following conditions
  39. * are met:
  40. * 1. Redistributions of source code must retain the above copyright
  41. * notice, this list of conditions and the following disclaimer.
  42. * 2. Redistributions in binary form must reproduce the above copyright
  43. * notice, this list of conditions and the following disclaimer in the
  44. * documentation and/or other materials provided with the distribution.
  45. * 3. Neither the name of the University nor the names of its contributors
  46. * may be used to endorse or promote products derived from this software
  47. * without specific prior written permission.
  48. *
  49. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  50. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  51. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  52. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  53. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  54. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  55. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  56. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  57. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  58. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  59. * SUCH DAMAGE.
  60. */
  61. /*
  62. * $Log: socket.h,v $
  63. * Revision 1.8 2005/07/26 15:49:59 haraldkipp
  64. * Cygwin support added.
  65. *
  66. * Revision 1.7 2005/04/08 10:01:21 freckle
  67. * removed #defines from unix emulation as provided by system headers
  68. *
  69. * Revision 1.6 2005/04/04 19:33:54 freckle
  70. * added creation of include/netdb_orig.h, include/sys/socket_orig.h and
  71. * include/netinet/in_orig.h to allow unix emulation to use tcp/ip sockets
  72. *
  73. * Revision 1.5 2004/07/30 19:54:46 drsung
  74. * Some code of TCP stack redesigned. Round trip time calculation is now
  75. * supported. Fixed several bugs in TCP state machine. Now TCP connections
  76. * should be more reliable under heavy traffic or poor physical connections.
  77. *
  78. * Revision 1.4 2004/03/16 16:48:44 haraldkipp
  79. * Added Jan Dubiec's H8/300 port.
  80. *
  81. * Revision 1.3 2004/02/02 19:03:09 drsung
  82. * Some more ICMP support added.
  83. *
  84. * Revision 1.2 2003/11/24 21:00:21 drsung
  85. * Packet queue added for UDP sockets.
  86. *
  87. * Revision 1.1.1.1 2003/05/09 14:41:21 haraldkipp
  88. * Initial using 3.2.1
  89. *
  90. * Revision 1.7 2003/02/04 18:00:53 harald
  91. * Version 3 released
  92. *
  93. * Revision 1.6 2002/09/15 16:46:57 harald
  94. * Error prototype added
  95. *
  96. * Revision 1.5 2002/06/26 17:29:29 harald
  97. * First pre-release with 2.4 stack
  98. *
  99. */
  100. #if defined(__linux__) || defined(__APPLE__) || defined(__CYGWIN__)
  101. /* use native version on unix emulation */
  102. #include <sys/socket_orig.h>
  103. #else /* embedded systems */
  104. /*!
  105. * \addtogroup xgSocket
  106. */
  107. /*
  108. * Types
  109. */
  110. #define SOCK_STREAM 1 /*!< \brief Stream socket */
  111. #define SOCK_DGRAM 2 /*!< \brief Datagram socket */
  112. #define SOCK_RAW 3 /*!< \brief Raw-protocol interface */
  113. /*
  114. * Option flags per-socket.
  115. */
  116. #define SO_DEBUG 0x0001 /*!< \brief Turn on debugging info recording */
  117. #define SO_ACCEPTCONN 0x0002 /*!< \brief Socket has had listen() */
  118. #define SO_REUSEADDR 0x0004 /*!< \brief Allow local address reuse */
  119. #define SO_KEEPALIVE 0x0008 /*!< \brief Keep connections alive */
  120. #define SO_DONTROUTE 0x0010 /*!< \brief Just use interface addresses */
  121. #define SO_BROADCAST 0x0020 /*!< \brief Permit sending of broadcast msgs */
  122. #define SO_USELOOPBACK 0x0040 /*!< \brief Bypass hardware when possible */
  123. #define SO_LINGER 0x0080 /*!< \brief Linger on close if data present */
  124. #define SO_OOBINLINE 0x0100 /*!< \brief Leave received OOB data in line */
  125. #define SO_REUSEPORT 0x0200 /*!< \brief Allow local address & port reuse */
  126. /*
  127. * Additional options, not kept in so_options.
  128. */
  129. #define SO_SNDBUF 0x1001 /*!< \brief Send buffer size */
  130. #define SO_RCVBUF 0x1002 /*!< \brief Receive buffer size */
  131. #define SO_SNDLOWAT 0x1003 /*!< \brief Send low-water mark */
  132. #define SO_RCVLOWAT 0x1004 /*!< \brief Receive low-water mark */
  133. #define SO_SNDTIMEO 0x1005 /*!< \brief Send timeout */
  134. #define SO_RCVTIMEO 0x1006 /*!< \brief Receive timeout */
  135. #define SO_ERROR 0x1007 /*!< \brief Get error status and clear */
  136. #define SO_TYPE 0x1008 /*!< \brief Get socket type */
  137. /*
  138. * Address families.
  139. */
  140. #define AF_INET 2 /*!< \brief internetwork: UDP, TCP, etc. */
  141. #endif /* unix / embedded */
  142. /* assure _SYS_SOCKET_H_ is set */
  143. #undef _SYS_SOCKET_H_
  144. #define _SYS_SOCKET_H_
  145. #include <sys/sock_var.h>
  146. /*!
  147. * \file sys/socket.h
  148. * \brief UDP and TCP socket interface definitions.
  149. */
  150. #ifdef __cplusplus
  151. extern "C" {
  152. #endif
  153. extern TCPSOCKET *NutTcpCreateSocket(void);
  154. extern int NutTcpSetSockOpt(TCPSOCKET *sock, int optname, CONST void *optval, int optlen);
  155. extern int NutTcpGetSockOpt(TCPSOCKET *sock, int optname, void *optval, int optlen);
  156. extern int NutTcpConnect(TCPSOCKET *sock, u_long addr, u_short port);
  157. extern int NutTcpAccept(TCPSOCKET *sock, u_short port);
  158. extern void NutTcpInput(NETBUF *nb);
  159. extern int NutTcpSend(TCPSOCKET *sock, CONST void *data, u_short len);
  160. #ifdef __HARVARD_ARCH__
  161. extern int NutTcpSend_P(TCPSOCKET *sock, PGM_P data, u_short len);
  162. #endif
  163. extern int NutTcpCloseSocket(TCPSOCKET *sock);
  164. extern void NutTcpDestroySocket(TCPSOCKET *sock);
  165. extern int NutTcpReceive(TCPSOCKET *sock, void *data, u_short size);
  166. extern TCPSOCKET *NutTcpFindSocket(u_short lport, u_short rport, u_long raddr);
  167. extern int NutTcpError(TCPSOCKET *sock);
  168. extern int NutTcpAbortSocket(TCPSOCKET *sock, u_short last_error);
  169. extern void NutTcpDiscardBuffers(TCPSOCKET * sock);
  170. extern int NutTcpDeviceRead(TCPSOCKET *sock, void *buffer, int size);
  171. extern int NutTcpDeviceWrite(TCPSOCKET *sock, CONST void *buffer, int size);
  172. #ifdef __HARVARD_ARCH__
  173. extern int NutTcpDeviceWrite_P(TCPSOCKET *sock, PGM_P buffer, int size);
  174. #endif
  175. extern int NutTcpDeviceIOCtl(TCPSOCKET *sock, int cmd, void *param);
  176. extern int NutTcpDeviceClose(TCPSOCKET *sock);
  177. extern UDPSOCKET *NutUdpCreateSocket(u_short port);
  178. extern int NutUdpSendTo(UDPSOCKET *sock, u_long addr, u_short port, void *data, u_short len);
  179. extern int NutUdpReceiveFrom(UDPSOCKET *sock, u_long *addr, u_short *port, void *data, u_short size, u_long timeout);
  180. extern int NutUdpDestroySocket(UDPSOCKET *sock);
  181. extern UDPSOCKET *NutUdpFindSocket(u_short port);
  182. extern int NutUdpSetSockOpt(UDPSOCKET *sock, int optname, CONST void *optval, int optlen);
  183. extern int NutUdpGetSockOpt(UDPSOCKET *sock, int optname, void *optval, int optlen);
  184. #ifdef __cplusplus
  185. }
  186. #endif
  187. #endif