// $Id$
//
// Copyright (C) 2006
-// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
-// Kompetenzzentrum fuer Satelitenkommunikation (SatCom)
-// Stefan Bund <stefan.bund@fokus.fraunhofer.de>
+// Fraunhofer Institute for Open Communication Systems (FOKUS)
+// Competence Center NETwork research (NET), St. Augustin, GERMANY
+// Stefan Bund <g0dil@berlios.de>
//
// 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
// 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 <class Iterator=nil, class IPacket=nil>
- struct Parse_UDP : public ParserBase<Iterator,IPacket>
- {
- template <class I, class P=nil>
- struct rebind { typedef Parse_UDP<I,P> parser; };
- typedef Iterator byte_iterator;
+ /** \brief Parse a UDP packet
- Parse_UDP() {}
- Parse_UDP(Iterator const & i) : ParserBase<Iterator,IPacket>(i) {}
+ Parser implementing the UDP header. The fields implemented are:
- static unsigned bytes() { return 8; }
+ \see UDPPacketType
+ <a href="http://tools.ietf.org/html/rfc768">RFC 768</a>
+ */
+ 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<Packet::iterator, UDPPacket>
- {
- public:
- ///////////////////////////////////////////////////////////////////////////
- // Types
+ /** \brief UDP packet
+
+ \par Packet type (typedef):
+ \ref UDPPacket
- typedef ptr_t<UDPPacket>::ptr ptr;
+ \par Fields:
+ \ref UDPPacketParser
- ///////////////////////////////////////////////////////////////////////////
+ \par Finalize action:
+ Set \a length from payload size\n
+ Calculate \a checksum
- private:
- template <class Arg>
- UDPPacket(Arg const & arg);
+ \ingroup protocolbundle_default
+ */
+ struct UDPPacketType
+ : public PacketTypeBase,
+ public PacketTypeMixin<UDPPacketType>
+ {
+#ifndef DOXYGEN
+ typedef PacketTypeMixin<UDPPacketType> mixin;
+ typedef ConcretePacket<UDPPacketType> 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<UDPPacketType> UDPPacket;
}
///////////////////////////////hh.e////////////////////////////////////////
+#endif
+#ifndef SENF_PACKETS_DECL_ONLY
//#include UDPPacket.cci"
//#include "UDPPacket.ct"
-#include "UDPPacket.cti"
+//#include "UDPPacket.cti"
#endif
\f
// c-file-style: "senf"
// indent-tabs-mode: nil
// ispell-local-dictionary: "american"
+// compile-command: "scons -u test"
+// comment-column: 40
// End: