1685295f4SBill Fenner /* 2685295f4SBill Fenner * Copyright (c) 1982, 1986, 1993 3685295f4SBill Fenner * The Regents of the University of California. All rights reserved. 4685295f4SBill Fenner * 5685295f4SBill Fenner * Redistribution and use in source and binary forms, with or without 6685295f4SBill Fenner * modification, are permitted provided that the following conditions 7685295f4SBill Fenner * are met: 8685295f4SBill Fenner * 1. Redistributions of source code must retain the above copyright 9685295f4SBill Fenner * notice, this list of conditions and the following disclaimer. 10685295f4SBill Fenner * 2. Redistributions in binary form must reproduce the above copyright 11685295f4SBill Fenner * notice, this list of conditions and the following disclaimer in the 12685295f4SBill Fenner * documentation and/or other materials provided with the distribution. 13685295f4SBill Fenner * 3. All advertising materials mentioning features or use of this software 14685295f4SBill Fenner * must display the following acknowledgement: 15685295f4SBill Fenner * This product includes software developed by the University of 16685295f4SBill Fenner * California, Berkeley and its contributors. 17685295f4SBill Fenner * 4. Neither the name of the University nor the names of its contributors 18685295f4SBill Fenner * may be used to endorse or promote products derived from this software 19685295f4SBill Fenner * without specific prior written permission. 20685295f4SBill Fenner * 21685295f4SBill Fenner * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22685295f4SBill Fenner * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23685295f4SBill Fenner * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24685295f4SBill Fenner * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25685295f4SBill Fenner * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26685295f4SBill Fenner * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27685295f4SBill Fenner * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28685295f4SBill Fenner * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29685295f4SBill Fenner * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30685295f4SBill Fenner * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31685295f4SBill Fenner * SUCH DAMAGE. 32685295f4SBill Fenner * 33685295f4SBill Fenner * @(#)tcp.h 8.1 (Berkeley) 6/10/93 34685295f4SBill Fenner */ 35685295f4SBill Fenner 36685295f4SBill Fenner /* 37685295f4SBill Fenner * TCP header. 38685295f4SBill Fenner * Per RFC 793, September, 1981. 39685295f4SBill Fenner */ 40685295f4SBill Fenner struct tcphdr { 41ee67461eSJoseph Mingrone nd_uint16_t th_sport; /* source port */ 42ee67461eSJoseph Mingrone nd_uint16_t th_dport; /* destination port */ 43ee67461eSJoseph Mingrone nd_uint32_t th_seq; /* sequence number */ 44ee67461eSJoseph Mingrone nd_uint32_t th_ack; /* acknowledgement number */ 45ee67461eSJoseph Mingrone nd_uint8_t th_offx2; /* data offset, rsvd */ 46ee67461eSJoseph Mingrone nd_uint8_t th_flags; 47ee67461eSJoseph Mingrone nd_uint16_t th_win; /* window */ 48ee67461eSJoseph Mingrone nd_uint16_t th_sum; /* checksum */ 49ee67461eSJoseph Mingrone nd_uint16_t th_urp; /* urgent pointer */ 50ee67461eSJoseph Mingrone }; 51a5779b6eSRui Paulo 52ee67461eSJoseph Mingrone #define TH_OFF(th) ((GET_U_1((th)->th_offx2) & 0xf0) >> 4) 53a5779b6eSRui Paulo 54a5779b6eSRui Paulo /* TCP flags */ 55685295f4SBill Fenner #define TH_FIN 0x01 56685295f4SBill Fenner #define TH_SYN 0x02 57685295f4SBill Fenner #define TH_RST 0x04 58685295f4SBill Fenner #define TH_PUSH 0x08 59685295f4SBill Fenner #define TH_ACK 0x10 60685295f4SBill Fenner #define TH_URG 0x20 61a90e161bSBill Fenner #define TH_ECNECHO 0x40 /* ECN Echo */ 62a90e161bSBill Fenner #define TH_CWR 0x80 /* ECN Cwnd Reduced */ 63a5779b6eSRui Paulo 64685295f4SBill Fenner 65685295f4SBill Fenner #define TCPOPT_EOL 0 66685295f4SBill Fenner #define TCPOPT_NOP 1 67685295f4SBill Fenner #define TCPOPT_MAXSEG 2 68685295f4SBill Fenner #define TCPOLEN_MAXSEG 4 69a90e161bSBill Fenner #define TCPOPT_WSCALE 3 /* window scale factor (rfc1323) */ 70a90e161bSBill Fenner #define TCPOPT_SACKOK 4 /* selective ack ok (rfc2018) */ 71a90e161bSBill Fenner #define TCPOPT_SACK 5 /* selective ack (rfc2018) */ 72a90e161bSBill Fenner #define TCPOPT_ECHO 6 /* echo (rfc1072) */ 73a90e161bSBill Fenner #define TCPOPT_ECHOREPLY 7 /* echo (rfc1072) */ 74a90e161bSBill Fenner #define TCPOPT_TIMESTAMP 8 /* timestamp (rfc1323) */ 75685295f4SBill Fenner #define TCPOLEN_TIMESTAMP 10 76685295f4SBill Fenner #define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ 77a90e161bSBill Fenner #define TCPOPT_CC 11 /* T/TCP CC options (rfc1644) */ 78a90e161bSBill Fenner #define TCPOPT_CCNEW 12 /* T/TCP CC options (rfc1644) */ 79a90e161bSBill Fenner #define TCPOPT_CCECHO 13 /* T/TCP CC options (rfc1644) */ 801de50e9fSSam Leffler #define TCPOPT_SIGNATURE 19 /* Keyed MD5 (rfc2385) */ 811de50e9fSSam Leffler #define TCPOLEN_SIGNATURE 18 821de50e9fSSam Leffler #define TCP_SIGLEN 16 /* length of an option 19 digest */ 833340d773SGleb Smirnoff #define TCPOPT_SCPS 20 /* SCPS-TP (CCSDS 714.0-B-2) */ 84ce3ed1caSRui Paulo #define TCPOPT_UTO 28 /* tcp user timeout (rfc5482) */ 85ce3ed1caSRui Paulo #define TCPOLEN_UTO 4 863340d773SGleb Smirnoff #define TCPOPT_TCPAO 29 /* TCP authentication option (rfc5925) */ 873c602fabSXin LI #define TCPOPT_MPTCP 30 /* MPTCP options */ 883340d773SGleb Smirnoff #define TCPOPT_FASTOPEN 34 /* TCP Fast Open (rfc7413) */ 893c602fabSXin LI #define TCPOPT_EXPERIMENT2 254 /* experimental headers (rfc4727) */ 9027df3f5dSRui Paulo 91685295f4SBill Fenner #define TCPOPT_TSTAMP_HDR \ 92685295f4SBill Fenner (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) 93a5779b6eSRui Paulo 943340d773SGleb Smirnoff #ifndef FTP_PORT 953340d773SGleb Smirnoff #define FTP_PORT 21 963340d773SGleb Smirnoff #endif 973340d773SGleb Smirnoff #ifndef SSH_PORT 983340d773SGleb Smirnoff #define SSH_PORT 22 993340d773SGleb Smirnoff #endif 100a5779b6eSRui Paulo #ifndef TELNET_PORT 101a5779b6eSRui Paulo #define TELNET_PORT 23 102a5779b6eSRui Paulo #endif 1038bdc5a62SPatrick Kelsey #ifndef SMTP_PORT 1048bdc5a62SPatrick Kelsey #define SMTP_PORT 25 1058bdc5a62SPatrick Kelsey #endif 106ee67461eSJoseph Mingrone #ifndef WHOIS_PORT 107ee67461eSJoseph Mingrone #define WHOIS_PORT 43 108ee67461eSJoseph Mingrone #endif 1093340d773SGleb Smirnoff #ifndef NAMESERVER_PORT 1103340d773SGleb Smirnoff #define NAMESERVER_PORT 53 1113340d773SGleb Smirnoff #endif 1123340d773SGleb Smirnoff #ifndef HTTP_PORT 1133340d773SGleb Smirnoff #define HTTP_PORT 80 1143340d773SGleb Smirnoff #endif 1153340d773SGleb Smirnoff #ifndef NETBIOS_SSN_PORT 1163340d773SGleb Smirnoff #define NETBIOS_SSN_PORT 139 /* RFC 1001, RFC 1002 */ 1173340d773SGleb Smirnoff #endif 118a5779b6eSRui Paulo #ifndef BGP_PORT 119a5779b6eSRui Paulo #define BGP_PORT 179 120a5779b6eSRui Paulo #endif 1213340d773SGleb Smirnoff #ifndef RPKI_RTR_PORT 1223340d773SGleb Smirnoff #define RPKI_RTR_PORT 323 1233340d773SGleb Smirnoff #endif 1243340d773SGleb Smirnoff #ifndef SMB_PORT 1253340d773SGleb Smirnoff #define SMB_PORT 445 1263340d773SGleb Smirnoff #endif 1273340d773SGleb Smirnoff #ifndef RTSP_PORT 1283340d773SGleb Smirnoff #define RTSP_PORT 554 1293340d773SGleb Smirnoff #endif 1303340d773SGleb Smirnoff #ifndef MSDP_PORT 1313340d773SGleb Smirnoff #define MSDP_PORT 639 1323340d773SGleb Smirnoff #endif 1333340d773SGleb Smirnoff #ifndef LDP_PORT 1343340d773SGleb Smirnoff #define LDP_PORT 646 1353340d773SGleb Smirnoff #endif 1363340d773SGleb Smirnoff #ifndef PPTP_PORT 1373340d773SGleb Smirnoff #define PPTP_PORT 1723 1383340d773SGleb Smirnoff #endif 1393340d773SGleb Smirnoff #ifndef NFS_PORT 1403340d773SGleb Smirnoff #define NFS_PORT 2049 1413340d773SGleb Smirnoff #endif 142*0a7e5f1fSJoseph Mingrone #ifndef REDIS_PORT 143*0a7e5f1fSJoseph Mingrone #define REDIS_PORT 6379 144*0a7e5f1fSJoseph Mingrone #endif 1453c602fabSXin LI #ifndef OPENFLOW_PORT_OLD 1463c602fabSXin LI #define OPENFLOW_PORT_OLD 6633 1473c602fabSXin LI #endif 1483c602fabSXin LI #ifndef OPENFLOW_PORT_IANA 1493c602fabSXin LI #define OPENFLOW_PORT_IANA 6653 1503c602fabSXin LI #endif 1518bdc5a62SPatrick Kelsey #ifndef HTTP_PORT_ALT 1528bdc5a62SPatrick Kelsey #define HTTP_PORT_ALT 8080 1538bdc5a62SPatrick Kelsey #endif 1548bdc5a62SPatrick Kelsey #ifndef RTSP_PORT_ALT 1558bdc5a62SPatrick Kelsey #define RTSP_PORT_ALT 8554 1568bdc5a62SPatrick Kelsey #endif 1573340d773SGleb Smirnoff #ifndef BEEP_PORT 1583340d773SGleb Smirnoff #define BEEP_PORT 10288 1593340d773SGleb Smirnoff #endif 160