tcp.h 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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. * 3. All advertising materials mentioning features or use of this software
  14. * must display the following acknowledgement:
  15. * This product includes software developed by the University of
  16. * California, Berkeley and its contributors.
  17. * 4. Neither the name of the University nor the names of its contributors
  18. * may be used to endorse or promote products derived from this software
  19. * without specific prior written permission.
  20. *
  21. * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
  22. * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
  23. * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
  24. * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
  25. * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
  26. * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
  27. * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
  28. * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
  29. * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
  30. * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
  31. * SUCH DAMAGE.
  32. *
  33. * @(#)tcp.h 8.1 (Berkeley) 6/10/93
  34. */
  35. typedef uint32_t tcp_seq;
  36. /*
  37. * TCP header.
  38. * Per RFC 793, September, 1981.
  39. */
  40. struct tcphdr {
  41. uint16_t th_sport; /* source port */
  42. uint16_t th_dport; /* destination port */
  43. tcp_seq th_seq; /* sequence number */
  44. tcp_seq th_ack; /* acknowledgement number */
  45. uint8_t th_offx2; /* data offset, rsvd */
  46. uint8_t th_flags;
  47. uint16_t th_win; /* window */
  48. uint16_t th_sum; /* checksum */
  49. uint16_t th_urp; /* urgent pointer */
  50. } UNALIGNED;
  51. #define TH_OFF(th) (((th)->th_offx2 & 0xf0) >> 4)
  52. /* TCP flags */
  53. #define TH_FIN 0x01
  54. #define TH_SYN 0x02
  55. #define TH_RST 0x04
  56. #define TH_PUSH 0x08
  57. #define TH_ACK 0x10
  58. #define TH_URG 0x20
  59. #define TH_ECNECHO 0x40 /* ECN Echo */
  60. #define TH_CWR 0x80 /* ECN Cwnd Reduced */
  61. #define TCPOPT_EOL 0
  62. #define TCPOPT_NOP 1
  63. #define TCPOPT_MAXSEG 2
  64. #define TCPOLEN_MAXSEG 4
  65. #define TCPOPT_WSCALE 3 /* window scale factor (rfc1323) */
  66. #define TCPOPT_SACKOK 4 /* selective ack ok (rfc2018) */
  67. #define TCPOPT_SACK 5 /* selective ack (rfc2018) */
  68. #define TCPOPT_ECHO 6 /* echo (rfc1072) */
  69. #define TCPOPT_ECHOREPLY 7 /* echo (rfc1072) */
  70. #define TCPOPT_TIMESTAMP 8 /* timestamp (rfc1323) */
  71. #define TCPOLEN_TIMESTAMP 10
  72. #define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
  73. #define TCPOPT_CC 11 /* T/TCP CC options (rfc1644) */
  74. #define TCPOPT_CCNEW 12 /* T/TCP CC options (rfc1644) */
  75. #define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */
  76. #define TCPOPT_SIGNATURE 19 /* Keyed MD5 (rfc2385) */
  77. #define TCPOLEN_SIGNATURE 18
  78. #define TCP_SIGLEN 16 /* length of an option 19 digest */
  79. #define TCPOPT_SCPS 20 /* SCPS-TP (CCSDS 714.0-B-2) */
  80. #define TCPOPT_UTO 28 /* tcp user timeout (rfc5482) */
  81. #define TCPOLEN_UTO 4
  82. #define TCPOPT_TCPAO 29 /* TCP authentication option (rfc5925) */
  83. #define TCPOPT_MPTCP 30 /* MPTCP options */
  84. #define TCPOPT_FASTOPEN 34 /* TCP Fast Open (rfc7413) */
  85. #define TCPOPT_EXPERIMENT2 254 /* experimental headers (rfc4727) */
  86. #define TCPOPT_TSTAMP_HDR \
  87. (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
  88. #ifndef FTP_PORT
  89. #define FTP_PORT 21
  90. #endif
  91. #ifndef SSH_PORT
  92. #define SSH_PORT 22
  93. #endif
  94. #ifndef TELNET_PORT
  95. #define TELNET_PORT 23
  96. #endif
  97. #ifndef SMTP_PORT
  98. #define SMTP_PORT 25
  99. #endif
  100. #ifndef NAMESERVER_PORT
  101. #define NAMESERVER_PORT 53
  102. #endif
  103. #ifndef HTTP_PORT
  104. #define HTTP_PORT 80
  105. #endif
  106. #ifndef NETBIOS_NS_PORT
  107. #define NETBIOS_NS_PORT 137 /* RFC 1001, RFC 1002 */
  108. #endif
  109. #ifndef NETBIOS_SSN_PORT
  110. #define NETBIOS_SSN_PORT 139 /* RFC 1001, RFC 1002 */
  111. #endif
  112. #ifndef BGP_PORT
  113. #define BGP_PORT 179
  114. #endif
  115. #ifndef RPKI_RTR_PORT
  116. #define RPKI_RTR_PORT 323
  117. #endif
  118. #ifndef SMB_PORT
  119. #define SMB_PORT 445
  120. #endif
  121. #ifndef RTSP_PORT
  122. #define RTSP_PORT 554
  123. #endif
  124. #ifndef MSDP_PORT
  125. #define MSDP_PORT 639
  126. #endif
  127. #ifndef LDP_PORT
  128. #define LDP_PORT 646
  129. #endif
  130. #ifndef PPTP_PORT
  131. #define PPTP_PORT 1723
  132. #endif
  133. #ifndef NFS_PORT
  134. #define NFS_PORT 2049
  135. #endif
  136. #ifndef OPENFLOW_PORT_OLD
  137. #define OPENFLOW_PORT_OLD 6633
  138. #endif
  139. #ifndef OPENFLOW_PORT_IANA
  140. #define OPENFLOW_PORT_IANA 6653
  141. #endif
  142. #ifndef HTTP_PORT_ALT
  143. #define HTTP_PORT_ALT 8080
  144. #endif
  145. #ifndef RTSP_PORT_ALT
  146. #define RTSP_PORT_ALT 8554
  147. #endif
  148. #ifndef BEEP_PORT
  149. #define BEEP_PORT 10288
  150. #endif
  151. #ifndef REDIS_PORT
  152. #define REDIS_PORT 6379
  153. #endif