Back to index

glibc  2.9
tcp.h
Go to the documentation of this file.
00001 /*
00002  * Copyright (c) 1982, 1986, 1993
00003  *     The Regents of the University of California.  All rights reserved.
00004  *
00005  * Redistribution and use in source and binary forms, with or without
00006  * modification, are permitted provided that the following conditions
00007  * are met:
00008  * 1. Redistributions of source code must retain the above copyright
00009  *    notice, this list of conditions and the following disclaimer.
00010  * 2. Redistributions in binary form must reproduce the above copyright
00011  *    notice, this list of conditions and the following disclaimer in the
00012  *    documentation and/or other materials provided with the distribution.
00013  * 4. Neither the name of the University nor the names of its contributors
00014  *    may be used to endorse or promote products derived from this software
00015  *    without specific prior written permission.
00016  *
00017  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00018  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00019  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00020  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00021  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00022  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00023  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00024  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00025  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00026  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00027  * SUCH DAMAGE.
00028  *
00029  *     @(#)tcp.h     8.1 (Berkeley) 6/10/93
00030  */
00031 
00032 #ifndef _NETINET_TCP_H
00033 #define _NETINET_TCP_H      1
00034 
00035 #include <features.h>
00036 
00037 /*
00038  * User-settable options (used with setsockopt).
00039  */
00040 #define       TCP_NODELAY    1     /* Don't delay send to coalesce packets  */
00041 #define       TCP_MAXSEG     2     /* Set maximum segment size  */
00042 #define TCP_CORK      3     /* Control sending of partial frames  */
00043 #define TCP_KEEPIDLE  4     /* Start keeplives after this period */
00044 #define TCP_KEEPINTVL        5     /* Interval between keepalives */
00045 #define TCP_KEEPCNT   6     /* Number of keepalives before death */
00046 #define TCP_SYNCNT    7     /* Number of SYN retransmits */
00047 #define TCP_LINGER2   8     /* Life time of orphaned FIN-WAIT-2 state */
00048 #define TCP_DEFER_ACCEPT 9  /* Wake up listener only when data arrive */
00049 #define TCP_WINDOW_CLAMP 10 /* Bound advertised window */
00050 #define TCP_INFO      11    /* Information about this connection. */
00051 #define       TCP_QUICKACK   12    /* Bock/reenable quick ACKs.  */
00052 #define TCP_CONGESTION       13    /* Congestion control algorithm.  */
00053 #define TCP_MD5SIG    14    /* TCP MD5 Signature (RFC2385) */
00054 
00055 #ifdef __USE_MISC
00056 # include <sys/types.h>
00057 # include <sys/socket.h>
00058 
00059 # ifdef __FAVOR_BSD
00060 typedef       u_int32_t tcp_seq;
00061 /*
00062  * TCP header.
00063  * Per RFC 793, September, 1981.
00064  */
00065 struct tcphdr
00066   {
00067     u_int16_t th_sport;            /* source port */
00068     u_int16_t th_dport;            /* destination port */
00069     tcp_seq th_seq;         /* sequence number */
00070     tcp_seq th_ack;         /* acknowledgement number */
00071 #  if __BYTE_ORDER == __LITTLE_ENDIAN
00072     u_int8_t th_x2:4;              /* (unused) */
00073     u_int8_t th_off:4;             /* data offset */
00074 #  endif
00075 #  if __BYTE_ORDER == __BIG_ENDIAN
00076     u_int8_t th_off:4;             /* data offset */
00077     u_int8_t th_x2:4;              /* (unused) */
00078 #  endif
00079     u_int8_t th_flags;
00080 #  define TH_FIN     0x01
00081 #  define TH_SYN     0x02
00082 #  define TH_RST     0x04
00083 #  define TH_PUSH    0x08
00084 #  define TH_ACK     0x10
00085 #  define TH_URG     0x20
00086     u_int16_t th_win;              /* window */
00087     u_int16_t th_sum;              /* checksum */
00088     u_int16_t th_urp;              /* urgent pointer */
00089 };
00090 
00091 # else /* !__FAVOR_BSD */
00092 struct tcphdr
00093   {
00094     u_int16_t source;
00095     u_int16_t dest;
00096     u_int32_t seq;
00097     u_int32_t ack_seq;
00098 #  if __BYTE_ORDER == __LITTLE_ENDIAN
00099     u_int16_t res1:4;
00100     u_int16_t doff:4;
00101     u_int16_t fin:1;
00102     u_int16_t syn:1;
00103     u_int16_t rst:1;
00104     u_int16_t psh:1;
00105     u_int16_t ack:1;
00106     u_int16_t urg:1;
00107     u_int16_t res2:2;
00108 #  elif __BYTE_ORDER == __BIG_ENDIAN
00109     u_int16_t doff:4;
00110     u_int16_t res1:4;
00111     u_int16_t res2:2;
00112     u_int16_t urg:1;
00113     u_int16_t ack:1;
00114     u_int16_t psh:1;
00115     u_int16_t rst:1;
00116     u_int16_t syn:1;
00117     u_int16_t fin:1;
00118 #  else
00119 #   error "Adjust your <bits/endian.h> defines"
00120 #  endif
00121     u_int16_t window;
00122     u_int16_t check;
00123     u_int16_t urg_ptr;
00124 };
00125 # endif /* __FAVOR_BSD */
00126 
00127 enum
00128 {
00129   TCP_ESTABLISHED = 1,
00130   TCP_SYN_SENT,
00131   TCP_SYN_RECV,
00132   TCP_FIN_WAIT1,
00133   TCP_FIN_WAIT2,
00134   TCP_TIME_WAIT,
00135   TCP_CLOSE,
00136   TCP_CLOSE_WAIT,
00137   TCP_LAST_ACK,
00138   TCP_LISTEN,
00139   TCP_CLOSING   /* now a valid state */
00140 };
00141 
00142 # define TCPOPT_EOL         0
00143 # define TCPOPT_NOP         1
00144 # define TCPOPT_MAXSEG             2
00145 # define TCPOLEN_MAXSEG            4
00146 # define TCPOPT_WINDOW             3
00147 # define TCPOLEN_WINDOW            3
00148 # define TCPOPT_SACK_PERMITTED     4             /* Experimental */
00149 # define TCPOLEN_SACK_PERMITTED    2
00150 # define TCPOPT_SACK        5             /* Experimental */
00151 # define TCPOPT_TIMESTAMP   8
00152 # define TCPOLEN_TIMESTAMP  10
00153 # define TCPOLEN_TSTAMP_APPA       (TCPOLEN_TIMESTAMP+2) /* appendix A */
00154 
00155 # define TCPOPT_TSTAMP_HDR  \
00156     (TCPOPT_NOP<<24|TCPOPT_NOP<<16|TCPOPT_TIMESTAMP<<8|TCPOLEN_TIMESTAMP)
00157 
00158 /*
00159  * Default maximum segment size for TCP.
00160  * With an IP MSS of 576, this is 536,
00161  * but 512 is probably more convenient.
00162  * This should be defined as MIN(512, IP_MSS - sizeof (struct tcpiphdr)).
00163  */
00164 # define TCP_MSS     512
00165 
00166 # define TCP_MAXWIN  65535  /* largest value for (unscaled) window */
00167 
00168 # define TCP_MAX_WINSHIFT   14     /* maximum window shift */
00169 
00170 # define SOL_TCP            6      /* TCP level */
00171 
00172 
00173 # define TCPI_OPT_TIMESTAMPS       1
00174 # define TCPI_OPT_SACK             2
00175 # define TCPI_OPT_WSCALE    4
00176 # define TCPI_OPT_ECN              8
00177 
00178 /* Values for tcpi_state.  */
00179 enum tcp_ca_state
00180 {
00181   TCP_CA_Open = 0,
00182   TCP_CA_Disorder = 1,
00183   TCP_CA_CWR = 2,
00184   TCP_CA_Recovery = 3,
00185   TCP_CA_Loss = 4
00186 };
00187 
00188 struct tcp_info
00189 {
00190   u_int8_t    tcpi_state;
00191   u_int8_t    tcpi_ca_state;
00192   u_int8_t    tcpi_retransmits;
00193   u_int8_t    tcpi_probes;
00194   u_int8_t    tcpi_backoff;
00195   u_int8_t    tcpi_options;
00196   u_int8_t    tcpi_snd_wscale : 4, tcpi_rcv_wscale : 4;
00197 
00198   u_int32_t   tcpi_rto;
00199   u_int32_t   tcpi_ato;
00200   u_int32_t   tcpi_snd_mss;
00201   u_int32_t   tcpi_rcv_mss;
00202 
00203   u_int32_t   tcpi_unacked;
00204   u_int32_t   tcpi_sacked;
00205   u_int32_t   tcpi_lost;
00206   u_int32_t   tcpi_retrans;
00207   u_int32_t   tcpi_fackets;
00208 
00209   /* Times. */
00210   u_int32_t   tcpi_last_data_sent;
00211   u_int32_t   tcpi_last_ack_sent;  /* Not remembered, sorry.  */
00212   u_int32_t   tcpi_last_data_recv;
00213   u_int32_t   tcpi_last_ack_recv;
00214 
00215   /* Metrics. */
00216   u_int32_t   tcpi_pmtu;
00217   u_int32_t   tcpi_rcv_ssthresh;
00218   u_int32_t   tcpi_rtt;
00219   u_int32_t   tcpi_rttvar;
00220   u_int32_t   tcpi_snd_ssthresh;
00221   u_int32_t   tcpi_snd_cwnd;
00222   u_int32_t   tcpi_advmss;
00223   u_int32_t   tcpi_reordering;
00224 
00225   u_int32_t   tcpi_rcv_rtt;
00226   u_int32_t   tcpi_rcv_space;
00227 
00228   u_int32_t   tcpi_total_retrans;
00229 };
00230 
00231 
00232 /* For TCP_MD5SIG socket option.  */
00233 #define TCP_MD5SIG_MAXKEYLEN       80
00234 
00235 struct tcp_md5sig
00236 {
00237   struct sockaddr_storage tcpm_addr;             /* Address associated.  */
00238   u_int16_t   __tcpm_pad1;                /* Zero.  */
00239   u_int16_t   tcpm_keylen;                /* Key length.  */
00240   u_int32_t   __tcpm_pad2;                /* Zero.  */
00241   u_int8_t    tcpm_key[TCP_MD5SIG_MAXKEYLEN];    /* Key (binary).  */
00242 };
00243 
00244 #endif /* Misc.  */
00245 
00246 #endif /* netinet/tcp.h */