X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FUDPPacket.hh;h=dc82ea2ffa2acd0317f435f80cd29fabc0cb5118;hb=6a0836b7f462d3d77b79b35638cdbf4c9d4202fc;hp=5ea93db33ef6fd6dae0e2017a7ea56ee003d2d55;hpb=a4e052fb8832499ef5e3ae4e563ea01b834010c2;p=senf.git diff --git a/Packets/DefaultBundle/UDPPacket.hh b/Packets/DefaultBundle/UDPPacket.hh index 5ea93db..dc82ea2 100644 --- a/Packets/DefaultBundle/UDPPacket.hh +++ b/Packets/DefaultBundle/UDPPacket.hh @@ -1,9 +1,9 @@ // $Id$ // // Copyright (C) 2006 -// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS) -// Kompetenzzentrum fuer Satelitenkommunikation (SatCom) -// Stefan Bund +// Fraunhofer Institute for Open Communication Systems (FOKUS) +// Competence Center NETwork research (NET), St. Augustin, GERMANY +// Stefan Bund // // This program is free software; you can redistribute it and/or modify // it under the terms of the GNU General Public License as published by @@ -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//////////////////////////////////////// @@ -35,31 +38,25 @@ namespace senf { Parser implementing the UDP header. The fields implemented are: - \see UDPPacketType + \see UDPPacketType \n RFC 768 */ - struct Parse_UDP : public PacketParserBase + struct UDPPacketParser : public PacketParserBase { - typedef Parse_UInt16 Parse_16bit; - -# ifndef DOXYGEN +# include SENF_FIXED_PARSER() - SENF_PACKET_PARSER_INIT(Parse_UDP); + SENF_PARSER_FIELD( source, senf::UInt16Parser ); + SENF_PARSER_FIELD( destination, senf::UInt16Parser ); + SENF_PARSER_FIELD( length, senf::UInt16Parser ); + SENF_PARSER_FIELD( checksum, senf::UInt16Parser ); - 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(UDPPacketParser); -# 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 @@ -68,7 +65,11 @@ namespace senf { \ref UDPPacket \par Fields: - \ref Parse_UDP + \ref UDPPacketParser + + \par Finalize action: + Set \a length from payload size\n + Calculate \a checksum \ingroup protocolbundle_default */ @@ -76,19 +77,22 @@ namespace senf { : public PacketTypeBase, public PacketTypeMixin { +#ifndef DOXYGEN typedef PacketTypeMixin mixin; typedef ConcretePacket packet; - typedef Parse_UDP parser; - + typedef UDPPacketParser 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; }