-// $Id: IpV4Packet.hh 307 2007-07-14 21:31:12Z g0dil $
+// $Id$
//
// Copyright (C) 2006
// Fraunhofer Institut fuer offene Kommunikationssysteme (FOKUS)
// Free Software Foundation, Inc.,
// 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+/** \file
+ \brief IpV4Packet public header */
+
#ifndef HH_IpV4Packet_
#define HH_IpV4Packet_ 1
// Custom includes
-#include "Packets/PacketType.hh"
-#include "Packets/ParseInt.hh"
-#include "Packets/PacketRegistry.hh"
-#include "Packets/PacketParser.hh"
+#include "../../Socket/Protocols/INet/INet4Address.hh"
+#include "../../Packets/Packets.hh"
//#include "IpV4Packet.mpp"
///////////////////////////////hh.p////////////////////////////////////////
namespace senf {
- ///\addtogroup protocolbundle_default
- ///@{
+ /** \brief Parse in IpV4 address
- struct Parse_IpV4 : public PacketParserBase
+ \see INet4Address
+ */
+ struct Parse_INet4Address : public PacketParserBase
{
- SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
+ Parse_INet4Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {}
///////////////////////////////////////////////////////////////////////////
+ typedef INet4Address value_type;
+ static const size_type fixed_bytes = 4u;
+
+ 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() { return value(); }
+ byte & operator[](size_type index) { return *boost::next(i(),index); }
+ Parse_INet4Address const & operator= (value_type const & other)
+ { value(other); return *this; }
+ };
+
+ /** \brief Parse an IpV4 packet
+
+ Parser implementing the IpV4 header. The fields implemented are:
+
+ \see IpV4PacketType \n
+ <a href="http://tools.ietf.org/html/rfc791">RFC 791</a>
+
+ \todo Implement options
+ */
+ struct Parse_IpV4 : public PacketParserBase
+ {
typedef Parse_UIntField < 0, 4 > Parse_Version;
typedef Parse_UIntField < 4, 8 > Parse_IHL;
typedef Parse_UInt8 Parse_8bit;
typedef Parse_Flag < 2 > Parse_MF;
typedef Parse_UIntField < 3, 16 > Parse_Frag;
typedef Parse_UInt32 Parse_32bit;
+ typedef Parse_INet4Address Parse_Addr;
+
+# ifndef DOXYGEN
+
+ SENF_PACKET_PARSER_NO_INIT(Parse_IpV4);
SENF_PACKET_PARSER_DEFINE_FIXED_FIELDS(
((OverlayField)( version, Parse_Version ))
((Field )( ttl, Parse_8bit ))
((Field )( protocol, Parse_8bit ))
((Field )( crc, Parse_16bit ))
- ((Field )( source, Parse_32bit ))
- ((Field )( destination, Parse_32bit )) );
+ ((Field )( source, Parse_Addr ))
+ ((Field )( destination, Parse_Addr )) );
+
+# else
+
+ Parse_Version version() const;
+ Parse_IHL ihl() const;
+ Parse_8bit tos() const;
+ Parse_16bit length() const;
+ Parse_16bit identifier() const;
+ Parse_R reserved() const;
+ Parse_DF df() const;
+ Parse_MF mf() const;
+ Parse_Frag frag() const;
+ Parse_8bit ttl() const;
+ Parse_8bit protocol() const;
+ Parse_16bit crc() const;
+ Parse_Addr source() const;
+ Parse_Addr destination() const;
+
+# endif
void init() {
version() = 4;
}
};
+ /** \brief IP protocol number registry
+
+ This registeres packets with their IP protocol number.
+
+ \see <a href="http://www.iana.org/assignments/protocol-numbers">Protocol numbers</a> \n
+ PacketRegistry
+ */
struct IpTypes {
- // See http://www.iana.org/assignments/protocol-numbers
- // Also used by IPv6
typedef boost::uint16_t key_t;
};
+ /** \brief IpV4 packet
+
+ \par Packet type (typedef):
+ \ref IpV4Packet
+
+ \par Fields:
+ \ref Parse_IpV4
+
+ \par Associated registries:
+ \ref IpTypes
+
+ \ingroup protocolbundle_default
+ */
struct IpV4PacketType
: public PacketTypeBase,
public PacketTypeMixin<IpV4PacketType, IpTypes>
static void dump(packet p, std::ostream & os);
};
+ /** \brief IpV4 packet typedef */
typedef IpV4PacketType::packet IpV4Packet;
-
- ///@}
}
///////////////////////////////hh.e////////////////////////////////////////
+#endif
+#ifndef SENF_PACKETS_DECL_ONLY
//#include IpV4Packet.cci"
//#include "IpV4Packet.ct"
//#include "IpV4Packet.cti"