add support for BSD struct tcphdr in netinet/tcp.h
[musl] / include / netinet / tcp.h
1 #ifndef _NETINET_TCP_H
2 #define _NETINET_TCP_H
3
4 #include <features.h>
5
6 #define TCP_NODELAY 1
7 #define TCP_MAXSEG       2
8 #define TCP_CORK         3
9 #define TCP_KEEPIDLE     4
10 #define TCP_KEEPINTVL    5
11 #define TCP_KEEPCNT      6
12 #define TCP_SYNCNT       7
13 #define TCP_LINGER2      8
14 #define TCP_DEFER_ACCEPT 9
15 #define TCP_WINDOW_CLAMP 10
16 #define TCP_INFO         11
17 #define TCP_QUICKACK     12
18 #define TCP_CONGESTION   13
19 #define TCP_MD5SIG       14
20 #define TCP_THIN_LINEAR_TIMEOUTS 16
21 #define TCP_THIN_DUPACK  17
22 #define TCP_USER_TIMEOUT 18
23 #define TCP_REPAIR       19
24 #define TCP_REPAIR_QUEUE 20
25 #define TCP_QUEUE_SEQ    21
26 #define TCP_REPAIR_OPTIONS 22
27 #define TCP_FASTOPEN     23
28 #define TCP_TIMESTAMP    24
29 #define TCP_NOTSENT_LOWAT 25
30
31 #define TCP_ESTABLISHED  1
32 #define TCP_SYN_SENT     2
33 #define TCP_SYN_RECV     3
34 #define TCP_FIN_WAIT1    4
35 #define TCP_FIN_WAIT2    5
36 #define TCP_TIME_WAIT    6
37 #define TCP_CLOSE        7
38 #define TCP_CLOSE_WAIT   8
39 #define TCP_LAST_ACK     9
40 #define TCP_LISTEN       10
41 #define TCP_CLOSING      11
42
43 #if defined(_GNU_SOURCE) || defined(_BSD_SOURCE)
44 #define SOL_TCP 6
45 #include <sys/types.h>
46 #include <sys/socket.h>
47 #include <endian.h>
48
49 typedef u_int32_t tcp_seq;
50
51 #define TH_FIN 0x01
52 #define TH_SYN 0x02
53 #define TH_RST 0x04
54 #define TH_PUSH 0x08
55 #define TH_ACK 0x10
56 #define TH_URG 0x20
57
58 struct tcphdr {
59 #ifdef _GNU_SOURCE
60 #ifdef __GNUC__
61         __extension__
62 #endif
63         union { struct {
64
65         u_int16_t source;
66         u_int16_t dest;
67         u_int32_t seq;
68         u_int32_t ack_seq;
69 #if __BYTE_ORDER == __LITTLE_ENDIAN
70         u_int16_t res1:4;
71         u_int16_t doff:4;
72         u_int16_t fin:1;
73         u_int16_t syn:1;
74         u_int16_t rst:1;
75         u_int16_t psh:1;
76         u_int16_t ack:1;
77         u_int16_t urg:1;
78         u_int16_t res2:2;
79 #else
80         u_int16_t doff:4;
81         u_int16_t res1:4;
82         u_int16_t res2:2;
83         u_int16_t urg:1;
84         u_int16_t ack:1;
85         u_int16_t psh:1;
86         u_int16_t rst:1;
87         u_int16_t syn:1;
88         u_int16_t fin:1;
89 #endif
90         u_int16_t window;
91         u_int16_t check;
92         u_int16_t urg_ptr;
93
94         }; struct {
95 #endif
96
97         u_int16_t th_sport;
98         u_int16_t th_dport;
99         u_int32_t th_seq;
100         u_int32_t th_ack;
101 #if __BYTE_ORDER == __LITTLE_ENDIAN
102         u_int8_t th_x2:4;
103         u_int8_t th_off:4;
104 #else
105         u_int8_t th_off:4;
106         u_int8_t th_x2:4;
107 #endif
108         u_int8_t th_flags;
109         u_int16_t th_win;
110         u_int16_t th_sum;
111         u_int16_t th_urp;
112
113 #ifdef _GNU_SOURCE
114         }; };
115 #endif
116 };
117 #endif
118
119 #ifdef _GNU_SOURCE
120 #define TCPI_OPT_TIMESTAMPS     1
121 #define TCPI_OPT_SACK           2
122 #define TCPI_OPT_WSCALE         4
123 #define TCPI_OPT_ECN            8
124
125 #define TCP_CA_Open             0
126 #define TCP_CA_Disorder         1
127 #define TCP_CA_CWR              2
128 #define TCP_CA_Recovery         3
129 #define TCP_CA_Loss             4
130
131 struct tcp_info
132 {
133         u_int8_t tcpi_state;
134         u_int8_t tcpi_ca_state;
135         u_int8_t tcpi_retransmits;
136         u_int8_t tcpi_probes;
137         u_int8_t tcpi_backoff;
138         u_int8_t tcpi_options;
139         u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
140         u_int32_t tcpi_rto;
141         u_int32_t tcpi_ato;
142         u_int32_t tcpi_snd_mss;
143         u_int32_t tcpi_rcv_mss;
144         u_int32_t tcpi_unacked;
145         u_int32_t tcpi_sacked;
146         u_int32_t tcpi_lost;
147         u_int32_t tcpi_retrans;
148         u_int32_t tcpi_fackets;
149         u_int32_t tcpi_last_data_sent;
150         u_int32_t tcpi_last_ack_sent;
151         u_int32_t tcpi_last_data_recv;
152         u_int32_t tcpi_last_ack_recv;
153         u_int32_t tcpi_pmtu;
154         u_int32_t tcpi_rcv_ssthresh;
155         u_int32_t tcpi_rtt;
156         u_int32_t tcpi_rttvar;
157         u_int32_t tcpi_snd_ssthresh;
158         u_int32_t tcpi_snd_cwnd;
159         u_int32_t tcpi_advmss;
160         u_int32_t tcpi_reordering;
161         u_int32_t tcpi_rcv_rtt;
162         u_int32_t tcpi_rcv_space;
163         u_int32_t tcpi_total_retrans;
164 };
165
166 #define TCP_MD5SIG_MAXKEYLEN    80
167
168 struct tcp_md5sig
169 {
170         struct sockaddr_storage tcpm_addr;
171         u_int16_t __tcpm_pad1;
172         u_int16_t tcpm_keylen;
173         u_int32_t __tcpm_pad2;
174         u_int8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN];
175 };
176
177 #endif
178
179 #endif