tcp.h 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225
  1. /*
  2. * Copyright (c) 1982, 1986, 1993
  3. * The Regents of the University of California. 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. * 1. Redistributions of source code must retain the above copyright
  9. * notice, this list of conditions and the following disclaimer.
  10. * 2. Redistributions in binary form must reproduce the above copyright
  11. * notice, this list of conditions and the following disclaimer in the
  12. * documentation and/or other materials provided with the distribution.
  13. * 4. Neither the name of the University nor the names of its contributors
  14. * may be used to endorse or promote products derived from this software
  15. * without specific prior written permission.
  16. *
  17. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  18. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  19. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  20. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  21. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  22. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  23. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  24. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  25. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  26. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  27. * SUCH DAMAGE.
  28. *
  29. * @(#)tcp.h 8.1 (Berkeley) 6/10/93
  30. */
  31. #ifndef _NETINET_TCP_H
  32. #define _NETINET_TCP_H 1
  33. #include <features.h>
  34. /*
  35. * User-settable options (used with setsockopt).
  36. */
  37. #define TCP_NODELAY 1 /* Don't delay send to coalesce packets */
  38. #define TCP_MAXSEG 2 /* Set maximum segment size */
  39. #define TCP_CORK 3 /* Control sending of partial frames */
  40. #define TCP_KEEPIDLE 4 /* Start keeplives after this period */
  41. #define TCP_KEEPINTVL 5 /* Interval between keepalives */
  42. #define TCP_KEEPCNT 6 /* Number of keepalives before death */
  43. #define TCP_SYNCNT 7 /* Number of SYN retransmits */
  44. #define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */
  45. #define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */
  46. #define TCP_WINDOW_CLAMP 10 /* Bound advertised window */
  47. #define TCP_INFO 11 /* Information about this connection. */
  48. #define TCP_QUICKACK 12 /* Bock/reenable quick ACKs. */
  49. #ifdef __USE_MISC
  50. # include <sys/types.h>
  51. # ifdef __FAVOR_BSD
  52. typedef u_int32_t tcp_seq;
  53. /*
  54. * TCP header.
  55. * Per RFC 793, September, 1981.
  56. */
  57. struct tcphdr
  58. {
  59. u_int16_t th_sport; /* source port */
  60. u_int16_t th_dport; /* destination port */
  61. tcp_seq th_seq; /* sequence number */
  62. tcp_seq th_ack; /* acknowledgement number */
  63. # if __BYTE_ORDER == __LITTLE_ENDIAN
  64. u_int8_t th_x2:4; /* (unused) */
  65. u_int8_t th_off:4; /* data offset */
  66. # endif
  67. # if __BYTE_ORDER == __BIG_ENDIAN
  68. u_int8_t th_off:4; /* data offset */
  69. u_int8_t th_x2:4; /* (unused) */
  70. # endif
  71. u_int8_t th_flags;
  72. # define TH_FIN 0x01
  73. # define TH_SYN 0x02
  74. # define TH_RST 0x04
  75. # define TH_PUSH 0x08
  76. # define TH_ACK 0x10
  77. # define TH_URG 0x20
  78. u_int16_t th_win; /* window */
  79. u_int16_t th_sum; /* checksum */
  80. u_int16_t th_urp; /* urgent pointer */
  81. };
  82. # else /* !__FAVOR_BSD */
  83. struct tcphdr
  84. {
  85. u_int16_t source;
  86. u_int16_t dest;
  87. u_int32_t seq;
  88. u_int32_t ack_seq;
  89. # if __BYTE_ORDER == __LITTLE_ENDIAN
  90. u_int16_t res1:4;
  91. u_int16_t doff:4;
  92. u_int16_t fin:1;
  93. u_int16_t syn:1;
  94. u_int16_t rst:1;
  95. u_int16_t psh:1;
  96. u_int16_t ack:1;
  97. u_int16_t urg:1;
  98. u_int16_t res2:2;
  99. # elif __BYTE_ORDER == __BIG_ENDIAN
  100. u_int16_t doff:4;
  101. u_int16_t res1:4;
  102. u_int16_t res2:2;
  103. u_int16_t urg:1;
  104. u_int16_t ack:1;
  105. u_int16_t psh:1;
  106. u_int16_t rst:1;
  107. u_int16_t syn:1;
  108. u_int16_t fin:1;
  109. # else
  110. # error "Adjust your <bits/endian.h> defines"
  111. # endif
  112. u_int16_t window;
  113. u_int16_t check;
  114. u_int16_t urg_ptr;
  115. };
  116. # endif /* __FAVOR_BSD */
  117. enum
  118. {
  119. TCP_ESTABLISHED = 1,
  120. TCP_SYN_SENT,
  121. TCP_SYN_RECV,
  122. TCP_FIN_WAIT1,
  123. TCP_FIN_WAIT2,
  124. TCP_TIME_WAIT,
  125. TCP_CLOSE,
  126. TCP_CLOSE_WAIT,
  127. TCP_LAST_ACK,
  128. TCP_LISTEN,
  129. TCP_CLOSING /* now a valid state */
  130. };
  131. # define TCPOPT_EOL 0
  132. # define TCPOPT_NOP 1
  133. # define TCPOPT_MAXSEG 2
  134. # define TCPOLEN_MAXSEG 4
  135. # define TCPOPT_WINDOW 3
  136. # define TCPOLEN_WINDOW 3
  137. # define TCPOPT_SACK_PERMITTED 4 /* Experimental */
  138. # define TCPOLEN_SACK_PERMITTED 2
  139. # define TCPOPT_SACK 5 /* Experimental */
  140. # define TCPOPT_TIMESTAMP 8
  141. # define TCPOLEN_TIMESTAMP 10
  142. # define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
  143. # define TCPOPT_TSTAMP_HDR \
  144. (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
  145. /*
  146. * Default maximum segment size for TCP.
  147. * With an IP MSS of 576, this is 536,
  148. * but 512 is probably more convenient.
  149. * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
  150. */
  151. # define TCP_MSS 512
  152. # define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
  153. # define TCP_MAX_WINSHIFT 14 /* maximum window shift */
  154. # define SOL_TCP 6 /* TCP level */
  155. # define TCPI_OPT_TIMESTAMPS 1
  156. # define TCPI_OPT_SACK 2
  157. # define TCPI_OPT_WSCALE 4
  158. # define TCPI_OPT_ECN 8
  159. /* Values for tcpi_state. */
  160. enum tcp_ca_state
  161. {
  162. TCP_CA_Open = 0,
  163. TCP_CA_Disorder = 1,
  164. TCP_CA_CWR = 2,
  165. TCP_CA_Recovery = 3,
  166. TCP_CA_Loss = 4
  167. };
  168. struct tcp_info
  169. {
  170. u_int8_t tcpi_state;
  171. u_int8_t tcpi_ca_state;
  172. u_int8_t tcpi_retransmits;
  173. u_int8_t tcpi_probes;
  174. u_int8_t tcpi_backoff;
  175. u_int8_t tcpi_options;
  176. u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
  177. u_int32_t tcpi_rto;
  178. u_int32_t tcpi_ato;
  179. u_int32_t tcpi_snd_mss;
  180. u_int32_t tcpi_rcv_mss;
  181. u_int32_t tcpi_unacked;
  182. u_int32_t tcpi_sacked;
  183. u_int32_t tcpi_lost;
  184. u_int32_t tcpi_retrans;
  185. u_int32_t tcpi_fackets;
  186. /* Times. */
  187. u_int32_t tcpi_last_data_sent;
  188. u_int32_t tcpi_last_ack_sent; /* Not remembered, sorry. */
  189. u_int32_t tcpi_last_data_recv;
  190. u_int32_t tcpi_last_ack_recv;
  191. /* Metrics. */
  192. u_int32_t tcpi_pmtu;
  193. u_int32_t tcpi_rcv_ssthresh;
  194. u_int32_t tcpi_rtt;
  195. u_int32_t tcpi_rttvar;
  196. u_int32_t tcpi_snd_ssthresh;
  197. u_int32_t tcpi_snd_cwnd;
  198. u_int32_t tcpi_advmss;
  199. u_int32_t tcpi_reordering;
  200. };
  201. #endif /* Misc. */
  202. #endif /* netinet/tcp.h */