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