switch to new MPL based Fraunhofer FOKUS Public License
[senf.git] / senf / Packets / DefaultBundle / IPv4Packet.hh
index 0cdae50..2fc68a4 100644 (file)
@@ -2,23 +2,28 @@
 //
 // Copyright (C) 2006
 // 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
-// the Free Software Foundation; either version 2 of the License, or
-// (at your option) any later version.
+// The contents of this file are subject to the Fraunhofer FOKUS Public License
+// Version 1.0 (the "License"); you may not use this file except in compliance
+// with the License. You may obtain a copy of the License at 
+// http://senf.berlios.de/license.html
 //
-// This program is distributed in the hope that it will be useful,
-// but WITHOUT ANY WARRANTY; without even the implied warranty of
-// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-// GNU General Public License for more details.
+// The Fraunhofer FOKUS Public License Version 1.0 is based on, 
+// but modifies the Mozilla Public License Version 1.1.
+// See the full license text for the amendments.
 //
-// You should have received a copy of the GNU General Public License
-// along with this program; if not, write to the
-// Free Software Foundation, Inc.,
-// 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+// Software distributed under the License is distributed on an "AS IS" basis, 
+// WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License 
+// for the specific language governing rights and limitations under the License.
+//
+// The Original Code is Fraunhofer FOKUS code.
+//
+// The Initial Developer of the Original Code is Fraunhofer-Gesellschaft e.V. 
+// (registered association), Hansastraße 27 c, 80686 Munich, Germany.
+// All Rights Reserved.
+//
+// Contributor(s):
+//   Stefan Bund <g0dil@berlios.de>
 
 /** \file
     \brief IPv4Packet public header */
 #define HH_SENF_Packets_DefaultBundle_IPv4Packet_ 1
 
 // Custom includes
-#include "../../Socket/Protocols/INet/INet4Address.hh"
-#include "../../Packets/Packets.hh"
+#include <senf/Socket/Protocols/INet/INet4Address.hh>
+#include <senf/Packets/Packets.hh>
 
 //#include "IPv4Packet.mpp"
-///////////////////////////////hh.p////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 
 namespace senf {
 
@@ -39,29 +44,23 @@ namespace senf {
 
         \see INet4Address
      */
-    struct INet4AddressParser : public PacketParserBase
+    struct INet4AddressParser
+        : public ValueParserBase<INet4AddressParser, INet4Address, 4u>
     {
-        INet4AddressParser(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
-
-        ///////////////////////////////////////////////////////////////////////////
-
-        typedef INet4Address value_type;
-        static const size_type fixed_bytes = 4u;
+        INet4AddressParser(data_iterator i, state_type s) : Base(i,s) {}
 
         value_type value() const { return value_type::from_data(i()); }
         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
-        operator value_type() const { return value(); }
-        byte & operator[](size_type index) const { return *boost::next(i(),index); }
-        INet4AddressParser const & operator= (value_type const & other) 
-            { value(other); return *this; }
+
+        using Base::operator=;
     };
 
     /** \brief Parse an IPv4 packet
 
         Parser implementing the IPv4 header.
-        
+
         \image html IPv4Packet.png
-                
+
         \see IPv4PacketType \n
             <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
 
@@ -96,7 +95,7 @@ namespace senf {
         }
 
         SENF_PARSER_FINALIZE(IPv4PacketParser);
-        
+
         boost::uint16_t calcChecksum() const; ///< calculate header checksum
                                               /**< calculate and return the checksum of the header
                                                    \see \ref senf::IpChecksum */
@@ -104,8 +103,8 @@ namespace senf {
         bool validateChecksum() const {
             return checksum() == calcChecksum();
         }                               ///< validate header checksum
-                                        /**< return \c true if the \ref checksum() "checksum" 
-                                             field is equal to the \ref calcChecksum() 
+                                        /**< return \c true if the \ref checksum() "checksum"
+                                             field is equal to the \ref calcChecksum()
                                              "calculated checksum" */
     };
 
@@ -117,11 +116,11 @@ namespace senf {
             PacketRegistry
      */
     struct IpTypes {
-        typedef boost::uint16_t key_t;
+        typedef boost::uint8_t key_t;
     };
 
     /** \brief IPv4 packet
-        
+
         \par Packet type (typedef):
             \ref IPv4Packet
 
@@ -139,7 +138,7 @@ namespace senf {
             <td>\ref IPv4PacketParser::version() "Version"</td>
             <td>\ref IPv4PacketParser::ihl() "IHL"</td>
             <td colspan="2">\ref IPv4PacketParser::tos() "TOS"</td>
-            <td colspan="8">\ref IPv4PacketParser::length() "Length"</td> 
+            <td colspan="8">\ref IPv4PacketParser::length() "Length"</td>
           </tr><tr>
             <td colspan="4">\ref IPv4PacketParser::identifier() "Identifier"</td>
             <td>R</td>
@@ -162,7 +161,7 @@ namespace senf {
 
         \par Finalize action:
             \copydetails finalize()
+
         \ingroup protocolbundle_default
      */
     struct IPv4PacketType
@@ -180,27 +179,29 @@ namespace senf {
         using mixin::initSize;
         using mixin::init;
 
-        static key_t nextPacketKey(packet p) 
+        static key_t nextPacketKey(packet p)
             { return p->protocol(); }
-        
+
         /** \brief Dump given IPv4Packet in readable form to given output stream */
-        static void dump(packet p, std::ostream & os); 
-        
+        static void dump(packet p, std::ostream & os);
+
         static void finalize(packet p); ///< Finalize packet.
-                                        /**< \li set \ref IPv4PacketParser::length() "length" 
+                                        /**< \li set \ref IPv4PacketParser::length() "length"
                                                from payload size
-                                             \li set \ref IPv4PacketParser::protocol() "protocol" 
+                                             \li set \ref IPv4PacketParser::protocol() "protocol"
                                                from type of next packet if found in \ref IpTypes
-                                             \li calculate and set 
+                                             \li calculate and set
                                                \ref IPv4PacketParser::checksum() "checksum" */
     };
 
-    /** \brief IPv4 packet typedef */
+    /** \brief IPv4 packet typedef
+        \ingroup protocolbundle_default
+     */
     typedef ConcretePacket<IPv4PacketType> IPv4Packet;
 }
 
 
-///////////////////////////////hh.e////////////////////////////////////////
+//-/////////////////////////////////////////////////////////////////////////////////////////////////
 //#include "IPv4Packet.cci"
 //#include "IPv4Packet.ct"
 //#include "IPv4Packet.cti"