1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32#ifndef _NETINET_TCP_H
33#define _NETINET_TCP_H 1
34
35#include <features.h>
36
37
38
39
40#define TCP_NODELAY 1
41#define TCP_MAXSEG 2
42#define TCP_CORK 3
43#define TCP_KEEPIDLE 4
44#define TCP_KEEPINTVL 5
45#define TCP_KEEPCNT 6
46#define TCP_SYNCNT 7
47#define TCP_LINGER2 8
48#define TCP_DEFER_ACCEPT 9
49#define TCP_WINDOW_CLAMP 10
50#define TCP_INFO 11
51#define TCP_QUICKACK 12
52#define TCP_CONGESTION 13
53
54#ifdef __USE_MISC
55# include <sys/types.h>
56
57# ifdef __FAVOR_BSD
58typedef u_int32_t tcp_seq;
59
60
61
62
63struct tcphdr
64 {
65 u_int16_t th_sport;
66 u_int16_t th_dport;
67 tcp_seq th_seq;
68 tcp_seq th_ack;
69# if __BYTE_ORDER == __LITTLE_ENDIAN
70 u_int8_t th_x2:4;
71 u_int8_t th_off:4;
72# endif
73# if __BYTE_ORDER == __BIG_ENDIAN
74 u_int8_t th_off:4;
75 u_int8_t th_x2:4;
76# endif
77 u_int8_t th_flags;
78# define TH_FIN 0x01
79# define TH_SYN 0x02
80# define TH_RST 0x04
81# define TH_PUSH 0x08
82# define TH_ACK 0x10
83# define TH_URG 0x20
84 u_int16_t th_win;
85 u_int16_t th_sum;
86 u_int16_t th_urp;
87};
88
89# else
90struct tcphdr
91 {
92 u_int16_t source;
93 u_int16_t dest;
94 u_int32_t seq;
95 u_int32_t ack_seq;
96# if __BYTE_ORDER == __LITTLE_ENDIAN
97 u_int16_t res1:4;
98 u_int16_t doff:4;
99 u_int16_t fin:1;
100 u_int16_t syn:1;
101 u_int16_t rst:1;
102 u_int16_t psh:1;
103 u_int16_t ack:1;
104 u_int16_t urg:1;
105 u_int16_t res2:2;
106# elif __BYTE_ORDER == __BIG_ENDIAN
107 u_int16_t doff:4;
108 u_int16_t res1:4;
109 u_int16_t res2:2;
110 u_int16_t urg:1;
111 u_int16_t ack:1;
112 u_int16_t psh:1;
113 u_int16_t rst:1;
114 u_int16_t syn:1;
115 u_int16_t fin:1;
116# else
117# error "Adjust your <bits/endian.h> defines"
118# endif
119 u_int16_t window;
120 u_int16_t check;
121 u_int16_t urg_ptr;
122};
123# endif
124
125enum
126{
127 TCP_ESTABLISHED = 1,
128 TCP_SYN_SENT,
129 TCP_SYN_RECV,
130 TCP_FIN_WAIT1,
131 TCP_FIN_WAIT2,
132 TCP_TIME_WAIT,
133 TCP_CLOSE,
134 TCP_CLOSE_WAIT,
135 TCP_LAST_ACK,
136 TCP_LISTEN,
137 TCP_CLOSING
138};
139
140# define TCPOPT_EOL 0
141# define TCPOPT_NOP 1
142# define TCPOPT_MAXSEG 2
143# define TCPOLEN_MAXSEG 4
144# define TCPOPT_WINDOW 3
145# define TCPOLEN_WINDOW 3
146# define TCPOPT_SACK_PERMITTED 4
147# define TCPOLEN_SACK_PERMITTED 2
148# define TCPOPT_SACK 5
149# define TCPOPT_TIMESTAMP 8
150# define TCPOLEN_TIMESTAMP 10
151# define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2)
152
153# define TCPOPT_TSTAMP_HDR \
154 (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
155
156
157
158
159
160
161
162# define TCP_MSS 512
163
164# define TCP_MAXWIN 65535
165
166# define TCP_MAX_WINSHIFT 14
167
168# define SOL_TCP 6
169
170
171# define TCPI_OPT_TIMESTAMPS 1
172# define TCPI_OPT_SACK 2
173# define TCPI_OPT_WSCALE 4
174# define TCPI_OPT_ECN 8
175# define TCPI_OPT_ECN_SEEN 16
176
177
178enum tcp_ca_state
179{
180 TCP_CA_Open = 0,
181 TCP_CA_Disorder = 1,
182 TCP_CA_CWR = 2,
183 TCP_CA_Recovery = 3,
184 TCP_CA_Loss = 4
185};
186
187struct tcp_info
188{
189 u_int8_t tcpi_state;
190 u_int8_t tcpi_ca_state;
191 u_int8_t tcpi_retransmits;
192 u_int8_t tcpi_probes;
193 u_int8_t tcpi_backoff;
194 u_int8_t tcpi_options;
195 u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
196
197 u_int32_t tcpi_rto;
198 u_int32_t tcpi_ato;
199 u_int32_t tcpi_snd_mss;
200 u_int32_t tcpi_rcv_mss;
201
202 u_int32_t tcpi_unacked;
203 u_int32_t tcpi_sacked;
204 u_int32_t tcpi_lost;
205 u_int32_t tcpi_retrans;
206 u_int32_t tcpi_fackets;
207
208
209 u_int32_t tcpi_last_data_sent;
210 u_int32_t tcpi_last_ack_sent;
211 u_int32_t tcpi_last_data_recv;
212 u_int32_t tcpi_last_ack_recv;
213
214
215 u_int32_t tcpi_pmtu;
216 u_int32_t tcpi_rcv_ssthresh;
217 u_int32_t tcpi_rtt;
218 u_int32_t tcpi_rttvar;
219 u_int32_t tcpi_snd_ssthresh;
220 u_int32_t tcpi_snd_cwnd;
221 u_int32_t tcpi_advmss;
222 u_int32_t tcpi_reordering;
223 u_int32_t tcpi_rcv_rtt;
224 u_int32_t tcpi_rcv_space;
225 u_int32_t tcpi_total_retrans;
226
227};
228
229#endif
230
231#endif
232