X-Git-Url: http://g0dil.de/git?a=blobdiff_plain;f=Packets%2FPacketType.ct;h=caec158fa3db3634b31bf79116ba943b303e43b8;hb=92f8630b75f3ef50e73c48cde58645dcd1534e27;hp=d3cc0855df7715a39780d31ce48e21ae172c3e65;hpb=0990bd1c4f917855f3645e7329a84b00e54ccd7d;p=senf.git diff --git a/Packets/PacketType.ct b/Packets/PacketType.ct index d3cc085..caec158 100644 --- a/Packets/PacketType.ct +++ b/Packets/PacketType.ct @@ -1,6 +1,6 @@ // $Id$ // -// Copyright (C) 2008 +// Copyright (C) 2008 // Fraunhofer Institute for Open Communication Systems (FOKUS) // Competence Center NETwork research (NET), St. Augustin, GERMANY // Stefan Bund @@ -35,19 +35,31 @@ template prefix_ senf::PacketInterpreterBase::optional_range -senf::PacketTypeMixin::nextPacketRange(Packet p) +senf::PacketTypeMixin::nextPacketRange(Packet const & p) { - if (p.data().size() < Self::initSize()) - return PacketTypeBase::no_range(); typename Self::size_type sz (Self::initHeadSize()); ///\idea This if condition could be replaced with a compile time switch by checking, wether /// (the function address) Self::initHeadSize is different from PacketTypeBase::initHeadSize - if (sz == PacketTypeBase::size_type(-1)) - return PacketTypeBase::range(boost::next(p.data().begin(),Self::initSize()), - p.data().end()); + if (sz == PacketTypeBase::size_type(-1)) { + typename Self::size_type headsz (bytes(p.as< ConcretePacket >().parser())); + return p.data().size() < headsz ? + PacketTypeBase::no_range() : + PacketInterpreterBase::optional_range( + PacketTypeBase::range(boost::next(p.data().begin(), headsz), + p.data().end())); + } else - return PacketTypeBase::range(boost::next(p.data().begin(),sz), - boost::prior(p.data().end(),Self::initSize()-sz)); + // If we have a trailer, we do *not* use the 'bytes' value but initSize/initHeadSize, this + // is much safer since the bytes() value will probably not be very correct anyways (what + // should it return ? the size of the header only, the combined size of header and trailer + // or the size of the packet from header to trailer including payload?). + // + // So, the helper only works with fixed-size parsers if the packet has a trailer. + return p.data().size() < Self::initSize() ? + PacketTypeBase::no_range() : + PacketInterpreterBase::optional_range( + PacketTypeBase::range(boost::next(p.data().begin(),sz), + boost::prior(p.data().end(),Self::initSize()-sz))); } ///////////////////////////////ct.e////////////////////////////////////////