"Fossies" - the Fresh Open Source Software Archive 
Member "snort3_extra-3.1.51.0/src/codecs/cd_slip/cd_slip.cc" (20 Dec 2022, 2613 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_slip.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_sip.cc author Josh Rosenbaum <jrosenba@cisco.com>
19
20 #include <daq_dlt.h>
21
22 #include "framework/codec.h"
23
24 using namespace snort;
25
26 #define CD_SLIP_NAME "slip"
27 #define CD_SLIP_HELP_STR "support for slip protocol"
28 #define CD_SLIP_HELP ADD_DLT(CD_SLIP_HELP_STR, DLT_SLIP)
29
30 const uint16_t SLIP_HEADER_LEN = 16;
31
32 namespace
33 {
34 class SlipCodec : public Codec
35 {
36 public:
37 SlipCodec() : Codec(CD_SLIP_NAME) { }
38
39 bool decode(const RawData&, CodecData&, DecodeData&) override;
40 void get_data_link_type(std::vector<int>&) override;
41 };
42 } // namespace
43
44 void SlipCodec::get_data_link_type(std::vector<int>& v)
45 {
46 v.push_back(DLT_SLIP);
47 }
48
49 bool SlipCodec::decode(const RawData& raw, CodecData& codec, DecodeData&)
50 {
51 if (raw.len < SLIP_HEADER_LEN)
52 return false;
53
54 // set the fields which will be sent back to the packet manager
55 codec.lyr_len = SLIP_HEADER_LEN;
56 codec.next_prot_id = ProtocolId::ETHERTYPE_IPV4;
57 return true;
58 }
59
60 //-------------------------------------------------------------------------
61 // api
62 //-------------------------------------------------------------------------
63
64 static Codec* ctor(Module*)
65 { return new SlipCodec(); }
66
67 static void dtor(Codec* cd)
68 { delete cd; }
69
70 static const CodecApi slip_api =
71 {
72 {
73 PT_CODEC,
74 sizeof(CodecApi),
75 CDAPI_VERSION,
76 0,
77 API_RESERVED,
78 API_OPTIONS,
79 CD_SLIP_NAME,
80 CD_SLIP_HELP,
81 nullptr,
82 nullptr
83 },
84 nullptr,
85 nullptr,
86 nullptr,
87 nullptr,
88 ctor,
89 dtor
90 };
91
92 SO_PUBLIC const BaseApi* snort_plugins[] =
93 {
94 &slip_api.base,
95 nullptr
96 };