"Fossies" - the Fresh Open Source Software Archive

Member "snort3_extra-3.1.51.0/src/codecs/cd_null/cd_null.cc" (20 Dec 2022, 2592 Bytes) of package /linux/misc/snort3_extra-3.1.51.0.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file. For more information about "cd_null.cc" see the Fossies "Dox" file reference documentation.

    1 //--------------------------------------------------------------------------
    2 // Copyright (C) 2014-2022 Cisco and/or its affiliates. All rights reserved.
    3 //
    4 // This program is free software; you can redistribute it and/or modify it
    5 // under the terms of the GNU General Public License Version 2 as published
    6 // by the Free Software Foundation.  You may not use, modify or distribute
    7 // this program under any other version of the GNU General Public License.
    8 //
    9 // This program is distributed in the hope that it will be useful, but
   10 // WITHOUT ANY WARRANTY; without even the implied warranty of
   11 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   12 // General Public License for more details.
   13 //
   14 // You should have received a copy of the GNU General Public License along
   15 // with this program; if not, write to the Free Software Foundation, Inc.,
   16 // 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
   17 //--------------------------------------------------------------------------
   18 // cd_null.cc author Josh Rosenbaum <jrosenba@cisco.com>
   19 
   20 #include <daq_dlt.h>
   21 
   22 #include "framework/codec.h"
   23 
   24 #define CD_NULL_NAME "null"
   25 #define CD_NULL_HELP_STR "support for null encapsulation"
   26 #define CD_NULL_HELP ADD_DLT(CD_NULL_HELP_STR, DLT_NULL)
   27 
   28 using namespace snort;
   29 
   30 namespace
   31 {
   32 class NullCodec : public Codec
   33 {
   34 public:
   35     NullCodec() : Codec(CD_NULL_NAME) { }
   36 
   37     bool decode(const RawData&, CodecData&, DecodeData&) override;
   38     void get_data_link_type(std::vector<int>&) override;
   39 };
   40 } // namespace
   41 
   42 static const uint16_t NULL_HDRLEN = 4;
   43 
   44 bool NullCodec::decode(const RawData& raw, CodecData& data, DecodeData&)
   45 {
   46     if (raw.len < NULL_HDRLEN)
   47         return false;
   48 
   49     data.lyr_len = NULL_HDRLEN;
   50     data.next_prot_id = ProtocolId::ETHERTYPE_IPV4;
   51     return true;
   52 }
   53 
   54 void NullCodec::get_data_link_type(std::vector<int>& v)
   55 { v.push_back(DLT_NULL); }
   56 
   57 //-------------------------------------------------------------------------
   58 // api
   59 //-------------------------------------------------------------------------
   60 
   61 static Codec* ctor(Module*)
   62 { return new NullCodec(); }
   63 
   64 static void dtor(Codec* cd)
   65 { delete cd; }
   66 
   67 static const CodecApi null_api =
   68 {
   69     {
   70         PT_CODEC,
   71         sizeof(CodecApi),
   72         CDAPI_VERSION,
   73         0,
   74         API_RESERVED,
   75         API_OPTIONS,
   76         CD_NULL_NAME,
   77         CD_NULL_HELP,
   78         nullptr,
   79         nullptr,
   80     },
   81     nullptr, // pinit
   82     nullptr, // pterm
   83     nullptr, // tinit
   84     nullptr, // tterm
   85     ctor, // ctor
   86     dtor, // dtor
   87 };
   88 
   89 SO_PUBLIC const BaseApi* snort_plugins[] =
   90 {
   91     &null_api.base,
   92     nullptr
   93 };