X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FUDPPacket.hh;h=2c662d336373d34d91f106b4eabf3cd2e48eb162;hb=6a3a31fb7b2d2a5e8ae6d67d50797700274fb34e;hp=5ea93db33ef6fd6dae0e2017a7ea56ee003d2d55;hpb=a4e052fb8832499ef5e3ae4e563ea01b834010c2;p=senf.git diff --git a/Packets/DefaultBundle/UDPPacket.hh b/Packets/DefaultBundle/UDPPacket.hh index 5ea93db..2c662d3 100644 --- a/Packets/DefaultBundle/UDPPacket.hh +++ b/Packets/DefaultBundle/UDPPacket.hh @@ -20,11 +20,14 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. +/** \file + \brief UDPPacket public header */ + #ifndef HH_UDPPacket_ #define HH_UDPPacket_ 1 // Custom includes -#include "Packets/Packets.hh" +#include "../../Packets/Packets.hh" //#include "UDPPacket.mpp" ///////////////////////////////hh.p//////////////////////////////////////// @@ -40,26 +43,20 @@ namespace senf { */ struct Parse_UDP : public PacketParserBase { - typedef Parse_UInt16 Parse_16bit; - -# ifndef DOXYGEN +# include SENF_FIXED_PARSER() - SENF_PACKET_PARSER_INIT(Parse_UDP); + SENF_PARSER_FIELD( source, senf::Parse_UInt16 ); + SENF_PARSER_FIELD( destination, senf::Parse_UInt16 ); + SENF_PARSER_FIELD( length, senf::Parse_UInt16 ); + SENF_PARSER_FIELD( checksum, senf::Parse_UInt16 ); - SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS( - ((Field)( source, Parse_16bit )) - ((Field)( destination, Parse_16bit )) - ((Field)( length, Parse_16bit )) - ((Field)( crc, Parse_16bit )) ); + SENF_PARSER_FINALIZE(Parse_UDP); -# else + boost::uint16_t calcChecksum() const; - Parse_16bit source(); - Parse_16bit destination(); - Parse_16bit length(); - Parse_16bit crc(); - -# endif + bool validateChecksum() const { + return checksum() == 0u || checksum() == calcChecksum(); + } }; /** \brief UDP packet @@ -70,25 +67,32 @@ namespace senf { \par Fields: \ref Parse_UDP + \par Finalize action: + Set \a length from payload size\n + Calculate \a checksum + \ingroup protocolbundle_default */ struct UDPPacketType : public PacketTypeBase, public PacketTypeMixin { +#ifndef DOXYGEN typedef PacketTypeMixin mixin; typedef ConcretePacket packet; typedef Parse_UDP parser; - +#endif using mixin::nextPacketRange; using mixin::initSize; using mixin::init; static void dump(packet p, std::ostream & os); + + static void finalize(packet p); }; /** \brief UDP packet typedef */ - typedef UDPPacketType::packet UDPPacket; + typedef ConcretePacket UDPPacket; }