source: mainline/uspace/srv/net/tl/tcp/tcp_header.h@ 21580dd

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 21580dd was 21580dd, checked in by Lukas Mejdrech <lukas@…>, 16 years ago

Merged with network branch svn://svn.helenos.org/HelenOS/branches/network revision 4759; ipc_share_* and ipc_data_* changed to async_*; client connection in module.c returns on IPC_M_PHONE_HUNGUP; * Qemu scripts renamed to net-qe.*; (the dp8390 does not respond)

  • Property mode set to 100644
File size: 7.0 KB
Line 
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 * Based on the RFC~793.
36 */
37
38#ifndef __NET_TCP_HEADER_H__
39#define __NET_TCP_HEADER_H__
40
41#include <sys/types.h>
42
43/** Returns the actual TCP header length in bytes.
44 * @param[in] header The TCP packet header.
45 */
46#define TCP_HEADER_LENGTH( header ) (( header )->header_length * 4u )
47
48/** Returns the TCP header length.
49 * @param[in] length The TCP header length in bytes.
50 */
51#define TCP_COMPUTE_HEADER_LENGTH( length ) (( uint8_t ) (( length ) / 4u ))
52
53/** Type definition of the transmission datagram header.
54 * @see tcp_header
55 */
56typedef struct tcp_header tcp_header_t;
57
58/** Type definition of the transmission datagram header pointer.
59 * @see tcp_header
60 */
61typedef tcp_header_t * tcp_header_ref;
62
63/** Type definition of the transmission datagram header option.
64 * @see tcp_option
65 */
66typedef struct tcp_option tcp_option_t;
67
68/** Type definition of the transmission datagram header option pointer.
69 * @see tcp_option
70 */
71typedef tcp_option_t * tcp_option_ref;
72
73/** Type definition of the Maximum segment size TCP option.
74 * @see ...
75 */
76typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
77
78/** Type definition of the Maximum segment size TCP option pointer.
79 * @see tcp_max_segment_size_option
80 */
81typedef tcp_max_segment_size_option_t * tcp_max_segment_size_option_ref;
82
83/** Transmission datagram header.
84 */
85struct tcp_header{
86 /** The source port number.
87 */
88 uint16_t source_port;
89 /** The destination port number.
90 */
91 uint16_t destination_port;
92 /** The sequence number of the first data octet in this segment (except when SYN is present).
93 * If SYN is present the sequence number is the initial sequence number (ISN) and the first data octet is ISN+1.
94 */
95 uint32_t sequence_number;
96 /** If the ACK control bit is set this field contains the value of the next sequence number the sender of the segment is expecting to receive.
97 * Once a~connection is established this is always sent.
98 * @see acknowledge
99 */
100 uint32_t acknowledgement_number;
101#ifdef ARCH_IS_BIG_ENDIAN
102 /** The number of 32~bit words in the TCP Header.
103 * This indicates where the data begins.
104 * The TCP header (even one including options) is an integral number of 32~bits long.
105 */
106 uint8_t header_length:4;
107 /** Four bits reserved for future use.
108 * Must be zero.
109 */
110 uint8_t reserved1:4;
111#else
112 /** Four bits reserved for future use.
113 * Must be zero.
114 */
115 uint8_t reserved1:4;
116 /** The number of 32~bit words in the TCP Header.
117 * This indicates where the data begins.
118 * The TCP header (even one including options) is an integral number of 32~bits long.
119 */
120 uint8_t header_length:4;
121#endif
122#ifdef ARCH_IS_BIG_ENDIAN
123 /** Two bits reserved for future use.
124 * Must be zero.
125 */
126 uint8_t reserved2:2;
127 /** Urgent Pointer field significant.
128 * @see tcp_header:urgent_pointer
129 */
130 uint8_t urgent:1;
131 /** Acknowledgment field significant
132 * @see tcp_header:acknowledgement_number
133 */
134 uint8_t acknowledge:1;
135 /** Push function.
136 */
137 uint8_t push:1;
138 /** Reset the connection.
139 */
140 uint8_t reset:1;
141 /** Synchronize the sequence numbers.
142 */
143 uint8_t synchronize:1;
144 /** No more data from the sender.
145 */
146 uint8_t finalize:1;
147#else
148 /** No more data from the sender.
149 */
150 uint8_t finalize:1;
151 /** Synchronize the sequence numbers.
152 */
153 uint8_t synchronize:1;
154 /** Reset the connection.
155 */
156 uint8_t reset:1;
157 /** Push function.
158 */
159 uint8_t push:1;
160 /** Acknowledgment field significant.
161 * @see tcp_header:acknowledgement_number
162 */
163 uint8_t acknowledge:1;
164 /** Urgent Pointer field significant.
165 * @see tcp_header:urgent_pointer
166 */
167 uint8_t urgent:1;
168 /** Two bits reserved for future use.
169 * Must be zero.
170 */
171 uint8_t reserved2:2;
172#endif
173 /** The number of data octets beginning with the one indicated in the acknowledgment field which the sender of this segment is willing to accept.
174 * @see tcp_header:acknowledge
175 */
176 uint16_t window;
177 /** The checksum field is the 16~bit one's complement of the one's complement sum of all 16~bit words in the header and text.
178 * If a~segment contains an odd number of header and text octets to be checksummed, the last octet is padded on the right with zeros to form a~16~bit word for checksum purposes.
179 * The pad is not transmitted as part of the segment.
180 * While computing the checksum, the checksum field itself is replaced with zeros.
181 * The checksum also coves a~pseudo header conceptually.
182 * The pseudo header conceptually prefixed to the TCP header contains the source address, the destination address, the protocol, and the TCP length.
183 * This information gives protection against misrouted datagrams.
184 * If the computed checksum is zero, it is transmitted as all ones (the equivalent in one's complement arithmetic).
185 */
186 uint16_t checksum;
187 /** This field communicates the current value of the urgent pointer as a~positive offset from the sequence number in this segment.
188 * The urgent pointer points to the sequence number of the octet following the urgent data.
189 * This field is only be interpreted in segments with the URG control bit set.
190 * @see tcp_header:urgent
191 */
192 uint16_t urgent_pointer;
193} __attribute__ ((packed));
194
195/** Transmission datagram header option.
196 */
197struct tcp_option{
198 /** Option type.
199 */
200 uint8_t type;
201 /** Option length.
202 */
203 uint8_t length;
204};
205
206/** Maximum segment size TCP option.
207 */
208struct tcp_max_segment_size_option{
209 /** TCP option.
210 * @see TCPOPT_MAX_SEGMENT_SIZE
211 * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
212 */
213 tcp_option_t option;
214 /** Maximum segment size in bytes.
215 */
216 uint16_t max_segment_size;
217} __attribute__ ((packed));
218
219#endif
220
221/** @}
222 */
Note: See TracBrowser for help on using the repository browser.