2.9
[glibc/nacl-glibc.git] / sysdeps / gnu / netinet / tcp.h
blob06e8414b58fd888f64be76434bd513da21be0162
1 /*
2 * Copyright (c) 1982, 1986, 1993
3 * The Regents of the University of California. All rights reserved.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
7 * are met:
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 4. Neither the name of the University nor the names of its contributors
14 * may be used to endorse or promote products derived from this software
15 * without specific prior written permission.
17 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
29 * @(#)tcp.h 8.1 (Berkeley) 6/10/93
32 #ifndef _NETINET_TCP_H
33 #define _NETINET_TCP_H 1
35 #include <features.h>
38 * User-settable options (used with setsockopt).
40 #define TCP_NODELAY 1 /* Don't delay send to coalesce packets */
41 #define TCP_MAXSEG 2 /* Set maximum segment size */
42 #define TCP_CORK 3 /* Control sending of partial frames */
43 #define TCP_KEEPIDLE 4 /* Start keeplives after this period */
44 #define TCP_KEEPINTVL 5 /* Interval between keepalives */
45 #define TCP_KEEPCNT 6 /* Number of keepalives before death */
46 #define TCP_SYNCNT 7 /* Number of SYN retransmits */
47 #define TCP_LINGER2 8 /* Life time of orphaned FIN-WAIT-2 state */
48 #define TCP_DEFER_ACCEPT 9 /* Wake up listener only when data arrive */
49 #define TCP_WINDOW_CLAMP 10 /* Bound advertised window */
50 #define TCP_INFO 11 /* Information about this connection. */
51 #define TCP_QUICKACK 12 /* Bock/reenable quick ACKs. */
52 #define TCP_CONGESTION 13 /* Congestion control algorithm. */
53 #define TCP_MD5SIG 14 /* TCP MD5 Signature (RFC2385) */
55 #ifdef __USE_MISC
56 # include <sys/types.h>
57 # include <sys/socket.h>
59 # ifdef __FAVOR_BSD
60 typedef u_int32_t tcp_seq;
62 * TCP header.
63 * Per RFC 793, September, 1981.
65 struct tcphdr
67 u_int16_t th_sport; /* source port */
68 u_int16_t th_dport; /* destination port */
69 tcp_seq th_seq; /* sequence number */
70 tcp_seq th_ack; /* acknowledgement number */
71 # if __BYTE_ORDER == __LITTLE_ENDIAN
72 u_int8_t th_x2:4; /* (unused) */
73 u_int8_t th_off:4; /* data offset */
74 # endif
75 # if __BYTE_ORDER == __BIG_ENDIAN
76 u_int8_t th_off:4; /* data offset */
77 u_int8_t th_x2:4; /* (unused) */
78 # endif
79 u_int8_t th_flags;
80 # define TH_FIN 0x01
81 # define TH_SYN 0x02
82 # define TH_RST 0x04
83 # define TH_PUSH 0x08
84 # define TH_ACK 0x10
85 # define TH_URG 0x20
86 u_int16_t th_win; /* window */
87 u_int16_t th_sum; /* checksum */
88 u_int16_t th_urp; /* urgent pointer */
91 # else /* !__FAVOR_BSD */
92 struct tcphdr
94 u_int16_t source;
95 u_int16_t dest;
96 u_int32_t seq;
97 u_int32_t ack_seq;
98 # if __BYTE_ORDER == __LITTLE_ENDIAN
99 u_int16_t res1:4;
100 u_int16_t doff:4;
101 u_int16_t fin:1;
102 u_int16_t syn:1;
103 u_int16_t rst:1;
104 u_int16_t psh:1;
105 u_int16_t ack:1;
106 u_int16_t urg:1;
107 u_int16_t res2:2;
108 # elif __BYTE_ORDER == __BIG_ENDIAN
109 u_int16_t doff:4;
110 u_int16_t res1:4;
111 u_int16_t res2:2;
112 u_int16_t urg:1;
113 u_int16_t ack:1;
114 u_int16_t psh:1;
115 u_int16_t rst:1;
116 u_int16_t syn:1;
117 u_int16_t fin:1;
118 # else
119 # error "Adjust your <bits/endian.h> defines"
120 # endif
121 u_int16_t window;
122 u_int16_t check;
123 u_int16_t urg_ptr;
125 # endif /* __FAVOR_BSD */
127 enum
129 TCP_ESTABLISHED = 1,
130 TCP_SYN_SENT,
131 TCP_SYN_RECV,
132 TCP_FIN_WAIT1,
133 TCP_FIN_WAIT2,
134 TCP_TIME_WAIT,
135 TCP_CLOSE,
136 TCP_CLOSE_WAIT,
137 TCP_LAST_ACK,
138 TCP_LISTEN,
139 TCP_CLOSING /* now a valid state */
142 # define TCPOPT_EOL 0
143 # define TCPOPT_NOP 1
144 # define TCPOPT_MAXSEG 2
145 # define TCPOLEN_MAXSEG 4
146 # define TCPOPT_WINDOW 3
147 # define TCPOLEN_WINDOW 3
148 # define TCPOPT_SACK_PERMITTED 4 /* Experimental */
149 # define TCPOLEN_SACK_PERMITTED 2
150 # define TCPOPT_SACK 5 /* Experimental */
151 # define TCPOPT_TIMESTAMP 8
152 # define TCPOLEN_TIMESTAMP 10
153 # define TCPOLEN_TSTAMP_APPA (TCPOLEN_TIMESTAMP+2) /* appendix A */
155 # define TCPOPT_TSTAMP_HDR \
156 (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
159 * Default maximum segment size for TCP.
160 * With an IP MSS of 576, this is 536,
161 * but 512 is probably more convenient.
162 * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
164 # define TCP_MSS 512
166 # define TCP_MAXWIN 65535 /* largest value for (unscaled) window */
168 # define TCP_MAX_WINSHIFT 14 /* maximum window shift */
170 # define SOL_TCP 6 /* TCP level */
173 # define TCPI_OPT_TIMESTAMPS 1
174 # define TCPI_OPT_SACK 2
175 # define TCPI_OPT_WSCALE 4
176 # define TCPI_OPT_ECN 8
178 /* Values for tcpi_state. */
179 enum tcp_ca_state
181 TCP_CA_Open = 0,
182 TCP_CA_Disorder = 1,
183 TCP_CA_CWR = 2,
184 TCP_CA_Recovery = 3,
185 TCP_CA_Loss = 4
188 struct tcp_info
190 u_int8_t tcpi_state;
191 u_int8_t tcpi_ca_state;
192 u_int8_t tcpi_retransmits;
193 u_int8_t tcpi_probes;
194 u_int8_t tcpi_backoff;
195 u_int8_t tcpi_options;
196 u_int8_t tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
198 u_int32_t tcpi_rto;
199 u_int32_t tcpi_ato;
200 u_int32_t tcpi_snd_mss;
201 u_int32_t tcpi_rcv_mss;
203 u_int32_t tcpi_unacked;
204 u_int32_t tcpi_sacked;
205 u_int32_t tcpi_lost;
206 u_int32_t tcpi_retrans;
207 u_int32_t tcpi_fackets;
209 /* Times. */
210 u_int32_t tcpi_last_data_sent;
211 u_int32_t tcpi_last_ack_sent; /* Not remembered, sorry. */
212 u_int32_t tcpi_last_data_recv;
213 u_int32_t tcpi_last_ack_recv;
215 /* Metrics. */
216 u_int32_t tcpi_pmtu;
217 u_int32_t tcpi_rcv_ssthresh;
218 u_int32_t tcpi_rtt;
219 u_int32_t tcpi_rttvar;
220 u_int32_t tcpi_snd_ssthresh;
221 u_int32_t tcpi_snd_cwnd;
222 u_int32_t tcpi_advmss;
223 u_int32_t tcpi_reordering;
225 u_int32_t tcpi_rcv_rtt;
226 u_int32_t tcpi_rcv_space;
228 u_int32_t tcpi_total_retrans;
232 /* For TCP_MD5SIG socket option. */
233 #define TCP_MD5SIG_MAXKEYLEN 80
235 struct tcp_md5sig
237 struct sockaddr_storage tcpm_addr; /* Address associated. */
238 u_int16_t __tcpm_pad1; /* Zero. */
239 u_int16_t tcpm_keylen; /* Key length. */
240 u_int32_t __tcpm_pad2; /* Zero. */
241 u_int8_t tcpm_key[TCP_MD5SIG_MAXKEYLEN]; /* Key (binary). */
244 #endif /* Misc. */
246 #endif /* netinet/tcp.h */