#include <netinet/tcp.h>
netinet/tcp.h
typedeftcp_seq
typedef __uint32_t tcp_seq
structtcphdr
TCP header.
Per RFC 793, September, 1981.
| unsigned short | th_sport | source port |
| unsigned short | th_dport | destination port |
| tcp_seq | th_seq | sequence number |
| tcp_seq | th_ack | acknowledgement number |
| unsigned int:4 | th_x2 | (unused) |
| unsigned int:4 | th_off | data offset |
| unsigned char | th_flags | |
| unsigned short | th_win | window |
| unsigned short | th_sum | checksum |
| unsigned short | th_urp | urgent pointer |
macroTH_FIN
#define TH_FIN 0x01
macroTH_SYN
#define TH_SYN 0x02
macroTH_RST
#define TH_RST 0x04
macroTH_PUSH
#define TH_PUSH 0x08
macroTH_ACK
#define TH_ACK 0x10
macroTH_URG
#define TH_URG 0x20
macroTH_ECE
#define TH_ECE 0x40
macroTH_CWR
#define TH_CWR 0x80
macroTH_FLAGS_ALL
#define TH_FLAGS_ALL (TH_FLAGS|TH_PUSH)
macroTCPOPT_EOL
#define TCPOPT_EOL 0
macroTCPOLEN_EOL
#define TCPOLEN_EOL 1
macroTCPOPT_NOP
#define TCPOPT_NOP 1
macroTCPOLEN_NOP
#define TCPOLEN_NOP 1
macroTCPOPT_MAXSEG
#define TCPOPT_MAXSEG 2
macroTCPOLEN_MAXSEG
#define TCPOLEN_MAXSEG 4
macroTCPOPT_WINDOW
#define TCPOPT_WINDOW 3
macroTCPOLEN_WINDOW
#define TCPOLEN_WINDOW 3
macroTCPOLEN_SACK_PERMITTED
#define TCPOLEN_SACK_PERMITTED 2
macroTCPOPT_SACK
#define TCPOPT_SACK 5
macroTCPOLEN_SACKHDR
#define TCPOLEN_SACKHDR 2
macroTCPOPT_TIMESTAMP
#define TCPOPT_TIMESTAMP 8
macroTCPOLEN_TIMESTAMP
#define TCPOLEN_TIMESTAMP 10
macroTCPOPT_TSTAMP_HDR
#define TCPOPT_TSTAMP_HDR (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
macroTCPOPT_CCNEW
#define TCPOPT_CCNEW 12
macroTCPOPT_CCECHO
#define TCPOPT_CCECHO 13
macroTCPOLEN_CC
#define TCPOLEN_CC 6
macroTCPOLEN_CC_APPA
#define TCPOLEN_CC_APPA (TCPOLEN_CC+2)
macroTCPOPT_CC_HDR
#define TCPOPT_CC_HDR(ccopt) (TCPOPT_NOP<<24|TCPOPT_NOP<<16|(ccopt)<<8|TCPOLEN_CC)
macroTCPOLEN_SIGNATURE
#define TCPOLEN_SIGNATURE 18
macroTCPOPT_FASTOPEN
#define TCPOPT_FASTOPEN 34
macroTCPOLEN_FASTOPEN_REQ
#define TCPOLEN_FASTOPEN_REQ 2
macroTCPOPT_SACK_PERMIT_HDR
Option definitions
#define TCPOPT_SACK_PERMIT_HDR (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK_PERMITTED<<8|TCPOLEN_SACK_PERMITTED)
macroTCPOPT_SACK_HDR
#define TCPOPT_SACK_HDR (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_SACK<<8)
macroMAX_SACK_BLKS
Miscellaneous constants
#define MAX_SACK_BLKS 6
Max # SACK blocks stored at sender side
macroTCP_MSS
Default maximum segment size for TCP.
With an IP MTU of 576, this is 536,
but 512 is probably more convenient.
This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
#define TCP_MSS 512
macroTCP_MINMSS
TCP_MINMSS is defined to be 216 which is fine for the smallest
link MTU (256 bytes, SLIP interface) in the Internet.
However it is very unlikely to come across such low MTU interfaces
these days (anno dato 2004).
Probably it can be set to 512 without ill effects. But we play safe.
See tcp_subr.c tcp_minmss SYSCTL declaration for more comments.
Setting this to "0" disables the minmss check.
#define TCP_MINMSS 216
macroTCP6_MSS
Default maximum segment size for TCP6.
With an IP6 MSS of 1280, this is 1220,
but 1024 is probably more convenient. (xxx kazu in doubt)
This should be defined as MIN(1024, IP6_MSS - sizeof (struct tcpip6hdr))
#define TCP6_MSS 1024
macroTCP_MAXOLEN
#define TCP_MAXOLEN (TCP_MAXHLEN - sizeof(struct tcphdr))
macroTCP_NODELAY
User-settable options (used with setsockopt).
#define TCP_NODELAY 0x01
don't delay send to coalesce packets
macroPERSIST_TIMEOUT
#define PERSIST_TIMEOUT 0x40
time after which a connection in
persist timeout will terminate.
see draft-ananth-tcpm-persist-02.txt
macroTCP_RXT_CONNDROPTIME
#define TCP_RXT_CONNDROPTIME 0x80
time after which tcp retransmissions will be
stopped and the connection will be dropped
macroTCP_RXT_FINDROP
#define TCP_RXT_FINDROP 0x100
when this option is set, drop a connection
after retransmitting the FIN 3 times. It will
prevent holding too many mbufs in socket
buffer queues.
structtcp_connection_info
| u_int8_t | tcpi_state | connection state |
| u_int8_t | tcpi_snd_wscale | Window scale for send window |
| u_int8_t | tcpi_rcv_wscale | Window scale for receive window |
| u_int8_t | __pad1 | |
| u_int32_t | tcpi_options | TCP options supported |
| u_int32_t | tcpi_flags | flags |
| u_int32_t | tcpi_rto | retransmit timeout in ms |
| u_int32_t | tcpi_maxseg | maximum segment size supported |
| u_int32_t | tcpi_snd_ssthresh | slow start threshold in bytes |
| u_int32_t | tcpi_snd_cwnd | send congestion window in bytes |
| u_int32_t | tcpi_snd_wnd | send widnow in bytes |
| u_int32_t | tcpi_snd_sbbytes | bytes in send socket buffer, including in-flight data |
| u_int32_t | tcpi_rcv_wnd | receive window in bytes |
| u_int32_t | tcpi_rttcur | most recent RTT in ms |
| u_int32_t | tcpi_srtt | average RTT in ms |
| u_int32_t | tcpi_rttvar | RTT variance |
| u_int32_t:1 | tcpi_tfo_cookie_req | Cookie requested? |
| u_int32_t:1 | tcpi_tfo_cookie_rcv | Cookie received? |
| u_int32_t:1 | tcpi_tfo_syn_loss | Fallback to reg. TCP after SYN-loss |
| u_int32_t:1 | tcpi_tfo_syn_data_sent | SYN+data has been sent out |
| u_int32_t:1 | tcpi_tfo_syn_data_acked | SYN+data has been fully acknowledged |
| u_int32_t:1 | tcpi_tfo_syn_data_rcv | Server received SYN+data with a valid cookie |
| u_int32_t:1 | tcpi_tfo_cookie_req_rcv | Server received cookie-request |
| u_int32_t:1 | tcpi_tfo_cookie_sent | Server announced cookie |
| u_int32_t:1 | tcpi_tfo_cookie_invalid | Server received an invalid cookie |
| u_int32_t:1 | tcpi_tfo_cookie_wrong | Our sent cookie was wrong |
| u_int32_t:1 | tcpi_tfo_no_cookie_rcv | We did not receive a cookie upon our request |
| u_int32_t:1 | tcpi_tfo_heuristics_disable | TFO-heuristics disabled it |
| u_int32_t:1 | tcpi_tfo_send_blackhole | A sending-blackhole got detected |
| u_int32_t:1 | tcpi_tfo_recv_blackhole | A receiver-blackhole got detected |
| u_int32_t:1 | tcpi_tfo_onebyte_proxy | A proxy acknowledges all but one byte of the SYN |
| u_int32_t:17 | __pad2 | |
| u_int64_t | tcpi_txpackets | |
| u_int64_t | tcpi_txbytes | |
| u_int64_t | tcpi_txretransmitbytes | |
| u_int64_t | tcpi_rxpackets | |
| u_int64_t | tcpi_rxbytes | |
| u_int64_t | tcpi_rxoutoforderbytes | |
| u_int64_t | tcpi_txretransmitpackets |
macroTCPCI_FLAG_LOSSRECOVERY
#define TCPCI_FLAG_LOSSRECOVERY 0x00000001
macroTCPCI_FLAG_REORDERING_DETECTED
#define TCPCI_FLAG_REORDERING_DETECTED 0x00000002