Small documentation updates
[senf.git] / Packets / DefaultBundle / UDPPacket.hh
index 5ea93db..9e0177b 100644 (file)
 // 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////////////////////////////////////////
@@ -40,26 +43,20 @@ namespace senf {
      */
     struct Parse_UDP : public PacketParserBase
     {
-        typedef Parse_UInt16 Parse_16bit;
-
-#       ifndef DOXYGEN
-
-        SENF_PACKET_PARSER_INIT(Parse_UDP);
+#       include SENF_FIXED_PARSER()
 
-        SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
-            ((Field)( source,      Parse_16bit ))
-            ((Field)( destination, Parse_16bit ))
-            ((Field)( length,      Parse_16bit ))
-            ((Field)( crc,         Parse_16bit )) );
+        SENF_PARSER_FIELD( source,      senf::Parse_UInt16 );
+        SENF_PARSER_FIELD( destination, senf::Parse_UInt16 );
+        SENF_PARSER_FIELD( length,      senf::Parse_UInt16 );
+        SENF_PARSER_FIELD( checksum,    senf::Parse_UInt16 );
 
-#       else
+        SENF_PARSER_FINALIZE(Parse_UDP);
 
-        Parse_16bit source();
-        Parse_16bit destination();
-        Parse_16bit length();
-        Parse_16bit crc();
+        boost::uint16_t calcChecksum() const;
 
-#       endif
+        bool validateChecksum() const {
+            return checksum() == 0u || checksum() == calcChecksum();
+        }
     };
 
     /** \brief UDP packet
@@ -70,6 +67,10 @@ namespace senf {
         \par Fields:
             \ref Parse_UDP
 
+        \par Finalize action:
+            Set \a length from payload size\n
+            Calculate \a checksum
+
         \ingroup protocolbundle_default
      */
     struct UDPPacketType
@@ -85,6 +86,8 @@ namespace senf {
         using mixin::init;
 
         static void dump(packet p, std::ostream & os);
+
+        static void finalize(packet p);
     };
 
     /** \brief UDP packet typedef */