X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FUDPPacket.hh;h=dc82ea2ffa2acd0317f435f80cd29fabc0cb5118;hb=6a0836b7f462d3d77b79b35638cdbf4c9d4202fc;hp=bd0fc5757b2a715ebc551ed7c60f198620afe309;hpb=9357448dc66bc9acfd3bd8db423deb75bcd6a2c4;p=senf.git diff --git a/Packets/DefaultBundle/UDPPacket.hh b/Packets/DefaultBundle/UDPPacket.hh index bd0fc57..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,73 +20,88 @@ // 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/Packet.hh" -#include "Packets/ParseInt.hh" -#include "Packets/ParseArray.hh" -#include "Packets/PacketRegistry.hh" +#include "../../Packets/Packets.hh" //#include "UDPPacket.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { - // See RFC768 - template - struct Parse_UDP : public ParserBase - { - template - struct rebind { typedef Parse_UDP parser; }; - typedef Iterator byte_iterator; + /** \brief Parse a UDP packet - Parse_UDP() {} - Parse_UDP(Iterator const & i) : ParserBase(i) {} + Parser implementing the UDP header. The fields implemented are: - static unsigned bytes() { return 8; } + \see UDPPacketType \n + RFC 768 + */ + struct UDPPacketParser : public PacketParserBase + { +# include SENF_FIXED_PARSER() - /////////////////////////////////////////////////////////////////////////// + SENF_PARSER_FIELD( source, senf::UInt16Parser ); + SENF_PARSER_FIELD( destination, senf::UInt16Parser ); + SENF_PARSER_FIELD( length, senf::UInt16Parser ); + SENF_PARSER_FIELD( checksum, senf::UInt16Parser ); - typedef Parse_UInt16 < Iterator > Parse_16bit; + SENF_PARSER_FINALIZE(UDPPacketParser); - Parse_16bit source() const { return Parse_16bit (this->i() ); } - Parse_16bit destination() const { return Parse_16bit (this->i() + 2 ); } - Parse_16bit length() const { return Parse_16bit (this->i() + 4 ); } - Parse_16bit crc() const { return Parse_16bit (this->i() + 6 ); } + boost::uint16_t calcChecksum() const; + bool validateChecksum() const { + return checksum() == 0u || checksum() == calcChecksum(); + } }; - class UDPPacket - : public Packet, - public Parse_UDP - { - public: - /////////////////////////////////////////////////////////////////////////// - // Types + /** \brief UDP packet + + \par Packet type (typedef): + \ref UDPPacket - typedef ptr_t::ptr ptr; + \par Fields: + \ref UDPPacketParser - /////////////////////////////////////////////////////////////////////////// + \par Finalize action: + Set \a length from payload size\n + Calculate \a checksum - private: - template - UDPPacket(Arg const & arg); + \ingroup protocolbundle_default + */ + struct UDPPacketType + : public PacketTypeBase, + public PacketTypeMixin + { +#ifndef DOXYGEN + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; + typedef UDPPacketParser parser; +#endif + using mixin::nextPacketRange; + using mixin::initSize; + using mixin::init; - virtual void v_nextInterpreter() const; - virtual void v_finalize(); - virtual void v_dump(std::ostream & os) const; + static void dump(packet p, std::ostream & os); - friend class Packet; + static void finalize(packet p); }; + + /** \brief UDP packet typedef */ + typedef ConcretePacket UDPPacket; } ///////////////////////////////hh.e//////////////////////////////////////// +#endif +#ifndef SENF_PACKETS_DECL_ONLY //#include UDPPacket.cci" //#include "UDPPacket.ct" -#include "UDPPacket.cti" +//#include "UDPPacket.cti" #endif @@ -96,4 +111,6 @@ namespace senf { // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: