// $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
\see UDPPacketType
<a href="http://tools.ietf.org/html/rfc768">RFC 768</a>
*/
- struct Parse_UDP : public PacketParserBase
+ struct UDPPacketParser : public PacketParserBase
{
- typedef Parse_UInt16 Parse_16bit;
+# include SENF_FIXED_PARSER()
-# ifndef DOXYGEN
+ 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_INIT(Parse_UDP);
+ SENF_PARSER_FINALIZE(UDPPacketParser);
- SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
- ((Field)( source, Parse_16bit ))
- ((Field)( destination, Parse_16bit ))
- ((Field)( length, Parse_16bit ))
- ((Field)( crc, Parse_16bit )) );
+ boost::uint16_t calcChecksum() const;
-# else
-
- Parse_16bit source();
- Parse_16bit destination();
- Parse_16bit length();
- Parse_16bit crc();
-
-# endif
+ bool validateChecksum() const {
+ return checksum() == 0u || checksum() == calcChecksum();
+ }
};
/** \brief UDP packet
\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
*/
: public PacketTypeBase,
public PacketTypeMixin<UDPPacketType>
{
+#ifndef DOXYGEN
typedef PacketTypeMixin<UDPPacketType> mixin;
typedef ConcretePacket<UDPPacketType> 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<UDPPacketType> UDPPacket;
}