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

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since 0578271 was 89e57cee, checked in by Jakub Jermar <jakub@…>, 15 years ago

Cleanup tpc.

  • Property mode set to 100644
File size: 4.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/** TCP header size in bytes. */
44#define TCP_HEADER_SIZE sizeof(tcp_header_t)
45
46/** Returns the actual TCP header length in bytes.
47 * @param[in] header The TCP packet header.
48 */
49#define TCP_HEADER_LENGTH(header) ((header)->header_length * 4U)
50
51/** Returns the TCP header length.
52 * @param[in] length The TCP header length in bytes.
53 */
54#define TCP_COMPUTE_HEADER_LENGTH(length) ((uint8_t) ((length) / 4U))
55
56/** Type definition of the transmission datagram header.
57 * @see tcp_header
58 */
59typedef struct tcp_header tcp_header_t;
60
61/** Type definition of the transmission datagram header pointer.
62 * @see tcp_header
63 */
64typedef tcp_header_t *tcp_header_ref;
65
66/** Type definition of the transmission datagram header option.
67 * @see tcp_option
68 */
69typedef struct tcp_option tcp_option_t;
70
71/** Type definition of the transmission datagram header option pointer.
72 * @see tcp_option
73 */
74typedef tcp_option_t *tcp_option_ref;
75
76/** Type definition of the Maximum segment size TCP option. */
77typedef struct tcp_max_segment_size_option tcp_max_segment_size_option_t;
78
79/** Type definition of the Maximum segment size TCP option pointer.
80 * @see tcp_max_segment_size_option
81 */
82typedef tcp_max_segment_size_option_t *tcp_max_segment_size_option_ref;
83
84/** Transmission datagram header. */
85struct tcp_header {
86 uint16_t source_port;
87 uint16_t destination_port;
88 uint32_t sequence_number;
89 uint32_t acknowledgement_number;
90
91#ifdef ARCH_IS_BIG_ENDIAN
92 uint8_t header_length:4;
93 uint8_t reserved1:4;
94#else
95 uint8_t reserved1:4;
96 uint8_t header_length:4;
97#endif
98
99#ifdef ARCH_IS_BIG_ENDIAN
100 uint8_t reserved2:2;
101 uint8_t urgent:1;
102 uint8_t acknowledge:1;
103 uint8_t push:1;
104 uint8_t reset:1;
105 uint8_t synchronize:1;
106 uint8_t finalize:1;
107#else
108 uint8_t finalize:1;
109 uint8_t synchronize:1;
110 uint8_t reset:1;
111 uint8_t push:1;
112 uint8_t acknowledge:1;
113 uint8_t urgent:1;
114 uint8_t reserved2:2;
115#endif
116
117 uint16_t window;
118 uint16_t checksum;
119 uint16_t urgent_pointer;
120} __attribute__ ((packed));
121
122/** Transmission datagram header option. */
123struct tcp_option {
124 /** Option type. */
125 uint8_t type;
126 /** Option length. */
127 uint8_t length;
128};
129
130/** Maximum segment size TCP option. */
131struct tcp_max_segment_size_option {
132 /** TCP option.
133 * @see TCPOPT_MAX_SEGMENT_SIZE
134 * @see TCPOPT_MAX_SEGMENT_SIZE_LENGTH
135 */
136 tcp_option_t option;
137
138 /** Maximum segment size in bytes. */
139 uint16_t max_segment_size;
140} __attribute__ ((packed));
141
142#endif
143
144/** @}
145 */
Note: See TracBrowser for help on using the repository browser.