The Pedigree Project  0.1
prot/tcp.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2008-2014, Pedigree Developers
3  *
4  * Please see the CONTRIB file in the root of the source tree for a full
5  * list of contributors.
6  *
7  * Permission to use, copy, modify, and distribute this software for any
8  * purpose with or without fee is hereby granted, provided that the above
9  * copyright notice and this permission notice appear in all copies.
10  *
11  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
12  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
13  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
14  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
15  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
16  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
17  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
18  */
19 
25 /*
26  * Copyright (c) 2001-2004 Swedish Institute of Computer Science.
27  * All rights reserved.
28  *
29  * Redistribution and use in source and binary forms, with or without modification,
30  * are permitted provided that the following conditions are met:
31  *
32  * 1. Redistributions of source code must retain the above copyright notice,
33  * this list of conditions and the following disclaimer.
34  * 2. Redistributions in binary form must reproduce the above copyright notice,
35  * this list of conditions and the following disclaimer in the documentation
36  * and/or other materials provided with the distribution.
37  * 3. The name of the author may not be used to endorse or promote products
38  * derived from this software without specific prior written permission.
39  *
40  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
41  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
42  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
43  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
44  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
45  * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
46  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
47  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
48  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
49  * OF SUCH DAMAGE.
50  *
51  * This file is part of the lwIP TCP/IP stack.
52  *
53  * Author: Adam Dunkels <adam@sics.se>
54  *
55  */
56 #ifndef LWIP_HDR_PROT_TCP_H
57 #define LWIP_HDR_PROT_TCP_H
58 
59 #include "lwip/arch.h"
60 
61 #ifdef __cplusplus
62 extern "C" {
63 #endif
64 
65 /* Length of the TCP header, excluding options. */
66 #define TCP_HLEN 20
67 
68 /* Fields are (of course) in network byte order.
69  * Some fields are converted to host byte order in tcp_input().
70  */
71 #ifdef PACK_STRUCT_USE_INCLUDES
72 # include "arch/bpstruct.h"
73 #endif
75 struct tcp_hdr {
76  PACK_STRUCT_FIELD(u16_t src);
77  PACK_STRUCT_FIELD(u16_t dest);
78  PACK_STRUCT_FIELD(u32_t seqno);
79  PACK_STRUCT_FIELD(u32_t ackno);
80  PACK_STRUCT_FIELD(u16_t _hdrlen_rsvd_flags);
81  PACK_STRUCT_FIELD(u16_t wnd);
82  PACK_STRUCT_FIELD(u16_t chksum);
83  PACK_STRUCT_FIELD(u16_t urgp);
84 } PACK_STRUCT_STRUCT;
86 #ifdef PACK_STRUCT_USE_INCLUDES
87 # include "arch/epstruct.h"
88 #endif
89 
90 /* TCP header flags bits */
91 #define TCP_FIN 0x01U
92 #define TCP_SYN 0x02U
93 #define TCP_RST 0x04U
94 #define TCP_PSH 0x08U
95 #define TCP_ACK 0x10U
96 #define TCP_URG 0x20U
97 #define TCP_ECE 0x40U
98 #define TCP_CWR 0x80U
99 /* Valid TCP header flags */
100 #define TCP_FLAGS 0x3fU
101 
102 #define TCPH_HDRLEN(phdr) ((u16_t)(lwip_ntohs((phdr)->_hdrlen_rsvd_flags) >> 12))
103 #define TCPH_FLAGS(phdr) ((u16_t)(lwip_ntohs((phdr)->_hdrlen_rsvd_flags) & TCP_FLAGS))
104 
105 #define TCPH_HDRLEN_SET(phdr, len) (phdr)->_hdrlen_rsvd_flags = lwip_htons(((len) << 12) | TCPH_FLAGS(phdr))
106 #define TCPH_FLAGS_SET(phdr, flags) (phdr)->_hdrlen_rsvd_flags = (((phdr)->_hdrlen_rsvd_flags & PP_HTONS(~TCP_FLAGS)) | lwip_htons(flags))
107 #define TCPH_HDRLEN_FLAGS_SET(phdr, len, flags) (phdr)->_hdrlen_rsvd_flags = (u16_t)(lwip_htons((u16_t)((len) << 12) | (flags)))
108 
109 #define TCPH_SET_FLAG(phdr, flags ) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags | lwip_htons(flags))
110 #define TCPH_UNSET_FLAG(phdr, flags) (phdr)->_hdrlen_rsvd_flags = ((phdr)->_hdrlen_rsvd_flags & ~lwip_htons(flags))
111 
112 #ifdef __cplusplus
113 }
114 #endif
115 
116 #endif /* LWIP_HDR_PROT_TCP_H */
#define PACK_STRUCT_BEGIN
Definition: arch.h:261
#define PACK_STRUCT_END
Definition: arch.h:270