X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FIpV4Packet.hh;h=0dd83445e3932c0e940a6cb96c89d0fc49f8cfb4;hb=81ffa1c459b96dd44472bcef37e1e373934ee138;hp=94a3a911535de2543e3adbc04a6d60f0493f3096;hpb=9357448dc66bc9acfd3bd8db423deb75bcd6a2c4;p=senf.git diff --git a/Packets/DefaultBundle/IpV4Packet.hh b/Packets/DefaultBundle/IpV4Packet.hh index 94a3a91..0dd8344 100644 --- a/Packets/DefaultBundle/IpV4Packet.hh +++ b/Packets/DefaultBundle/IpV4Packet.hh @@ -20,98 +20,162 @@ // 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/Packet.hh" -#include "Packets/ParseInt.hh" -#include "Packets/ParseArray.hh" -#include "Packets/PacketRegistry.hh" +#include "Socket/Protocols/INet/INet4Address.hh" +#include "Packets/Packets.hh" //#include "IpV4Packet.mpp" ///////////////////////////////hh.p//////////////////////////////////////// namespace senf { + /** \brief Parse in IpV4 address - template - struct Parse_IpV4 : public ParserBase + \see INet4Address + */ + struct Parse_INet4Address : public PacketParserBase { - template - struct rebind { typedef Parse_IpV4 parser; }; - typedef Iterator byte_iterator; + Parse_INet4Address(data_iterator i, state_type s) : PacketParserBase(i,s,fixed_bytes) {} - Parse_IpV4() {} - Parse_IpV4(Iterator const & i) : ParserBase(i) {} + /////////////////////////////////////////////////////////////////////////// - static unsigned bytes() { return 20; } + 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; } + }; - typedef Parse_UIntField < 0, 4, Iterator > Parse_Version; - typedef Parse_UIntField < 4, 8, Iterator > Parse_IHL; - typedef Parse_UInt8 < Iterator > Parse_8bit; - typedef Parse_UInt16 < Iterator > Parse_16bit; - typedef Parse_Flag < 0, Iterator > Parse_R; - typedef Parse_Flag < 1, Iterator > Parse_DF; - typedef Parse_Flag < 2, Iterator > Parse_MF; - typedef Parse_UIntField < 3, 16, Iterator > Parse_Frag; - typedef Parse_UInt32 < Iterator > Parse_32bit; - - Parse_Version version() const { return Parse_Version (this->i() ); } - Parse_IHL ihl() const { return Parse_IHL (this->i() ); } - Parse_8bit tos() const { return Parse_8bit (this->i() + 1 ); } - Parse_16bit length() const { return Parse_16bit (this->i() + 2 ); } - Parse_16bit identifier() const { return Parse_16bit (this->i() + 4 ); } - Parse_R reserved() const { return Parse_R (this->i() + 6 ); } - Parse_DF df() const { return Parse_DF (this->i() + 6 ); } - Parse_MF mf() const { return Parse_MF (this->i() + 6 ); } - Parse_Frag frag() const { return Parse_Frag (this->i() + 6 ); } - Parse_8bit ttl() const { return Parse_8bit (this->i() + 8 ); } - Parse_8bit protocol() const { return Parse_8bit (this->i() + 9 ); } - Parse_16bit crc() const { return Parse_16bit (this->i() + 10 ); } - Parse_32bit source() const { return Parse_32bit (this->i() + 12 ); } - Parse_32bit destination() const { return Parse_32bit (this->i() + 16 ); } + /** \brief Parse an IpV4 packet + + Parser implementing the IpV4 header. The fields implemented are: + + \see IpV4PacketType \n + RFC 791 + + \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_UInt16 Parse_16bit; + typedef Parse_Flag < 0 > Parse_R; + typedef Parse_Flag < 1 > Parse_DF; + 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 )( ihl, Parse_IHL )) + ((Field )( tos, Parse_8bit )) + ((Field )( length, Parse_16bit )) + ((Field )( identifier, Parse_16bit )) + ((OverlayField)( reserved, Parse_R )) + ((OverlayField)( df, Parse_DF )) + ((OverlayField)( mf, Parse_MF )) + ((Field )( frag, Parse_Frag )) + ((Field )( ttl, Parse_8bit )) + ((Field )( protocol, Parse_8bit )) + ((Field )( crc, Parse_16bit )) + ((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 Protocol numbers \n + PacketRegistry + */ struct IpTypes { - // See http://www.iana.org/assignments/protocol-numbers - // Also used by IPv6 typedef boost::uint16_t key_t; }; - class IpV4Packet - : public Packet, - public Parse_IpV4, - public PacketRegistryMixin - { - using PacketRegistryMixin::registerInterpreter; - public: - /////////////////////////////////////////////////////////////////////////// - // Types + /** \brief IpV4 packet + + \par Packet type (typedef): + \ref IpV4Packet - typedef ptr_t::ptr ptr; + \par Fields: + \ref Parse_IpV4 - /////////////////////////////////////////////////////////////////////////// + \par Associated registries: + \ref IpTypes + + \ingroup protocolbundle_default + */ + struct IpV4PacketType + : public PacketTypeBase, + public PacketTypeMixin + { + typedef PacketTypeMixin mixin; + typedef ConcretePacket packet; + typedef Parse_IpV4 parser; - private: - template - IpV4Packet(Arg const & arg); + using mixin::nextPacketRange; + using mixin::nextPacketType; + using mixin::initSize; + using mixin::init; - virtual void v_nextInterpreter() const; - virtual void v_finalize(); - virtual void v_dump(std::ostream & os) const; + static registry_key_t nextPacketKey(packet p) + { return p->protocol(); } - friend class Packet; + 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" +//#include "IpV4Packet.cti" #endif @@ -121,4 +185,6 @@ namespace senf { // c-file-style: "senf" // indent-tabs-mode: nil // ispell-local-dictionary: "american" +// compile-command: "scons -u test" +// comment-column: 40 // End: