2 // Copyright (c) 2020 Fraunhofer Institute for Applied Information Technology (FIT)
3 // Network Research Group (NET)
4 // Schloss Birlinghoven, 53754 Sankt Augustin, GERMANY
5 // Contact: support@wiback.org
7 // This file is part of the SENF code tree.
8 // It is licensed under the 3-clause BSD License (aka New BSD License).
9 // See LICENSE.txt in the top level directory for details or visit
10 // https://opensource.org/licenses/BSD-3-Clause
15 \brief PacketParser inline non-template implementation */
19 #include "PacketData.hh"
21 #define prefix_ inline
22 //-/////////////////////////////////////////////////////////////////////////////////////////////////
24 //-/////////////////////////////////////////////////////////////////////////////////////////////////
25 // senf::PacketParserBase
29 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::i()
37 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::end()
43 prefix_ senf::PacketParserBase::ParserProtector::ParserProtector(PacketParserBase const * p)
44 : safe_i_( *p), parser_(p)
47 prefix_ senf::PacketParserBase::ParserProtector::ParserProtector(ParserProtector const & other_)
48 : safe_i_( *other_.parser_), parser_(other_.parser_)
50 other_.parser_ = nullptr;
53 prefix_ senf::PacketParserBase::ParserProtector::~ParserProtector()
55 if (parser_) const_cast<PacketParserBase *>(parser_)->i_ = safe_i_;
60 prefix_ senf::PacketParserBase::ParserProtector senf::PacketParserBase::protect()
63 return ParserProtector(this);
66 prefix_ bool senf::PacketParserBase::check(size_type size)
69 return std::distance(i(),end()) < 0 ? false : size <= size_type(std::distance(i(),end()));
72 prefix_ void senf::PacketParserBase::validate(size_type size)
75 if (SENF_UNLIKELY(!check(size)))
76 throw TruncatedPacketException();
79 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s)
83 prefix_ senf::PacketParserBase::PacketParserBase(data_iterator i, state_type s,
92 prefix_ senf::PacketParserBase::data_iterator senf::PacketParserBase::i(size_type offset)
96 return boost::next(i_, offset);
99 prefix_ senf::PacketParserBase::state_type senf::PacketParserBase::state()
105 prefix_ senf::PacketData & senf::PacketParserBase::data()
111 prefix_ void senf::PacketParserBase::init()
115 prefix_ void senf::PacketParserBase::defaultInit()
119 prefix_ senf::Packet senf::PacketParserBase::packet()
122 // OUCH ... I hate this but for some awkward packet types, access to the packet
123 // from the parser is really needed (e.g. UDP when building the pseudo-header
124 // for calculating the checksum).
125 return Packet(PacketInterpreterBase::ptr(static_cast<PacketInterpreterBase*>(&data())));
128 //-/////////////////////////////////////////////////////////////////////////////////////////////////
135 // c-file-style: "senf"
136 // indent-tabs-mode: nil
137 // ispell-local-dictionary: "american"
138 // compile-command: "scons -u test"
139 // comment-column: 40