->
operator of the packet. Possibilities here are e.g. checksum calculation and validation, packet validation as a whole and so on.
Defining a protocol parser is quite simple:
struct EthernetPacketParser : public PacketParserBase { # include SENF_FIXED_PARSER() SENF_PARSER_FIELD( destination, MACAddressParser ); SENF_PARSER_FIELD( source, MACAddressParser ); SENF_PARSER_FIELD( type_length, UInt16Parser ); SENF_PARSER_FINALIZE(EthernetPacketParser); };
There are a lot of other possibilities to define fields. See Helper macros for defining new packet parsers for a detailed description of the macro language which is used to define composite parsers.
struct EthernetPacketType : public PacketTypeBase, public PacketTypeMixin<EthernetPacketType, EtherTypes> { typedef PacketTypeMixin<EthernetPacketType, EtherTypes> mixin; typedef ConcretePacket<EthernetPacketType> packet; typedef EthernetPacketParser parser; using mixin::nextPacketRange; using mixin::initSize; using mixin::init; static factory_t nextPacketType(packet p); static void dump(packet p, std::ostream & os); static void finalize(packet p); }; typedef EthernetPacketType::packet EthernetPacket;
The definition of senf::EthernetPacket is quite straight forward. This template works for most simple packet types.