Search:

SENF Extensible Network Framework

  • Home
  • Download
  • Wiki
  • BerliOS
  • ChangeLog
  • Browse SVN
  • Bug Tracker
  • Overview
  • Examples
  • HowTos
  • Glossary
  • PPI
  • Packets
  • Scheduler
  • Socket
  • Utils
  • Console
  • Daemon
  • Logger
  • Termlib
  • Main Page
  • Related Pages
  • Modules
  • Namespaces
  • Classes
  • Files
  • File List
  • File Members

DefaultBundle/IPv4Packet.hh

Go to the documentation of this file.
00001 // $Id: IPv4Packet.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2006
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Stefan Bund <g0dil@berlios.de>
00007 //
00008 // This program is free software; you can redistribute it and/or modify
00009 // it under the terms of the GNU General Public License as published by
00010 // the Free Software Foundation; either version 2 of the License, or
00011 // (at your option) any later version.
00012 //
00013 // This program is distributed in the hope that it will be useful,
00014 // but WITHOUT ANY WARRANTY; without even the implied warranty of
00015 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016 // GNU General Public License for more details.
00017 //
00018 // You should have received a copy of the GNU General Public License
00019 // along with this program; if not, write to the
00020 // Free Software Foundation, Inc.,
00021 // 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
00022 
00026 #ifndef HH_SENF_Packets_DefaultBundle_IPv4Packet_
00027 #define HH_SENF_Packets_DefaultBundle_IPv4Packet_ 1
00028 
00029 // Custom includes
00030 #include <senf/Socket/Protocols/INet/INet4Address.hh>
00031 #include <senf/Packets/Packets.hh>
00032 
00033 //#include "IPv4Packet.mpp"
00034 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00035 
00036 namespace senf {
00037 
00042     struct INet4AddressParser
00043         : public ValueParserBase<INet4AddressParser, INet4Address, 4u>
00044     {
00045         INet4AddressParser(data_iterator i, state_type s) : Base(i,s) {}
00046 
00047         value_type value() const { return value_type::from_data(i()); }
00048         void value(value_type const & v) { std::copy(v.begin(), v.end(), i()); }
00049 
00050         using Base::operator=;
00051     };
00052 
00064     struct IPv4PacketParser : public PacketParserBase
00065     {
00066 #       include SENF_FIXED_PARSER()
00067 
00068         SENF_PARSER_BITFIELD( version,   4, unsigned );
00069         SENF_PARSER_BITFIELD( ihl,       4, unsigned );
00070 
00071         SENF_PARSER_FIELD( tos,         UInt8Parser        );
00072         SENF_PARSER_FIELD( length,      UInt16Parser       );
00073         SENF_PARSER_FIELD( identifier,  UInt16Parser       );
00074 
00075         SENF_PARSER_PRIVATE_BITFIELD( reserved,  1, bool     );
00076         SENF_PARSER_BITFIELD        ( df,        1, bool     );
00077         SENF_PARSER_BITFIELD        ( mf,        1, bool     );
00078         SENF_PARSER_BITFIELD        ( frag,     13, unsigned );
00079 
00080         SENF_PARSER_FIELD( ttl,         UInt8Parser        );
00081         SENF_PARSER_FIELD( protocol,    UInt8Parser        );
00082         SENF_PARSER_FIELD( checksum,    UInt16Parser       );
00083         SENF_PARSER_FIELD( source,      INet4AddressParser );
00084         SENF_PARSER_FIELD( destination, INet4AddressParser );
00085 
00086         SENF_PARSER_INIT() {
00087             version() = 4;
00088             // We don't support option headers at the moment ...
00089             ihl() = 5;
00090         }
00091 
00092         SENF_PARSER_FINALIZE(IPv4PacketParser);
00093 
00094         boost::uint16_t calcChecksum() const; 
00095 
00098         bool validateChecksum() const {
00099             return checksum() == calcChecksum();
00100         }                               
00101 
00104     };
00105 
00113     struct IpTypes {
00114         typedef boost::uint8_t key_t;
00115     };
00116 
00162     struct IPv4PacketType
00163         : public PacketTypeBase,
00164           public PacketTypeMixin<IPv4PacketType, IpTypes>
00165     {
00166 #ifndef DOXYGEN
00167         typedef PacketTypeMixin<IPv4PacketType, IpTypes> mixin;
00168 #endif
00169         typedef ConcretePacket<IPv4PacketType> packet;  
00170         typedef IPv4PacketParser parser;                
00171 
00172         using mixin::nextPacketRange;
00173         using mixin::nextPacketType;
00174         using mixin::initSize;
00175         using mixin::init;
00176 
00177         static key_t nextPacketKey(packet p)
00178             { return p->protocol(); }
00179 
00181         static void dump(packet p, std::ostream & os);
00182 
00183         static void finalize(packet p); 
00184 
00190     };
00191 
00195     typedef ConcretePacket<IPv4PacketType> IPv4Packet;
00196 }
00197 
00198 
00199 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00200 //#include "IPv4Packet.cci"
00201 //#include "IPv4Packet.ct"
00202 //#include "IPv4Packet.cti"
00203 #endif
00204 
00205 
00206 // Local Variables:
00207 // mode: c++
00208 // fill-column: 100
00209 // c-file-style: "senf"
00210 // indent-tabs-mode: nil
00211 // ispell-local-dictionary: "american"
00212 // compile-command: "scons -u test"
00213 // comment-column: 40
00214 // End:

Contact: senf-dev@lists.berlios.de | © 2006-2010 Fraunhofer Institute for Open Communication Systems, Network Research