home *** CD-ROM | disk | FTP | other *** search
/ RISCWORLD 7 / RISCWORLD_VOL7.iso / Software / Issue6 / SDL.ZIP / !gcc / include / unixlib / netinet / h / tcp < prev    next >
Encoding:
Text File  |  2006-09-17  |  6.8 KB  |  243 lines

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