TCPPacket.hh
Go to the documentation of this file.
1 //
2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
6 //
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
11 //
12 
13 
17 #ifndef HH_SENF_Packets_DefaultBundle_TCPPacket_
18 #define HH_SENF_Packets_DefaultBundle_TCPPacket_ 1
19 
20 // Custom includes
21 #include <senf/Packets/Packets.hh>
22 #include "Registries.hh"
23 
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 
26 namespace senf {
27 
37  {
38 # include SENF_PARSER()
39 
44 
45  SENF_PARSER_BITFIELD ( dataoffset, 4, unsigned );
46  SENF_PARSER_PRIVATE_BITFIELD( reserved, 6, unsigned );
47  SENF_PARSER_BITFIELD ( urgf, 1, bool );
48  SENF_PARSER_BITFIELD ( ackf, 1, bool );
49  SENF_PARSER_BITFIELD ( pshf, 1, bool );
50  SENF_PARSER_BITFIELD ( rstf, 1, bool );
51  SENF_PARSER_BITFIELD ( synf, 1, bool );
52  SENF_PARSER_BITFIELD ( finf, 1, bool );
53 
57 
58  // skip option part in TCP-Header, dataoffset()*4 = TCP header length in byte
59  // for options see http://www.iana.org/assignments/tcp-parameters/
60  // if dataoffset() < 5 packet is invalid
61  SENF_PARSER_SKIP( (dataoffset() < 5 ? 0 : dataoffset()*4-20), 0);
62 
64 
66  // Reserved: 6 bits, reserved for future use. Must be zero.
67  // see http://tools.ietf.org/html/rfc793
68  reserved_() = 0;
69  // dataoffset per default 5, 5*4 = 20 Byte Header Length
70  dataoffset() = 5;
71  }
72 
73  boost::uint16_t calcChecksum() const;
74 
77  bool validateChecksum() const {
78  return checksum() == 0u || checksum() == calcChecksum();
79  }
80 
82  };
83 
134  : public PacketTypeBase,
135  public PacketTypeMixin<TCPPacketType>
136  {
140 
141  using mixin::nextPacketRange;
142  using mixin::initSize;
143  using mixin::init;
144 
146  static void dump(packet p, std::ostream & os);
147 
148  static void finalize(packet p);
149 
153  static const IPTypes::key_t ipType = 6;
154  };
155 
161 }
162 
163 
164 //-/////////////////////////////////////////////////////////////////////////////////////////////////
165 //#include "TCPPacket.cci"
166 //#include "TCPPacket.ct"
167 //#include "TCPPacket.cti"
168 #endif
169 
170 
171 // Local Variables:
172 // mode: c++
173 // fill-column: 100
174 // c-file-style: "senf"
175 // indent-tabs-mode: nil
176 // ispell-local-dictionary: "american"
177 // compile-command: "scons -u test"
178 // comment-column: 40
179 // End:
UInt32Parser acknowledgmentnumber() const
#define SENF_PARSER_BITFIELD(name, bits, type)
Define bit-field.
senf::FlagParser<?> synf() const
UInt32Parser sequencenumber() const
Mixin to provide standard implementations for nextPacketRange and nextPacketType. ...
Definition: PacketType.hh:300
ConcretePacket< TCPPacketType > packet
TCP packet typedef.
Definition: TCPPacket.hh:138
Packets public header.
senf::FlagParser<?> rstf() const
DefaultBundle packet registries public header.
senf::UIntFieldParser<?,?+6 > reserved() const
boost::uint8_t key_t
Definition: Registries.hh:61
PacketTypeMixin< TCPPacketType > mixin
Definition: TCPPacket.hh:137
boost::uint16_t calcChecksum() const
calculate (pseudo-)header checksum
Definition: TCPPacket.cc:36
#define SENF_PARSER_FIELD(name, type)
Define normal parser field.
UInt16Parser urgentpointer() const
TCPPacketParser parser
typedef to the parser of TCP packet
Definition: TCPPacket.hh:139
#define SENF_PARSER_FINALIZE(name)
Generate parser control members.
ConcretePacket< TCPPacketType > TCPPacket
TCP packet typedef.
Definition: TCPPacket.hh:159
void dump(std::ostream &os, DirectoryNode &dir=root())
Protocol specific packet handle.
Definition: Packet.hh:87
senf::FlagParser<?> ackf() const
Helper base-class implementing the PacketType interface.
Definition: PacketType.hh:100
bool validateChecksum() const
validate header checksum
Definition: TCPPacket.hh:77
#define SENF_PARSER_INIT()
Define parser initialization routine.
senf::UIntFieldParser<?,?+4 > dataoffset() const
Parse a TCP packet.
Definition: TCPPacket.hh:36
#define SENF_PARSER_SKIP(skip)
Skip bytes.
TCP packet.
Definition: TCPPacket.hh:133
SENF_PACKET_PREVENT_TEMPLATE_INSTANTIATION(RadiotapPacket)
UInt16Parser destination() const
UInt16Parser checksum() const
senf::FlagParser<?> finf() const
Parser Base class.
Parse 32bit unsigned byte aligned integer.
Definition: IntParser.hh:310
#define SENF_PARSER_PRIVATE_BITFIELD(name, bits, type)
Define bit-field (private)
Parse 16bit unsigned byte aligned integer.
Definition: IntParser.hh:174
senf::FlagParser<?> pshf() const
UInt16Parser source() const
senf::FlagParser<?> urgf() const
UInt16Parser window() const