Subversion Repositories HelenOS

Rev

Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. /*
  2.  * Copyright (c) 2009 Lukas Mejdrech
  3.  * All rights reserved.
  4.  *
  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.  *
  9.  * - Redistributions of source code must retain the above copyright
  10.  *   notice, this list of conditions and the following disclaimer.
  11.  * - Redistributions in binary form must reproduce the above copyright
  12.  *   notice, this list of conditions and the following disclaimer in the
  13.  *   documentation and/or other materials provided with the distribution.
  14.  * - The name of the author may not be used to endorse or promote products
  15.  *   derived from this software without specific prior written permission.
  16.  *
  17.  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
  18.  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
  19.  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
  20.  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
  21.  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
  22.  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  23.  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  24.  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  25.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
  26.  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  27.  */
  28.  
  29. /** @addtogroup tcp
  30.  *  @{
  31.  */
  32.  
  33. /** @file
  34.  *  TCP header definition.
  35.  *  Names according to the linux src/include/linux/tcp.h header file.
  36.  */
  37.  
  38. #ifndef __NET_TCP_HEADER_H__
  39. #define __NET_TCP_HEADER_H__
  40.  
  41. #include <sys/types.h>
  42.  
  43. /** Type definition of the transmission datagram header.
  44.  *  @see tcp_header
  45.  */
  46. typedef struct tcp_header   tcp_header_t;
  47.  
  48. /** Type definition of the transmission datagram header pointer.
  49.  *  @see tcp_header
  50.  */
  51. typedef tcp_header_t *      tcp_header_ref;
  52.  
  53. /** Transmission datagram header.
  54.  */
  55. struct tcp_header{
  56.     /** The 16-bit source port number, used by the receiver to reply.
  57.      */
  58.     uint16_t    source;
  59.     /** The 16-bit destination port number.
  60.      */
  61.     uint16_t    dest;
  62.     /** The sequence number of the first data byte in this segment.
  63.      *  If the SYN control bit is set, the sequence number is the initial sequence number (n) and the first data byte is n+1.
  64.      */
  65.     uint32_t    seq;
  66.     /** If the ACK control bit is set, this field contains the value of the next sequence number that the receiver is expecting to receive.
  67.      */
  68.     uint32_t    ack_seq;
  69. #ifdef ARCH_IS_BIG_ENDIAN
  70.     /** The number of 32-bit words in the TCP header.
  71.      *  It indicates where the data begins.
  72.      */
  73.     uint8_t doff:4;
  74.     /** Four bits reserved for future use.
  75.      *  Must be zero.
  76.      */
  77.     uint8_t res1:4;
  78. #else
  79.     /** Four bits reserved for future use.
  80.      *  Must be zero.
  81.      */
  82.     uint8_t res1:4;
  83.     /** The number of 32-bit words in the TCP header.
  84.      *  It indicates where the data begins.
  85.      */
  86.     uint8_t doff:4;
  87. #endif
  88. #ifdef ARCH_IS_BIG_ENDIAN
  89.     /** Two bits reserved for future use.
  90.      *  Must be zero.
  91.      */
  92.     uint8_t res2:2;
  93.     /** Indicates that the urgent pointer field is significant in this segment.
  94.      */
  95.     uint8_t urg:1;
  96.     /** Indicates that the acknowledgment field is significant in this segment.
  97.      */
  98.     uint8_t ack:1;
  99.     /** Push function.
  100.      */
  101.     uint8_t psh:1;
  102.     /** Resets the connection.
  103.      */
  104.     uint8_t rst:1;
  105.     /** Synchronizes the sequence numbers.
  106.      */
  107.     uint8_t syn:1;
  108.     /** No more data from sender.
  109.      */
  110.     uint8_t fin:1;
  111. #else
  112.     /** No more data from sender.
  113.      */
  114.     uint8_t fin:1;
  115.     /** Synchronizes the sequence numbers.
  116.      */
  117.     uint8_t syn:1;
  118.     /** Resets the connection.
  119.      */
  120.     uint8_t rst:1;
  121.     /** Push function.
  122.      */
  123.     uint8_t psh:1;
  124.     /** Indicates that the acknowledgment field is significant in this segment.
  125.      */
  126.     uint8_t ack:1;
  127.     /** Indicates that the urgent pointer field is significant in this segment.
  128.      */
  129.     uint8_t urg:1;
  130.     /** Two bits reserved for future use.
  131.      *  Must be zero.
  132.      */
  133.     uint8_t res2:2;
  134. #endif
  135.     /** Used in ACK segments.
  136.      *  It specifies the number of data bytes, beginning with the one indicated in the acknowledgment number field that the receiver (the sender of this segment) is willing to accept.
  137.      */
  138.     uint16_t    window;
  139.     /** The 16-bit one's complement of the one's complement sum of all 16-bit words in a pseudo-header, the TCP header, and the TCP data.
  140.      *  While computing the checksum, the checksum field itself is considered zero.
  141.      *  The pseudo header conceptually prefixed to the TCP header contains the source address, the destination address, the protocol, and the TCP length.
  142.      *  This information gives protection against misrouted datagrams.
  143.      *  If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic).
  144.      */
  145.     uint16_t    check;
  146.     /** Points to the first data octet following the urgent data.
  147.      *  Only significant when the URG control bit is set.
  148.      */
  149.     uint16_t    urg_ptr;
  150. } __attribute__ ((packed));
  151.  
  152. #endif
  153.  
  154. /** @}
  155.  */
  156.