Parser Base class. More...
#include <senf/Packets/PacketParser.hh>
Inherited by senf::ArrayValueParserBase< EUI64Parser, EUI64 >, senf::ArrayValueParserBase< INet4AddressParser, INet4Address >, senf::ArrayValueParserBase< INet6AddressParser, INet6Address >, senf::ArrayValueParserBase< MACAddressParser, MACAddress >, senf::ArrayParser< elements, ElementParser >, senf::ArrayValueParserBase< Parser, ValueType >, senf::BitsetParser< N, Endianness >, senf::DTCPHelloPacketParser, senf::DTCPIPv4AddressListParser, senf::DTCPIPv6AddressListParser, senf::EnumParser< EnumType, UnderlyingTypeParser >, senf::EthernetPacketParser, senf::EthOUIExtensionPacketParser, senf::EthVLanPacketParser, senf::FixedSizeStringParser< N >, senf::FlagParser< Bit >, senf::GREChecksumParser, senf::GREPacketParser, senf::ICMPv6EchoReplyParser, senf::ICMPv6EchoRequestParser, senf::ICMPv6ErrDestUnreachableParser, senf::ICMPv6ErrParamProblemParser, senf::ICMPv6ErrTimeExceededParser, senf::ICMPv6ErrTooBigParser, senf::ICMPv6PacketParser, senf::InformationElementsPacketParser, senf::Int16LSBParser, senf::Int16Parser, senf::Int24Parser, senf::Int32Parser, senf::Int64Parser, senf::Int8Parser, senf::IntFieldParser< Start, End >, senf::IPv4PacketParser, senf::IPv6DestinationOptionsPacketParser, senf::IPv6FragmentPacketParser, senf::IPv6HopByHopOptionsPacketParser, senf::IPv6OptionParser, senf::IPv6PacketParser, senf::IPv6RoutingPacketParser, senf::ListParser< ListPolicy >, senf::LlcSnapPacketParser, senf::MIHBaseTLVParser, senf::MIHGenericPayloadPacketParser, senf::MIHLengthParser, senf::MIHPacketParser, senf::MLDv2AddressRecordParser, senf::MLDv2ListenerQueryParser, senf::MLDv2ListenerReportParser, senf::MPERealTimeParametersParser, senf::MPESectionParser, senf::NDPNeighborAdvertisementParser, senf::NDPNeighborSolicitationParser, senf::NDPOptionParser, senf::NDPRedirectParser, senf::NDPRouterAdvertisementParser, senf::NDPRouterSolicitationParser, senf::PPPoEPacketParser, senf::RadiotapPacket_AMPDUStatusParser, senf::RadiotapPacket_ChannelOptionsParser, senf::RadiotapPacket_FlagsParser, senf::RadiotapPacket_FrameTypeParser, senf::RadiotapPacket_HeaderParser, senf::RadiotapPacket_MCSParser, senf::RadiotapPacket_RxFlagsParser, senf::RadiotapPacket_TxFlagsParser, senf::RadiotapPacket_VHTParser, senf::RTPPacketParser, senf::SNDUPacketParser, senf::StringParser< LengthParser >, senf::TCPPacketParser, senf::TransportPacketParser, senf::UDPPacketParser, senf::UInt16LSBParser, senf::UInt16Parser, senf::UInt24Parser, senf::UInt32LSBParser, senf::UInt32Parser, senf::UInt64LSBParser, senf::UInt64Parser, senf::UInt8Parser, senf::UIntFieldParser< Start, End >, senf::VariantParser< AuxPolicy, Parsers >, senf::VectorParser< ElementParser, AuxPolicy >, senf::VoidPacketParser, senf::WLANAMPDUParametersParser, senf::WLANAntennaSelectionCapabilityParser, senf::WLANBeaconPacketParser, senf::WLANHTCapabilitiesInfoFieldParser, senf::WLANHTExtendedCapabilitiesParser, senf::WLANHTOperationInfoFieldParser, senf::WLANInfoElementParser, senf::WLANPacket_MeshControlFieldParser, senf::WLANPacketParser, senf::WLANSupportedMCSSetParser, senf::WLANSupportedVHTMCSSetParser, senf::WLANTxBeamformingCapabilitiesParser, senf::WLANVHTCapabilitiesInfoFieldParser, senf::WLANVHTHighestSupportedDataRateParser, senf::WLANVHTMCSMapParser, and senf::WLANVHTOperationInfoFieldParser.
Public Types | |
typedef detail::packet::iterator | data_iterator |
Raw data iterator type. More... | |
typedef detail::packet::size_type | size_type |
Unsigned integral type. More... | |
typedef detail::packet::difference_type | difference_type |
Signed integral type. More... | |
typedef detail::packet::byte | byte |
Unsigned 8bit value, the raw value type. More... | |
typedef PacketData * | state_type |
Type of the 'state' parameter. More... | |
typedef PacketParserBase | parser_base_type |
Base type of the next parser. More... | |
Public Member Functions | |
data_iterator | i () const |
Return beginning of data to parse. More... | |
data_iterator | i (size_type offset) const |
Return iterator offset bytes from the start. More... | |
state_type | state () const |
Return state of this parser. More... | |
PacketData & | data () const |
Access the packets raw data container. More... | |
void | init () const |
Default implementation. More... | |
Protected Member Functions | |
ParserProtector | protect () const |
PacketParserBase (data_iterator i, state_type s) | |
Standard constructor. More... | |
PacketParserBase (data_iterator i, state_type s, size_type size) | |
Size checking constructor. More... | |
bool | check (size_type size) const |
Check size of data container. More... | |
void | validate (size_type size) const |
Validate size of data container. More... | |
template<class Parser > | |
Parser | parse (data_iterator i) const |
Create sub-parser. More... | |
template<class Parser , class Arg > | |
Parser | parse (Arg const &arg, data_iterator i) const |
Create sub-parser. More... | |
template<class Parser > | |
Parser | parse (size_type n) const |
Create sub-parser. More... | |
template<class Parser , class Arg > | |
Parser | parse (Arg const &arg, size_type n) const |
Create sub-parser. More... | |
void | defaultInit () const |
Default implementation. More... | |
Packet | packet () const |
Get packet this parser is parsing from. More... | |
void | resize (size_type oldSize, size_type newSize) |
Resize data container. More... | |
Parser Base class.
Parsers come in two flavors: fixed and dynamically sized parsers. A fixed size parser has a constant size, it will always parse a fixed number of bytes. The low-level 'final' parsers (like the integer parsers) are fixed size parsers as are composite parsers built up only of fixed-size fields.
A dynamically sized parser on the other hand infers it's size from the contents of the data parsed. Any parser containing at least one dynamically sized sub-parser will itself be dynamically sized.
Both kinds of parser need to derive from PacketParserBase and implement several required members. Which members to implement depends on the parsers flavor. There are two ways how to do this.
This documentation is about the manual implementation. You should nevertheless read through this to understand, what above macros are doing.
The following example documents the interface (which must be) provided by a parser:
You should never call the \c bytes() member of a parser directly. Instead you should use the freestanding senf::bytes() function. This function will return the correct size irrespective of the parsers flavor. You may access \c fixed_bytes directly, however be aware that this will restrict your code to fixed size parsers (which depending on the circumstances may be exactly what you want). In the same way, don't access \c init_bytes directly, always use the senf::init_bytes meta-function class which correctly supports fixed size parsers.
Definition at line 228 of file PacketParser.hh.
Unsigned 8bit value, the raw value type.
Definition at line 237 of file PacketParser.hh.
Raw data iterator type.
Definition at line 234 of file PacketParser.hh.
Signed integral type.
Definition at line 236 of file PacketParser.hh.
Base type of the next parser.
Definition at line 239 of file PacketParser.hh.
Unsigned integral type.
Definition at line 235 of file PacketParser.hh.
Type of the 'state' parameter.
Definition at line 238 of file PacketParser.hh.
|
protected |
Standard constructor.
This is the constructor used by most parsers. The parameters are just forwarded from the derived classes constructor parameters.
|
protected |
Size checking constructor.
In addition to the standard constructor, this constructor will validate, that there is enough data in the raw data container to parse size bytes after i.
This constructor is called by all 'final' parsers (e.g. the integer parsers) and only by those parsers. Most parsers do not check the validity of the iterator, this is delayed until the very last parser. This allows to partial parse truncated packets.
TruncatedPacketException | if the raw data container does not hold at least size bytes beginning at i. |
|
protected |
Check size of data container.
true
, if the data container holds at least size beginning at i(), false
otherwise. PacketData& senf::PacketParserBase::data | ( | ) | const |
Access the packets raw data container.
This member will return the raw data container holding the data which is parsed by this
parser.
|
protected |
Default implementation.
This is just an empty default implementation. Re-implement this member in your own parsers if needed.
data_iterator senf::PacketParserBase::i | ( | ) | const |
Return beginning of data to parse.
The parser is expected to interpret the data beginning here. The size of the interpreted is given by senf::bytes(
parser instance)
.
data_iterator senf::PacketParserBase::i | ( | size_type | offset | ) | const |
Return iterator offset bytes from the start.
The return value is the same as i() + offset. However, the parser checks, that the iterator is still within range of the raw data container. Otherwise a TruncatedPacketException is thrown.
TruncatedPacketException | if the raw data container does not hold at least offset bytes starting at i(). |
void senf::PacketParserBase::init | ( | ) | const |
Default implementation.
This is just an empty default implementation. Re-implement this member in your own parsers if needed.
|
protected |
Get packet this parser is parsing from.
|
protected |
Create sub-parser.
Creates a new instance of Parser to parse data beginning at i. Automatically passes state() to the new parser.
|
protected |
Create sub-parser.
This is like parse(data_iterator), however it passes the extra argument arg to the Parser constructor.
|
protected |
|
protected |
Create sub-parser.
This is like parse(size_type), however it passes the extra argument arg to the Parser constructor.
|
protected |
Resize data container.
This command will erase or insert bytes from/into the data container at the end of the parser (at i() + newSize). If oldSize is > newSize, bytes will be removed, otherwise bytes will be inserted.
Definition at line 26 of file PacketParser.cc.
state_type senf::PacketParserBase::state | ( | ) | const |
Return state of this parser.
The value returned should be interpreted as an opaque value provided just to be forwarded to other parsers.
|
protected |
Validate size of data container.
TruncatedPacketException | if the raw data container does not hold at least size bytes beginning at i(). |