X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FDefaultBundle%2FIpV4Packet.hh;h=bbc884c2eb53eba012ab3e66313b8bffdfbb6713;hb=d6abda313f70c8a849c5e3f3bbfc12ce301789f1;hp=5fc143ead6a46c07ed3994394c05e955b1d101f4;hpb=8d2d26f114d3df0a60c5c516fcf40671b1e55558;p=senf.git diff --git a/Packets/DefaultBundle/IpV4Packet.hh b/Packets/DefaultBundle/IpV4Packet.hh index 5fc143e..bbc884c 100644 --- a/Packets/DefaultBundle/IpV4Packet.hh +++ b/Packets/DefaultBundle/IpV4Packet.hh @@ -67,58 +67,38 @@ namespace senf { */ 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() { +# include SENF_FIXED_PARSER() + + SENF_PARSER_BITFIELD( version, 4, unsigned ); + SENF_PARSER_BITFIELD( ihl, 4, unsigned ); + + SENF_PARSER_FIELD( tos, Parse_UInt8 ); + SENF_PARSER_FIELD( length, Parse_UInt16 ); + SENF_PARSER_FIELD( identifier, Parse_UInt16 ); + + SENF_PARSER_BITFIELD( reserved, 1, bool ); + SENF_PARSER_BITFIELD( df, 1, bool ); + SENF_PARSER_BITFIELD( mf, 1, bool ); + SENF_PARSER_BITFIELD( frag, 13, unsigned ); + + SENF_PARSER_FIELD( ttl, Parse_UInt8 ); + SENF_PARSER_FIELD( protocol, Parse_UInt8 ); + SENF_PARSER_FIELD( checksum, Parse_UInt16 ); + SENF_PARSER_FIELD( source, Parse_INet4Address ); + SENF_PARSER_FIELD( destination, Parse_INet4Address ); + + SENF_PARSER_INIT() { version() = 4; + // We don't support option headers at the moment ... + ihl() = 5; + } + + SENF_PARSER_FINALIZE(Parse_IpV4); + + boost::uint16_t calcChecksum() const; + + bool validateChecksum() const { + return checksum() == calcChecksum(); } }; @@ -163,6 +143,7 @@ namespace senf { { return p->protocol(); } static void dump(packet p, std::ostream & os); + static void finalize(packet p); }; /** \brief IpV4 packet typedef */