X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FUDPPacket.hh;h=456b3259b2a8f0265168be192ba87a73615bb3fc;hb=8674fb1d184e7d620eb7c604957b5b4203df37a6;hp=58b945587adfeb08c0366cf038ea5cc1d15020c7;hpb=31d85cd6b8e03c5ecc924ca8892906be1bab702f;p=senf.git diff --git a/Packets/DefaultBundle/UDPPacket.hh b/Packets/DefaultBundle/UDPPacket.hh index 58b9455..456b325 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,108 @@ // Free Software Foundation, Inc., // 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. -#ifndef HH_UDPPacket_ -#define HH_UDPPacket_ 1 +/** \file + \brief UDPPacket public header */ + +#ifndef HH_SENF_Packets_DefaultBundle_UDPPacket_ +#define HH_SENF_Packets_DefaultBundle_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; - - Parse_UDP() {} - Parse_UDP(Iterator const & i) : ParserBase(i) {} - - static unsigned bytes() { return 8; } - - /////////////////////////////////////////////////////////////////////////// - - typedef Parse_UInt16 < Iterator > Parse_16bit; - - 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 ); } + /** \brief Parse a UDP packet + Parser implementing the UDP header. The fields implemented are: + \image html UDPPacket.png + + \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 ); + + SENF_PARSER_FINALIZE(UDPPacketParser); + + boost::uint16_t calcChecksum() const; ///< calculate (pseudo-)header checksum + /**< calculate and return the checksum of the + (pseudo-)header \see \ref senf::IpChecksum */ + bool validateChecksum() const { + return checksum() == 0u || checksum() == calcChecksum(); + } ///< validate header checksum + /**< return \c true if the \ref checksum() "checksum" + field is equal to the \ref calcChecksum() "calculated checksum" */ }; - class UDPPacket - : public Packet, - public Parse_UDP + /** \brief UDP packet + + \par Packet type (typedef): + \ref UDPPacket + + \par Fields: + \ref UDPPacketParser + + + + + + + + + + + + +
0 8 1624 31
\ref UDPPacketParser::source() "Source Port"\ref UDPPacketParser::destination() "Destination Port"
\ref UDPPacketParser::length() "Length"\ref UDPPacketParser::checksum() "Checksum"
+ + \par Finalize action: + \copydetails finalize() + + \ingroup protocolbundle_default + */ + struct UDPPacketType + : public PacketTypeBase, + public PacketTypeMixin { - public: - /////////////////////////////////////////////////////////////////////////// - // Types - - typedef ptr_t::ptr ptr; - - /////////////////////////////////////////////////////////////////////////// - - private: - template - UDPPacket(Arg const & arg); - - virtual void v_nextInterpreter() const; - virtual void v_finalize(); - virtual void v_dump(std::ostream & os) const; - - friend class Packet; +#ifndef DOXYGEN + typedef PacketTypeMixin mixin; +#endif + typedef ConcretePacket packet; ///< UDP packet typedef + typedef UDPPacketParser parser; ///< typedef to the parser of UDP packet + + using mixin::nextPacketRange; + using mixin::initSize; + using mixin::init; + + /** \brief Dump given UDPPacket in readable form to given output stream */ + static void dump(packet p, std::ostream & os); + + static void finalize(packet p); ///< Finalize packet. + /**< \li set \ref UDPPacketParser::length() "length" from + payload size + \li calculate and set \ref UDPPacketParser::checksum() + "checksum" */ }; + + /** \brief UDP packet typedef */ + typedef ConcretePacket UDPPacket; } ///////////////////////////////hh.e//////////////////////////////////////// -//#include UDPPacket.cci" +//#include "UDPPacket.cci" //#include "UDPPacket.ct" -#include "UDPPacket.cti" +//#include "UDPPacket.cti" #endif @@ -97,4 +132,5 @@ namespace senf { // indent-tabs-mode: nil // ispell-local-dictionary: "american" // compile-command: "scons -u test" +// comment-column: 40 // End: