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/TCPPacket.hh

Go to the documentation of this file.
00001 // $Id: TCPPacket.hh 1742 2010-11-04 14:51:56Z g0dil $
00002 //
00003 // Copyright (C) 2009
00004 // Fraunhofer (FOKUS)
00005 // Competence Center NETwork research (NET), St. Augustin, GERMANY
00006 //     Dennis Goslar <dennis.goslar@inf.hochschule-bonn-rhein-sieg.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_TCPPacket_
00027 #define HH_SENF_Packets_DefaultBundle_TCPPacket_ 1
00028 
00029 // Custom includes
00030 #include <senf/Packets/Packets.hh>
00031 
00032 //#include "TCPPacket.mpp"
00033 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00034 
00035 namespace senf {
00036 
00045     struct TCPPacketParser : public PacketParserBase
00046     {
00047 #       include SENF_PARSER()
00048 
00049         SENF_PARSER_FIELD( source,                  UInt16Parser );
00050         SENF_PARSER_FIELD( destination,             UInt16Parser );
00051         SENF_PARSER_FIELD( sequencenumber,          UInt32Parser );
00052         SENF_PARSER_FIELD( acknowledgmentnumber,    UInt32Parser );
00053 
00054         SENF_PARSER_BITFIELD        ( dataoffset, 4, unsigned );
00055         SENF_PARSER_PRIVATE_BITFIELD( reserved,   6, unsigned );
00056         SENF_PARSER_BITFIELD        ( urgf,       1, bool     );
00057         SENF_PARSER_BITFIELD        ( ackf,       1, bool     );
00058         SENF_PARSER_BITFIELD        ( pshf,       1, bool     );
00059         SENF_PARSER_BITFIELD        ( rstf,       1, bool     );
00060         SENF_PARSER_BITFIELD        ( synf,       1, bool     );
00061         SENF_PARSER_BITFIELD        ( finf,       1, bool     );
00062 
00063         SENF_PARSER_FIELD( window,        UInt16Parser );
00064         SENF_PARSER_FIELD( checksum,      UInt16Parser );
00065         SENF_PARSER_FIELD( urgentpointer, UInt16Parser );
00066 
00067         // skip option part in TCP-Header, dataoffset()*4 = TCP header length in byte
00068         // for options see http://www.iana.org/assignments/tcp-parameters/
00069         // if dataoffset() < 5 packet is invalid
00070         SENF_PARSER_SKIP( (dataoffset() < 5 ? 0 : dataoffset()*4-20), 0);
00071 
00072         SENF_PARSER_FINALIZE(TCPPacketParser);
00073 
00074         SENF_PARSER_INIT() {
00075             // Reserved: 6 bits, reserved for future use. Must be zero.
00076             // see http://tools.ietf.org/html/rfc793
00077             reserved_() = 0;
00078             // dataoffset per default 5, 5*4 = 20 Byte Header Length
00079             dataoffset() = 5;
00080         }
00081 
00082         boost::uint16_t calcChecksum() const; 
00083 
00086         bool validateChecksum() const {
00087             return checksum() == 0u || checksum() == calcChecksum();
00088         }                               
00089 
00091     };
00092 
00142     struct TCPPacketType
00143         : public PacketTypeBase,
00144           public PacketTypeMixin<TCPPacketType>
00145     {
00146 #ifndef DOXYGEN
00147         typedef PacketTypeMixin<TCPPacketType> mixin;
00148 #endif
00149         typedef ConcretePacket<TCPPacketType> packet; 
00150         typedef TCPPacketParser parser;               
00151 
00152         using mixin::nextPacketRange;
00153         using mixin::initSize;
00154         using mixin::init;
00155 
00157         static void dump(packet p, std::ostream & os);
00158 
00159         static void finalize(packet p); 
00160 
00164     };
00165 
00169     typedef ConcretePacket<TCPPacketType> TCPPacket;
00170 }
00171 
00172 
00173 //-/////////////////////////////////////////////////////////////////////////////////////////////////
00174 //#include "TCPPacket.cci"
00175 //#include "TCPPacket.ct"
00176 //#include "TCPPacket.cti"
00177 #endif
00178 
00179 
00180 // Local Variables:
00181 // mode: c++
00182 // fill-column: 100
00183 // c-file-style: "senf"
00184 // indent-tabs-mode: nil
00185 // ispell-local-dictionary: "american"
00186 // compile-command: "scons -u test"
00187 // comment-column: 40
00188 // End:

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