35 |
/* |
/* |
36 |
* User-settable options (used with setsockopt). |
* User-settable options (used with setsockopt). |
37 |
*/ |
*/ |
38 |
#define TCP_NODELAY 1 /* Don't delay send to coalesce packets */ |
#define TCP_NODELAY 1 /* Don't delay send to coalesce packets */ |
39 |
#define TCP_MAXSEG 2 /* Set maximum segment size */ |
#define TCP_MAXSEG 2 /* Set maximum segment size */ |
40 |
#define TCP_CORK 3 /* Control sending of partial frames */ |
#define TCP_CORK 3 /* Control sending of partial frames */ |
41 |
#define TCP_KEEPIDLE 4 /* Start keeplives after this period */ |
#define TCP_KEEPIDLE 4 /* Start keeplives after this period */ |
42 |
#define TCP_KEEPINTVL 5 /* Interval between keepalives */ |
#define TCP_KEEPINTVL 5 /* Interval between keepalives */ |
43 |
#define TCP_KEEPCNT 6 /* Number of keepalives before death */ |
#define TCP_KEEPCNT 6 /* Number of keepalives before death */ |
44 |
#define TCP_SYNCNT 7 /* Number of SYN retransmits */ |
#define TCP_SYNCNT 7 /* Number of SYN retransmits */ |
45 |
#define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */ |
#define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */ |
46 |
#define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */ |
#define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */ |
47 |
#define TCP_WINDOW_CLAMP 10 /* Bound advertised window */ |
#define TCP_WINDOW_CLAMP 10 /* Bound advertised window */ |
48 |
#define TCP_INFO 11 /* Information about this connection. */ |
#define TCP_INFO 11 /* Information about this connection. */ |
49 |
#define TCP_QUICKACK 12 /* Bock/reenable quick ACKs. */ |
#define TCP_QUICKACK 12 /* Bock/reenable quick ACKs. */ |
50 |
|
|
51 |
# include <sys/types.h> |
# include <sys/types.h> |
52 |
|
|
53 |
typedef u_int32_t tcp_seq; |
typedef u_int32_t tcp_seq; |
54 |
/* |
/* |
55 |
* TCP header. |
* TCP header. |
56 |
* Per RFC 793, September, 1981. |
* Per RFC 793, September, 1981. |
57 |
*/ |
*/ |
58 |
struct tcphdr |
struct tcphdr |
59 |
{ |
{ |
60 |
u_int16_t th_sport; /* source port */ |
u_int16_t th_sport; /* source port */ |
61 |
u_int16_t th_dport; /* destination port */ |
u_int16_t th_dport; /* destination port */ |
62 |
tcp_seq th_seq; /* sequence number */ |
tcp_seq th_seq; /* sequence number */ |
63 |
tcp_seq th_ack; /* acknowledgement number */ |
tcp_seq th_ack; /* acknowledgement number */ |
64 |
# if __BYTE_ORDER == __LITTLE_ENDIAN |
# if __BYTE_ORDER == __LITTLE_ENDIAN |
65 |
u_int8_t th_x2:4; /* (unused) */ |
u_int8_t th_x2:4; /* (unused) */ |
66 |
u_int8_t th_off:4; /* data offset */ |
u_int8_t th_off:4; /* data offset */ |
67 |
# endif |
# endif |
68 |
# if __BYTE_ORDER == __BIG_ENDIAN |
# if __BYTE_ORDER == __BIG_ENDIAN |
69 |
u_int8_t th_off:4; /* data offset */ |
u_int8_t th_off:4; /* data offset */ |
70 |
u_int8_t th_x2:4; /* (unused) */ |
u_int8_t th_x2:4; /* (unused) */ |
71 |
# endif |
# endif |
72 |
u_int8_t th_flags; |
u_int8_t th_flags; |
73 |
# define TH_FIN 0x01 |
# define TH_FIN 0x01 |
74 |
# define TH_SYN 0x02 |
# define TH_SYN 0x02 |
75 |
# define TH_RST 0x04 |
# define TH_RST 0x04 |
76 |
# define TH_PUSH 0x08 |
# define TH_PUSH 0x08 |
77 |
# define TH_ACK 0x10 |
# define TH_ACK 0x10 |
78 |
# define TH_URG 0x20 |
# define TH_URG 0x20 |
79 |
u_int16_t th_win; /* window */ |
u_int16_t th_win; /* window */ |
80 |
u_int16_t th_sum; /* checksum */ |
u_int16_t th_sum; /* checksum */ |
81 |
u_int16_t th_urp; /* urgent pointer */ |
u_int16_t th_urp; /* urgent pointer */ |
82 |
}; |
}; |
83 |
|
|
84 |
enum |
enum |
93 |
TCP_CLOSE_WAIT, |
TCP_CLOSE_WAIT, |
94 |
TCP_LAST_ACK, |
TCP_LAST_ACK, |
95 |
TCP_LISTEN, |
TCP_LISTEN, |
96 |
TCP_CLOSING /* now a valid state */ |
TCP_CLOSING /* now a valid state */ |
97 |
}; |
}; |
98 |
|
|
99 |
# define TCPOPT_EOL 0 |
# define TCPOPT_EOL 0 |
102 |
# define TCPOLEN_MAXSEG 4 |
# define TCPOLEN_MAXSEG 4 |
103 |
# define TCPOPT_WINDOW 3 |
# define TCPOPT_WINDOW 3 |
104 |
# define TCPOLEN_WINDOW 3 |
# define TCPOLEN_WINDOW 3 |
105 |
# define TCPOPT_SACK_PERMITTED 4 /* Experimental */ |
# define TCPOPT_SACK_PERMITTED 4 /* Experimental */ |
106 |
# define TCPOLEN_SACK_PERMITTED 2 |
# define TCPOLEN_SACK_PERMITTED 2 |
107 |
# define TCPOPT_SACK 5 /* Experimental */ |
# define TCPOPT_SACK 5 /* Experimental */ |
108 |
# define TCPOPT_TIMESTAMP 8 |
# define TCPOPT_TIMESTAMP 8 |
109 |
# define TCPOLEN_TIMESTAMP 10 |
# define TCPOLEN_TIMESTAMP 10 |
110 |
# define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ |
# define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */ |
111 |
|
|
112 |
# define TCPOPT_TSTAMP_HDR \ |
# define TCPOPT_TSTAMP_HDR \ |
113 |
(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) |
(TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP) |
120 |
*/ |
*/ |
121 |
# define TCP_MSS 512 |
# define TCP_MSS 512 |
122 |
|
|
123 |
# define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ |
# define TCP_MAXWIN 65535 /* largest value for (unscaled) window */ |
124 |
|
|
125 |
# define TCP_MAX_WINSHIFT 14 /* maximum window shift */ |
# define TCP_MAX_WINSHIFT 14 /* maximum window shift */ |
126 |
|
|
127 |
# define SOL_TCP 6 /* TCP level */ |
# define SOL_TCP 6 /* TCP level */ |
128 |
|
|
129 |
|
|
130 |
# define TCPI_OPT_TIMESTAMPS 1 |
# define TCPI_OPT_TIMESTAMPS 1 |
144 |
|
|
145 |
struct tcp_info |
struct tcp_info |
146 |
{ |
{ |
147 |
u_int8_t tcpi_state; |
u_int8_t tcpi_state; |
148 |
u_int8_t tcpi_ca_state; |
u_int8_t tcpi_ca_state; |
149 |
u_int8_t tcpi_retransmits; |
u_int8_t tcpi_retransmits; |
150 |
u_int8_t tcpi_probes; |
u_int8_t tcpi_probes; |
151 |
u_int8_t tcpi_backoff; |
u_int8_t tcpi_backoff; |
152 |
u_int8_t tcpi_options; |
u_int8_t tcpi_options; |
153 |
u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4; |
u_int8_t tcpi_snd_wscale:4, tcpi_rcv_wscale:4; |
154 |
|
|
155 |
u_int32_t tcpi_rto; |
u_int32_t tcpi_rto; |
156 |
u_int32_t tcpi_ato; |
u_int32_t tcpi_ato; |
157 |
u_int32_t tcpi_snd_mss; |
u_int32_t tcpi_snd_mss; |
158 |
u_int32_t tcpi_rcv_mss; |
u_int32_t tcpi_rcv_mss; |
159 |
|
|
160 |
u_int32_t tcpi_unacked; |
u_int32_t tcpi_unacked; |
161 |
u_int32_t tcpi_sacked; |
u_int32_t tcpi_sacked; |
162 |
u_int32_t tcpi_lost; |
u_int32_t tcpi_lost; |
163 |
u_int32_t tcpi_retrans; |
u_int32_t tcpi_retrans; |
164 |
u_int32_t tcpi_fackets; |
u_int32_t tcpi_fackets; |
165 |
|
|
166 |
/* Times. */ |
/* Times. */ |
167 |
u_int32_t tcpi_last_data_sent; |
u_int32_t tcpi_last_data_sent; |
168 |
u_int32_t tcpi_last_ack_sent; /* Not remembered, sorry. */ |
u_int32_t tcpi_last_ack_sent; /* Not remembered, sorry. */ |
169 |
u_int32_t tcpi_last_data_recv; |
u_int32_t tcpi_last_data_recv; |
170 |
u_int32_t tcpi_last_ack_recv; |
u_int32_t tcpi_last_ack_recv; |
171 |
|
|
172 |
/* Metrics. */ |
/* Metrics. */ |
173 |
u_int32_t tcpi_pmtu; |
u_int32_t tcpi_pmtu; |
174 |
u_int32_t tcpi_rcv_ssthresh; |
u_int32_t tcpi_rcv_ssthresh; |
175 |
u_int32_t tcpi_rtt; |
u_int32_t tcpi_rtt; |
176 |
u_int32_t tcpi_rttvar; |
u_int32_t tcpi_rttvar; |
177 |
u_int32_t tcpi_snd_ssthresh; |
u_int32_t tcpi_snd_ssthresh; |
178 |
u_int32_t tcpi_snd_cwnd; |
u_int32_t tcpi_snd_cwnd; |
179 |
u_int32_t tcpi_advmss; |
u_int32_t tcpi_advmss; |
180 |
u_int32_t tcpi_reordering; |
u_int32_t tcpi_reordering; |
181 |
}; |
}; |
182 |
|
|
183 |
#endif /* __BSDTCP_H__ */ |
#endif /* __BSDTCP_H__ */ |