IPv4Packet.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_IPv4Packet_
18 #define HH_SENF_Packets_DefaultBundle_IPv4Packet_ 1
19 
20 // Custom includes
22 #include <senf/Packets/Packets.hh>
23 #include "Registries.hh"
24 
25 //-/////////////////////////////////////////////////////////////////////////////////////////////////
26 
27 namespace senf {
28 
34  : public ArrayValueParserBase<INet4AddressParser, INet4Address>
35  {
37 
38  using Base::operator=;
39  };
40 
53  {
54 # include SENF_FIXED_PARSER()
55 
56  SENF_PARSER_BITFIELD( version, 4, unsigned );
57  SENF_PARSER_BITFIELD( ihl, 4, unsigned );
58 
59  // Originally defined as the Type of service (TOS), now DiffServ
60  SENF_PARSER_BITFIELD( dscp, 6, unsigned );
61  SENF_PARSER_BITFIELD( ecn, 2, unsigned );
62 
65 
66  SENF_PARSER_PRIVATE_BITFIELD( reserved, 1, bool );
67  SENF_PARSER_BITFIELD ( df, 1, bool );
68  SENF_PARSER_BITFIELD ( mf, 1, bool );
69  SENF_PARSER_BITFIELD ( frag, 13, unsigned );
70 
76 
78 
80  version() = 4;
81  // We don't support option headers at the moment ...
82  ihl() = 5;
83  }
84 
85  boost::uint16_t calcChecksum() const;
86 
89  bool validateChecksum() const {
90  return checksum() == calcChecksum();
91  }
92 
95  };
96 
97 
144  : public PacketTypeBase,
145  public PacketTypeMixin<IPv4PacketType, IPTypes>
146  {
150 
151  using mixin::nextPacketRange;
152  using mixin::nextPacketType;
153  using mixin::initSize;
154  using mixin::init;
155 
156  static key_t nextPacketKey(packet p)
157  { return p->protocol(); }
158 
160  static void dump(packet p, std::ostream & os);
161 
162  static void finalize(packet p);
163 
170  static const EtherTypes::key_t etherType = 0x0800;
171  };
172 
178 }
179 
180 
181 //-/////////////////////////////////////////////////////////////////////////////////////////////////
182 //#include "IPv4Packet.cci"
183 //#include "IPv4Packet.ct"
184 //#include "IPv4Packet.cti"
185 #endif
186 
187 
188 // Local Variables:
189 // mode: c++
190 // fill-column: 100
191 // c-file-style: "senf"
192 // indent-tabs-mode: nil
193 // ispell-local-dictionary: "american"
194 // compile-command: "scons -u test"
195 // comment-column: 40
196 // End:
IPv4PacketParser parser
typedef to the parser of IPv4 packet
Definition: IPv4Packet.hh:149
#define SENF_PARSER_BITFIELD(name, bits, type)
Define bit-field.
Mixin to provide standard implementations for nextPacketRange and nextPacketType. ...
Definition: PacketType.hh:300
Parse 8bit unsigned byte aligned integer.
Definition: IntParser.hh:91
Packets public header.
DefaultBundle packet registries public header.
#define SENF_PARSER_FIELD(name, type)
Define normal parser field.
IPv4 packet.
Definition: IPv4Packet.hh:143
PacketTypeMixin< IPv4PacketType, IPTypes > mixin
Definition: IPv4Packet.hh:147
#define SENF_PARSER_FINALIZE(name)
Generate parser control members.
void dump(std::ostream &os, DirectoryNode &dir=root())
Protocol specific packet handle.
Definition: Packet.hh:87
Helper base-class implementing the PacketType interface.
Definition: PacketType.hh:100
bool validateChecksum() const
validate header checksum
Definition: IPv4Packet.hh:89
Packet data STL-sequence view.
Definition: PacketData.hh:61
#define SENF_PARSER_INIT()
Define parser initialization routine.
data_iterator i() const
Return beginning of data to parse.
ConcretePacket< IPv4PacketType > packet
IPv4 packet typedef.
Definition: IPv4Packet.hh:148
SENF_PACKET_PREVENT_TEMPLATE_INSTANTIATION(RadiotapPacket)
Parser Base class.
INet4AddressParser(data_iterator i, state_type s)
Definition: IPv4Packet.hh:36
Parse an IPv4 packet.
Definition: IPv4Packet.hh:52
#define SENF_PARSER_PRIVATE_BITFIELD(name, bits, type)
Define bit-field (private)
Parse 16bit unsigned byte aligned integer.
Definition: IntParser.hh:174
static key_t nextPacketKey(packet p)
Definition: IPv4Packet.hh:156
boost::uint16_t key_t
Definition: Registries.hh:35
Parse in IPv4 address.
Definition: IPv4Packet.hh:33
detail::packet::iterator data_iterator
Raw data iterator type.
ConcretePacket< IPv4PacketType > IPv4Packet
IPv4 packet typedef.
Definition: IPv4Packet.hh:176