tcp.h 9.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. #ifndef _NETINET_TCP_H_
  2. #define _NETINET_TCP_H_
  3. /*
  4. * Copyright (C) 2001-2003 by egnite Software GmbH. All rights reserved.
  5. *
  6. * Redistribution and use in source and binary forms, with or without
  7. * modification, are permitted provided that the following conditions
  8. * are met:
  9. *
  10. * 1. Redistributions of source code must retain the above copyright
  11. * notice, this list of conditions and the following disclaimer.
  12. * 2. Redistributions in binary form must reproduce the above copyright
  13. * notice, this list of conditions and the following disclaimer in the
  14. * documentation and/or other materials provided with the distribution.
  15. * 3. Neither the name of the copyright holders nor the names of
  16. * contributors may be used to endorse or promote products derived
  17. * from this software without specific prior written permission.
  18. *
  19. * THIS SOFTWARE IS PROVIDED BY EGNITE SOFTWARE GMBH AND CONTRIBUTORS
  20. * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  21. * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
  22. * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL EGNITE
  23. * SOFTWARE GMBH OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
  24. * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
  25. * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
  26. * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
  27. * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
  28. * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
  29. * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  30. * SUCH DAMAGE.
  31. *
  32. * For additional information see http://www.ethernut.de/
  33. *
  34. * -
  35. * Portions Copyright (C) 2000 David J. Hudson <dave@humbug.demon.co.uk>
  36. *
  37. * This file is distributed in the hope that it will be useful, but WITHOUT
  38. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  39. * FITNESS FOR A PARTICULAR PURPOSE.
  40. *
  41. * You can redistribute this file and/or modify it under the terms of the GNU
  42. * General Public License (GPL) as published by the Free Software Foundation;
  43. * either version 2 of the License, or (at your discretion) any later version.
  44. * See the accompanying file "copying-gpl.txt" for more details.
  45. *
  46. * As a special exception to the GPL, permission is granted for additional
  47. * uses of the text contained in this file. See the accompanying file
  48. * "copying-liquorice.txt" for details.
  49. * -
  50. * Portions Copyright (c) 1983, 1993 by
  51. * The Regents of the University of California. All rights reserved.
  52. *
  53. * Redistribution and use in source and binary forms, with or without
  54. * modification, are permitted provided that the following conditions
  55. * are met:
  56. * 1. Redistributions of source code must retain the above copyright
  57. * notice, this list of conditions and the following disclaimer.
  58. * 2. Redistributions in binary form must reproduce the above copyright
  59. * notice, this list of conditions and the following disclaimer in the
  60. * documentation and/or other materials provided with the distribution.
  61. * 3. Neither the name of the University nor the names of its contributors
  62. * may be used to endorse or promote products derived from this software
  63. * without specific prior written permission.
  64. *
  65. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  66. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  67. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  68. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  69. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  70. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  71. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  72. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  73. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  74. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  75. * SUCH DAMAGE.
  76. */
  77. /*
  78. * $Log: tcp.h,v $
  79. * Revision 1.5 2006/03/21 21:22:18 drsung
  80. * Enhancement made to TCP state machine. Now TCP options
  81. * are read from peer and at least the maximum segment size is stored.
  82. *
  83. * Revision 1.4 2005/08/02 17:46:49 haraldkipp
  84. * Major API documentation update.
  85. *
  86. * Revision 1.3 2005/04/05 17:38:45 haraldkipp
  87. * ARM7 memory alignment bugs fixed.
  88. *
  89. * Revision 1.2 2004/03/16 16:48:28 haraldkipp
  90. * Added Jan Dubiec's H8/300 port.
  91. *
  92. * Revision 1.1.1.1 2003/05/09 14:41:16 haraldkipp
  93. * Initial using 3.2.1
  94. *
  95. * Revision 1.7 2003/02/04 18:00:46 harald
  96. * Version 3 released
  97. *
  98. * Revision 1.6 2002/09/03 17:49:58 harald
  99. * *** empty log message ***
  100. *
  101. * Revision 1.5 2002/08/16 17:53:36 harald
  102. * Larger window size for better MP3 stream results
  103. *
  104. * Revision 1.4 2002/06/26 17:29:22 harald
  105. * First pre-release with 2.4 stack
  106. *
  107. */
  108. #include <sys/types.h>
  109. /*!
  110. * \file netinet/tcp.h
  111. * \brief TCP protocol definitions.
  112. */
  113. #ifdef __cplusplus
  114. extern "C" {
  115. #endif
  116. #define TH_FIN 0x01 /*!< \brief Finishing transmission. */
  117. #define TH_SYN 0x02 /*!< \brief Synchronizing sequence numbers. */
  118. #define TH_RST 0x04 /*!< \brief Reset connection. */
  119. #define TH_PUSH 0x08 /*!< \brief Push data to application level. */
  120. #define TH_ACK 0x10 /*!< \brief Acknowledge field is valid. */
  121. #define TH_URG 0x20 /*!< \brief Urgent data present. */
  122. /*! \brief TCP flag mask. */
  123. #define TH_FLAGS (TH_FIN | TH_SYN | TH_RST | TH_ACK | TH_URG)
  124. /*!
  125. * \struct tcphdr tcp.h netinet/tcp.h
  126. * \brief TCP protocol header structure.
  127. */
  128. /*!
  129. * \typedef TCPHDR
  130. * \brief TCP protocol header type.
  131. */
  132. typedef struct __attribute__ ((packed)) tcphdr {
  133. u_short th_sport; /*!< \brief Source port. */
  134. u_short th_dport; /*!< \brief Destination port. */
  135. u_long th_seq; /*!< \brief Sequence number of first octet in this segment. */
  136. u_long th_ack; /*!< \brief Expected sequence number of next octet. */
  137. #ifndef __BIG_ENDIAN__
  138. #ifdef __IMAGECRAFT__
  139. unsigned th_x2:4,
  140. th_off:4;
  141. #else /* #ifndef __BIG_ENDIAN__ */
  142. u_char th_x2:4, /*!< \brief Unused. */
  143. th_off:4; /*!< \brief Data offset. */
  144. #endif
  145. #else /* #ifndef __BIG_ENDIAN__ */
  146. u_char th_off:4, /*!< \brief Data offset. */
  147. th_x2:4; /*!< \brief Unused. */
  148. #endif
  149. u_char th_flags; /*!< \brief Control flags. */
  150. u_short th_win; /*!< \brief Number of acceptable octects. */
  151. u_short th_sum; /*!< \brief 96 byte pseudo header checksum. */
  152. u_short th_urp; /*!< \brief Urgent data pointer. */
  153. } TCPHDR;
  154. #define TCPOPT_EOL 0 /*!< \brief End of options. */
  155. #define TCPOPT_NOP 1 /*!< \brief Nothing. */
  156. #define TCPOPT_MAXSEG 2 /*!< \brief Maximum segment size. */
  157. #define TCPOLEN_MAXSEG 4 /*!< \brief Maximum segment size length. */
  158. #define TCPOPT_WINDOW 3 /*!< \brief Receive window. */
  159. #define TCPOLEN_WINDOW 3 /*!< \brief Receive window length. */
  160. /*!
  161. * \struct _TCPPSEUDOHDR tcp.h netinet/tcp.h
  162. * \brief TCP pseudo header structure.
  163. */
  164. /*!
  165. * \typedef TCPPSEUDOHDR
  166. * \brief TCP pseudo header type.
  167. */
  168. typedef struct _TCPPSEUDOHDR {
  169. u_long tph_src; /*!< \brief IP address of sender. */
  170. u_long tph_dst; /*!< \brief IP address of target. */
  171. u_char tph_mbz; /*!< \brief mbz */
  172. u_char tph_p; /*!< \brief p */
  173. u_short tph_len; /*!< \brief len */
  174. u_short tph_sum; /*!< \brief Checksum */
  175. } TCPPSEUDOHDR;
  176. #define TCP_MSS 536 /*!< \brief Default maximum segment size.
  177. The maximum size of an IP datagram, that will
  178. not become fragmented, is 576. The maximum
  179. IP datagram for Ethernet is 1500. Reduce this
  180. number by 40, 20 bytes TCP header and 20 bytes
  181. IP header.
  182. \showinitializer
  183. */
  184. #define TCP_WINSIZE 3216 /*!< \brief Default window size.
  185. It's recommended to set this 6 times the maximum
  186. segment size.
  187. \showinitializer
  188. */
  189. #define TCP_MAXWIN 65535 /*!< \brief Largest value for (unscaled) window. \showinitializer */
  190. #define TTCP_CLIENT_SND_WND 4096 /*!< \brief Default send window for T/TCP client. \showinitializer */
  191. #define TCP_MAX_WINSHIFT 14 /*!< \brief Maximum window shift. \showinitializer */
  192. #define TCP_MAXHLEN (0xf<<2) /*!< \brief Maximum length of header in bytes. */
  193. #define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr)) /*!< \brief Maximum space left for options. */
  194. /*
  195. * User-settable options.
  196. */
  197. #define TCP_NODELAY 0x01 /*!< \brief Don't delay send to coalesce segments. */
  198. #define TCP_MAXSEG 0x02 /*!< \brief Set maximum segment size. */
  199. #define TCP_NOPUSH 0x04 /*!< \brief Don't push last block of write. */
  200. #define TCP_NOOPT 0x08 /*!< \brief Don't use TCP options. */
  201. #ifdef __cplusplus
  202. }
  203. #endif
  204. #endif