/src/PcapPlusPlus/Packet++/header/TLVData.h
Line | Count | Source |
1 | | #pragma once |
2 | | |
3 | | #include "Layer.h" |
4 | | #include "IpAddress.h" |
5 | | #include <string.h> |
6 | | #include <type_traits> |
7 | | |
8 | | /// @file |
9 | | |
10 | | /// @namespace pcpp |
11 | | /// @brief The main namespace for the PcapPlusPlus lib |
12 | | namespace pcpp |
13 | | { |
14 | | /// @class TLVRecord |
15 | | /// A wrapper class for a Type-Length-Value (TLV) record. This class does not create or modify TLV records, but |
16 | | /// rather serves as a wrapper and provides useful methods for retrieving data from them. This class has several |
17 | | /// abstract methods that should be implemented in derived classes. These methods are for record length value |
18 | | /// calculation (the 'L' in TLV) which is implemented differently in different protocols |
19 | | template <typename TRecType, typename TRecLen> class TLVRecord |
20 | | { |
21 | | protected: |
22 | | /// A struct representing the TLV construct |
23 | | #pragma pack(push, 1) |
24 | | struct TLVRawData |
25 | | { |
26 | | /// Record type |
27 | | TRecType recordType; |
28 | | /// Record length in bytes |
29 | | TRecLen recordLen; |
30 | | /// Record value (variable size) |
31 | | uint8_t recordValue[]; |
32 | | }; |
33 | | #pragma pack(pop) |
34 | | |
35 | | TLVRawData* m_Data; |
36 | | |
37 | | public: |
38 | | /// A c'tor for this class that gets a pointer to the TLV record raw data (byte array) |
39 | | /// @param[in] recordRawData A pointer to the TLV record raw data |
40 | | TLVRecord(uint8_t* recordRawData) |
41 | 1.29M | { |
42 | 1.29M | assign(recordRawData); |
43 | 1.29M | } pcpp::TLVRecord<unsigned char, unsigned char>::TLVRecord(unsigned char*) Line | Count | Source | 41 | 1.27M | { | 42 | 1.27M | assign(recordRawData); | 43 | 1.27M | } |
pcpp::TLVRecord<unsigned short, unsigned short>::TLVRecord(unsigned char*) Line | Count | Source | 41 | 15.3k | { | 42 | 15.3k | assign(recordRawData); | 43 | 15.3k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::TLVRecord(unsigned char*) |
44 | | |
45 | | /// A copy c'tor for this class. This copy c'tor doesn't copy the TLV data, but only the pointer to it, |
46 | | /// which means that after calling it both the old and the new instance will point to the same TLV raw data |
47 | | /// @param[in] other The TLVRecord instance to copy from |
48 | | TLVRecord(const TLVRecord& other) |
49 | 390k | { |
50 | 390k | m_Data = other.m_Data; |
51 | 390k | } pcpp::TLVRecord<unsigned short, unsigned short>::TLVRecord(pcpp::TLVRecord<unsigned short, unsigned short> const&) Line | Count | Source | 49 | 4.43k | { | 50 | 4.43k | m_Data = other.m_Data; | 51 | 4.43k | } |
pcpp::TLVRecord<unsigned char, unsigned char>::TLVRecord(pcpp::TLVRecord<unsigned char, unsigned char> const&) Line | Count | Source | 49 | 385k | { | 50 | 385k | m_Data = other.m_Data; | 51 | 385k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::TLVRecord(pcpp::TLVRecord<unsigned char, unsigned short> const&) |
52 | | |
53 | | /// A d'tor for this class, currently does nothing |
54 | 1.35M | virtual ~TLVRecord() = default; pcpp::TLVRecord<unsigned char, unsigned char>::~TLVRecord() Line | Count | Source | 54 | 1.33M | virtual ~TLVRecord() = default; |
pcpp::TLVRecord<unsigned short, unsigned short>::~TLVRecord() Line | Count | Source | 54 | 17.7k | virtual ~TLVRecord() = default; |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::~TLVRecord() |
55 | | |
56 | | /// Assign a pointer to the TLV record raw data (byte array) |
57 | | /// @param[in] recordRawData A pointer to the TLV record raw data |
58 | | void assign(uint8_t* recordRawData) |
59 | 2.43M | { |
60 | 2.43M | m_Data = reinterpret_cast<TLVRawData*>(recordRawData); |
61 | 2.43M | } pcpp::TLVRecord<unsigned char, unsigned char>::assign(unsigned char*) Line | Count | Source | 59 | 2.40M | { | 60 | 2.40M | m_Data = reinterpret_cast<TLVRawData*>(recordRawData); | 61 | 2.40M | } |
pcpp::TLVRecord<unsigned short, unsigned short>::assign(unsigned char*) Line | Count | Source | 59 | 31.1k | { | 60 | 31.1k | m_Data = reinterpret_cast<TLVRawData*>(recordRawData); | 61 | 31.1k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::assign(unsigned char*) |
62 | | |
63 | | /// Check if a pointer can be assigned to the TLV record data |
64 | | /// @param[in] recordRawData A pointer to the TLV record raw data |
65 | | /// @param[in] tlvDataLen The size of the TLV record raw data |
66 | | /// @return True if data is valid and can be assigned |
67 | | static bool canAssign(const uint8_t* recordRawData, size_t tlvDataLen) |
68 | 172k | { |
69 | 172k | return recordRawData != nullptr && |
70 | 172k | tlvDataLen >= (sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)); |
71 | 172k | } pcpp::TLVRecord<unsigned char, unsigned char>::canAssign(unsigned char const*, unsigned long) Line | Count | Source | 68 | 156k | { | 69 | 156k | return recordRawData != nullptr && | 70 | 156k | tlvDataLen >= (sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)); | 71 | 156k | } |
pcpp::TLVRecord<unsigned short, unsigned short>::canAssign(unsigned char const*, unsigned long) Line | Count | Source | 68 | 15.3k | { | 69 | 15.3k | return recordRawData != nullptr && | 70 | 15.3k | tlvDataLen >= (sizeof(TLVRawData::recordType) + sizeof(TLVRawData::recordLen)); | 71 | 15.3k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::canAssign(unsigned char const*, unsigned long) |
72 | | |
73 | | /// Overload of the assignment operator. This operator doesn't copy the TLV data, but rather copies the pointer |
74 | | /// to it, which means that after calling it both the old and the new instance will point to the same TLV raw |
75 | | /// data |
76 | | /// @param[in] other The TLVRecord instance to assign |
77 | | TLVRecord& operator=(const TLVRecord& other) |
78 | 1.01M | { |
79 | 1.01M | m_Data = other.m_Data; |
80 | 1.01M | return *this; |
81 | 1.01M | } pcpp::TLVRecord<unsigned short, unsigned short>::operator=(pcpp::TLVRecord<unsigned short, unsigned short> const&) Line | Count | Source | 78 | 12.4k | { | 79 | 12.4k | m_Data = other.m_Data; | 80 | 12.4k | return *this; | 81 | 12.4k | } |
pcpp::TLVRecord<unsigned char, unsigned char>::operator=(pcpp::TLVRecord<unsigned char, unsigned char> const&) Line | Count | Source | 78 | 999k | { | 79 | 999k | m_Data = other.m_Data; | 80 | 999k | return *this; | 81 | 999k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::operator=(pcpp::TLVRecord<unsigned char, unsigned short> const&) |
82 | | |
83 | | /// Overload of the equality operator. Two record are equal if both of them point to the same data, or if they |
84 | | /// point to different data but their total size is equal and the raw data they both contain is similar. |
85 | | /// @param[in] rhs The object to compare to |
86 | | /// @return True if both objects are equal, false otherwise |
87 | | bool operator==(const TLVRecord& rhs) const |
88 | | { |
89 | | if (m_Data == rhs.m_Data) |
90 | | return true; |
91 | | |
92 | | if (getTotalSize() != rhs.getTotalSize()) |
93 | | return false; |
94 | | |
95 | | if (isNull() || ((TLVRecord&)rhs).isNull()) |
96 | | return false; |
97 | | |
98 | | return (memcmp(m_Data, rhs.m_Data, getTotalSize()) == 0); |
99 | | } |
100 | | |
101 | | /// Overload of the not equal operator. |
102 | | /// @param[in] rhs The object to compare to |
103 | | /// @return True if objects are not equal, false otherwise |
104 | | bool operator!=(const TLVRecord& rhs) const |
105 | | { |
106 | | return !operator==(rhs); |
107 | | } |
108 | | |
109 | | /// @return The type field of the record (the 'T' in __Type__-Length-Value) |
110 | | TRecType getType() const |
111 | 519k | { |
112 | 519k | if (m_Data == nullptr) |
113 | 0 | return 0; |
114 | | |
115 | 519k | return m_Data->recordType; |
116 | 519k | } pcpp::TLVRecord<unsigned char, unsigned char>::getType() const Line | Count | Source | 111 | 519k | { | 112 | 519k | if (m_Data == nullptr) | 113 | 0 | return 0; | 114 | | | 115 | 519k | return m_Data->recordType; | 116 | 519k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::getType() const |
117 | | |
118 | | /// @return A pointer to the value of the record as byte array (the 'V' in Type-Length- __Value__) |
119 | | uint8_t* getValue() const |
120 | 634 | { |
121 | 634 | if (m_Data == nullptr) |
122 | 0 | return nullptr; |
123 | | |
124 | 634 | return m_Data->recordValue; |
125 | 634 | } |
126 | | |
127 | | /// @return True if the TLV record raw data is nullptr, false otherwise |
128 | | bool isNull() const |
129 | 3.17M | { |
130 | 3.17M | return (m_Data == nullptr); |
131 | 3.17M | } pcpp::TLVRecord<unsigned char, unsigned char>::isNull() const Line | Count | Source | 129 | 3.13M | { | 130 | 3.13M | return (m_Data == nullptr); | 131 | 3.13M | } |
pcpp::TLVRecord<unsigned short, unsigned short>::isNull() const Line | Count | Source | 129 | 36.4k | { | 130 | 36.4k | return (m_Data == nullptr); | 131 | 36.4k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::isNull() const |
132 | | |
133 | | /// @return True if the TLV record raw data is not nullptr, false otherwise |
134 | | bool isNotNull() const |
135 | 140k | { |
136 | 140k | return (m_Data != nullptr); |
137 | 140k | } pcpp::TLVRecord<unsigned char, unsigned char>::isNotNull() const Line | Count | Source | 135 | 140k | { | 136 | 140k | return (m_Data != nullptr); | 137 | 140k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned short, unsigned short>::isNotNull() const Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::isNotNull() const |
138 | | |
139 | | /// @return A pointer to the TLV record raw data byte stream |
140 | | uint8_t* getRecordBasePtr() const |
141 | 5.10M | { |
142 | 5.10M | return reinterpret_cast<uint8_t*>(m_Data); |
143 | 5.10M | } pcpp::TLVRecord<unsigned char, unsigned char>::getRecordBasePtr() const Line | Count | Source | 141 | 5.04M | { | 142 | 5.04M | return reinterpret_cast<uint8_t*>(m_Data); | 143 | 5.04M | } |
pcpp::TLVRecord<unsigned short, unsigned short>::getRecordBasePtr() const Line | Count | Source | 141 | 60.7k | { | 142 | 60.7k | return reinterpret_cast<uint8_t*>(m_Data); | 143 | 60.7k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::getRecordBasePtr() const |
144 | | |
145 | | /// Free the memory of the TLV record raw data |
146 | | void purgeRecordData() |
147 | 36.5k | { |
148 | 36.5k | if (!isNull()) |
149 | 36.5k | { |
150 | 36.5k | delete[] m_Data; |
151 | 36.5k | m_Data = nullptr; |
152 | 36.5k | } |
153 | 36.5k | } pcpp::TLVRecord<unsigned char, unsigned char>::purgeRecordData() Line | Count | Source | 147 | 36.5k | { | 148 | 36.5k | if (!isNull()) | 149 | 36.5k | { | 150 | 36.5k | delete[] m_Data; | 151 | 36.5k | m_Data = nullptr; | 152 | 36.5k | } | 153 | 36.5k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned short, unsigned short>::purgeRecordData() Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::purgeRecordData() |
154 | | |
155 | | /// A templated method to retrieve the record data as a certain type T. For example, if record data is 4B long |
156 | | /// (integer) then this method should be used as getValueAs<int>() and it will return the record data as an |
157 | | /// integer.<BR> Notice this return value is a copy of the data, not a pointer to the actual data |
158 | | /// @tparam T A non-pointer, default-constructible, trivially copyable type |
159 | | /// @param[in] offset The offset in the record data to start reading the value from. Useful for cases when you |
160 | | /// want to read some of the data that doesn't start at offset 0. This is an optional parameter and the default |
161 | | /// value is 0, meaning start reading the value at the beginning of the record data |
162 | | /// @return The record data as type T |
163 | | template <typename T> T getValueAs(size_t offset = 0) const |
164 | 12.9k | { |
165 | 12.9k | static_assert(std::is_trivially_copyable<T>::value && std::is_default_constructible<T>::value && |
166 | 12.9k | !std::is_pointer<T>::value, |
167 | 12.9k | "TLVRecord::getValueAs<T>() requires T to be a non-pointer, " |
168 | 12.9k | "default-constructible, trivially copyable type"); |
169 | | |
170 | 12.9k | if (getDataSize() < sizeof(T) + offset) |
171 | 4.15k | { |
172 | 4.15k | return T{}; |
173 | 4.15k | } |
174 | | |
175 | 8.80k | T result; |
176 | 8.80k | memcpy(&result, m_Data->recordValue + getValueOffset() + offset, sizeof(T)); |
177 | 8.80k | return result; |
178 | 12.9k | } unsigned int pcpp::TLVRecord<unsigned char, unsigned char>::getValueAs<unsigned int>(unsigned long) const Line | Count | Source | 164 | 3.69k | { | 165 | 3.69k | static_assert(std::is_trivially_copyable<T>::value && std::is_default_constructible<T>::value && | 166 | 3.69k | !std::is_pointer<T>::value, | 167 | 3.69k | "TLVRecord::getValueAs<T>() requires T to be a non-pointer, " | 168 | 3.69k | "default-constructible, trivially copyable type"); | 169 | | | 170 | 3.69k | if (getDataSize() < sizeof(T) + offset) | 171 | 3.57k | { | 172 | 3.57k | return T{}; | 173 | 3.57k | } | 174 | | | 175 | 121 | T result; | 176 | 121 | memcpy(&result, m_Data->recordValue + getValueOffset() + offset, sizeof(T)); | 177 | 121 | return result; | 178 | 3.69k | } |
unsigned char pcpp::TLVRecord<unsigned char, unsigned char>::getValueAs<unsigned char>(unsigned long) const Line | Count | Source | 164 | 9.27k | { | 165 | 9.27k | static_assert(std::is_trivially_copyable<T>::value && std::is_default_constructible<T>::value && | 166 | 9.27k | !std::is_pointer<T>::value, | 167 | 9.27k | "TLVRecord::getValueAs<T>() requires T to be a non-pointer, " | 168 | 9.27k | "default-constructible, trivially copyable type"); | 169 | | | 170 | 9.27k | if (getDataSize() < sizeof(T) + offset) | 171 | 585 | { | 172 | 585 | return T{}; | 173 | 585 | } | 174 | | | 175 | 8.68k | T result; | 176 | 8.68k | memcpy(&result, m_Data->recordValue + getValueOffset() + offset, sizeof(T)); | 177 | 8.68k | return result; | 178 | 9.27k | } |
|
179 | | |
180 | | /// A templated method to copy data of type T into the TLV record data. For example: if record data is 4[Bytes] |
181 | | /// long use this method with \<int\> to set an integer value into the record data: setValue<int>(num) |
182 | | /// @tparam T A non-pointer, trivially copyable type |
183 | | /// @param[in] newValue The value of type T to copy to the record data |
184 | | /// @param[in] valueOffset An optional parameter that specifies where to start setting the record data (default |
185 | | /// set to 0). For example: if record data is 20 bytes long and you only need to set the 4 last bytes as integer |
186 | | /// then use this method like this: setValue<int>(num, 16) |
187 | | /// @return True if value was set successfully or false if the size of T is larger than the record data size |
188 | | template <typename T> bool setValue(T newValue, int valueOffset = 0) |
189 | 0 | { |
190 | 0 | static_assert(std::is_trivially_copyable<T>::value && !std::is_pointer<T>::value, |
191 | 0 | "TLVRecord::setValue<T>() requires T to be a non-pointer, trivially copyable type"); |
192 | |
|
193 | 0 | if (getDataSize() < sizeof(T)) |
194 | 0 | { |
195 | 0 | return false; |
196 | 0 | } |
197 | | |
198 | 0 | memcpy(m_Data->recordValue + getValueOffset() + valueOffset, &newValue, sizeof(T)); |
199 | 0 | return true; |
200 | 0 | } Unexecuted instantiation: bool pcpp::TLVRecord<unsigned char, unsigned char>::setValue<unsigned int>(unsigned int, int) Unexecuted instantiation: bool pcpp::TLVRecord<unsigned char, unsigned char>::setValue<unsigned char>(unsigned char, int) |
201 | | |
202 | | /// @return The total size of the TLV record (in bytes) |
203 | | virtual size_t getTotalSize() const = 0; |
204 | | |
205 | | /// @return The size of the record value (meaning the size of the 'V' part in TLV) |
206 | | virtual size_t getDataSize() const = 0; |
207 | | |
208 | | protected: |
209 | | virtual size_t getValueOffset() const |
210 | 8.80k | { |
211 | 8.80k | return 0; |
212 | 8.80k | } Unexecuted instantiation: pcpp::TLVRecord<unsigned short, unsigned short>::getValueOffset() const pcpp::TLVRecord<unsigned char, unsigned char>::getValueOffset() const Line | Count | Source | 210 | 8.80k | { | 211 | 8.80k | return 0; | 212 | 8.80k | } |
Unexecuted instantiation: pcpp::TLVRecord<unsigned char, unsigned short>::getValueOffset() const |
213 | | }; |
214 | | |
215 | | /// @class TLVRecordReader |
216 | | /// A class for reading TLV records data out of a byte stream. This class contains helper methods for retrieving and |
217 | | /// counting TLV records. This is a template class that expects template argument class derived from TLVRecord. |
218 | | template <typename TLVRecordType> class TLVRecordReader |
219 | | { |
220 | | private: |
221 | | mutable size_t m_RecordCount; |
222 | | |
223 | | public: |
224 | | /// A default c'tor for this class |
225 | | TLVRecordReader() |
226 | 1.36M | { |
227 | 1.36M | m_RecordCount = static_cast<size_t>(-1); |
228 | 1.36M | } pcpp::TLVRecordReader<pcpp::DhcpOption>::TLVRecordReader() Line | Count | Source | 226 | 20.9k | { | 227 | 20.9k | m_RecordCount = static_cast<size_t>(-1); | 228 | 20.9k | } |
pcpp::TLVRecordReader<pcpp::DhcpV6Option>::TLVRecordReader() Line | Count | Source | 226 | 5.70k | { | 227 | 5.70k | m_RecordCount = static_cast<size_t>(-1); | 228 | 5.70k | } |
pcpp::TLVRecordReader<pcpp::GtpV2InformationElement>::TLVRecordReader() Line | Count | Source | 226 | 20.6k | { | 227 | 20.6k | m_RecordCount = static_cast<size_t>(-1); | 228 | 20.6k | } |
pcpp::TLVRecordReader<pcpp::IPv4Option>::TLVRecordReader() Line | Count | Source | 226 | 714k | { | 227 | 714k | m_RecordCount = static_cast<size_t>(-1); | 228 | 714k | } |
pcpp::TLVRecordReader<pcpp::NflogTlv>::TLVRecordReader() Line | Count | Source | 226 | 2.27k | { | 227 | 2.27k | m_RecordCount = static_cast<size_t>(-1); | 228 | 2.27k | } |
pcpp::TLVRecordReader<pcpp::PPPoEDiscoveryLayer::PPPoETag>::TLVRecordReader() Line | Count | Source | 226 | 3.36k | { | 227 | 3.36k | m_RecordCount = static_cast<size_t>(-1); | 228 | 3.36k | } |
pcpp::TLVRecordReader<pcpp::TcpOption>::TLVRecordReader() Line | Count | Source | 226 | 560k | { | 227 | 560k | m_RecordCount = static_cast<size_t>(-1); | 228 | 560k | } |
pcpp::TLVRecordReader<pcpp::RadiusAttribute>::TLVRecordReader() Line | Count | Source | 226 | 21.9k | { | 227 | 21.9k | m_RecordCount = static_cast<size_t>(-1); | 228 | 21.9k | } |
pcpp::TLVRecordReader<pcpp::NdpOption>::TLVRecordReader() Line | Count | Source | 226 | 3.32k | { | 227 | 3.32k | m_RecordCount = static_cast<size_t>(-1); | 228 | 3.32k | } |
pcpp::TLVRecordReader<pcpp::IPv6TLVOptionHeader::IPv6Option>::TLVRecordReader() Line | Count | Source | 226 | 11.4k | { | 227 | 11.4k | m_RecordCount = static_cast<size_t>(-1); | 228 | 11.4k | } |
|
229 | | |
230 | | /// A default copy c'tor for this class |
231 | | TLVRecordReader(const TLVRecordReader& other) |
232 | | { |
233 | | m_RecordCount = other.m_RecordCount; |
234 | | } |
235 | | |
236 | | /// A d'tor for this class which currently does nothing |
237 | 1.36M | virtual ~TLVRecordReader() = default; pcpp::TLVRecordReader<pcpp::TcpOption>::~TLVRecordReader() Line | Count | Source | 237 | 560k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::DhcpOption>::~TLVRecordReader() Line | Count | Source | 237 | 20.9k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::DhcpV6Option>::~TLVRecordReader() Line | Count | Source | 237 | 5.70k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::GtpV2InformationElement>::~TLVRecordReader() Line | Count | Source | 237 | 20.6k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::IPv4Option>::~TLVRecordReader() Line | Count | Source | 237 | 714k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::IPv6TLVOptionHeader::IPv6Option>::~TLVRecordReader() Line | Count | Source | 237 | 11.4k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::NflogTlv>::~TLVRecordReader() Line | Count | Source | 237 | 2.27k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::PPPoEDiscoveryLayer::PPPoETag>::~TLVRecordReader() Line | Count | Source | 237 | 3.36k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::RadiusAttribute>::~TLVRecordReader() Line | Count | Source | 237 | 21.9k | virtual ~TLVRecordReader() = default; |
pcpp::TLVRecordReader<pcpp::NdpOption>::~TLVRecordReader() Line | Count | Source | 237 | 3.32k | virtual ~TLVRecordReader() = default; |
|
238 | | |
239 | | /// Overload of the assignment operator for this class |
240 | | /// @param[in] other The TLVRecordReader instance to assign |
241 | | TLVRecordReader& operator=(const TLVRecordReader& other) |
242 | 88.9k | { |
243 | 88.9k | m_RecordCount = other.m_RecordCount; |
244 | 88.9k | return *this; |
245 | 88.9k | } Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv4Option>::operator=(pcpp::TLVRecordReader<pcpp::IPv4Option> const&) pcpp::TLVRecordReader<pcpp::TcpOption>::operator=(pcpp::TLVRecordReader<pcpp::TcpOption> const&) Line | Count | Source | 242 | 88.9k | { | 243 | 88.9k | m_RecordCount = other.m_RecordCount; | 244 | 88.9k | return *this; | 245 | 88.9k | } |
|
246 | | |
247 | | // cppcheck-suppress functionStatic |
248 | | /// Get the first TLV record out of a byte stream |
249 | | /// @param[in] tlvDataBasePtr A pointer to the TLV data byte stream |
250 | | /// @param[in] tlvDataLen The TLV data byte stream length |
251 | | /// @return An instance of type TLVRecordType that contains the first TLV record. If tlvDataBasePtr is nullptr |
252 | | /// or tlvDataLen is zero the returned TLVRecordType instance will be logically null, meaning |
253 | | /// TLVRecordType.isNull() will return true |
254 | | TLVRecordType getFirstTLVRecord(uint8_t* tlvDataBasePtr, size_t tlvDataLen) const |
255 | 156k | { |
256 | 156k | TLVRecordType resRec(nullptr); // for NRVO optimization |
257 | 156k | if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen)) |
258 | 45.9k | return resRec; |
259 | | |
260 | 110k | resRec.assign(tlvDataBasePtr); |
261 | | // resRec pointer is out-bounds of the TLV records memory |
262 | 110k | if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) |
263 | 4.45k | resRec.assign(nullptr); |
264 | | |
265 | | // check if there are records at all and the total size is not zero |
266 | 110k | if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0)) |
267 | 1.41k | resRec.assign(nullptr); |
268 | | |
269 | 110k | return resRec; |
270 | 156k | } pcpp::TLVRecordReader<pcpp::DhcpOption>::getFirstTLVRecord(unsigned char*, unsigned long) const Line | Count | Source | 255 | 22.3k | { | 256 | 22.3k | TLVRecordType resRec(nullptr); // for NRVO optimization | 257 | 22.3k | if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen)) | 258 | 0 | return resRec; | 259 | | | 260 | 22.3k | resRec.assign(tlvDataBasePtr); | 261 | | // resRec pointer is out-bounds of the TLV records memory | 262 | 22.3k | if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 263 | 235 | resRec.assign(nullptr); | 264 | | | 265 | | // check if there are records at all and the total size is not zero | 266 | 22.3k | if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0)) | 267 | 0 | resRec.assign(nullptr); | 268 | | | 269 | 22.3k | return resRec; | 270 | 22.3k | } |
pcpp::TLVRecordReader<pcpp::DhcpV6Option>::getFirstTLVRecord(unsigned char*, unsigned long) const Line | Count | Source | 255 | 2.89k | { | 256 | 2.89k | TLVRecordType resRec(nullptr); // for NRVO optimization | 257 | 2.89k | if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen)) | 258 | 0 | return resRec; | 259 | | | 260 | 2.89k | resRec.assign(tlvDataBasePtr); | 261 | | // resRec pointer is out-bounds of the TLV records memory | 262 | 2.89k | if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 263 | 343 | resRec.assign(nullptr); | 264 | | | 265 | | // check if there are records at all and the total size is not zero | 266 | 2.89k | if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0)) | 267 | 0 | resRec.assign(nullptr); | 268 | | | 269 | 2.89k | return resRec; | 270 | 2.89k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::GtpV2InformationElement>::getFirstTLVRecord(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv4Option>::getFirstTLVRecord(unsigned char*, unsigned long) const pcpp::TLVRecordReader<pcpp::TcpOption>::getFirstTLVRecord(unsigned char*, unsigned long) const Line | Count | Source | 255 | 125k | { | 256 | 125k | TLVRecordType resRec(nullptr); // for NRVO optimization | 257 | 125k | if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen)) | 258 | 45.6k | return resRec; | 259 | | | 260 | 79.9k | resRec.assign(tlvDataBasePtr); | 261 | | // resRec pointer is out-bounds of the TLV records memory | 262 | 79.9k | if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 263 | 2.51k | resRec.assign(nullptr); | 264 | | | 265 | | // check if there are records at all and the total size is not zero | 266 | 79.9k | if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0)) | 267 | 91 | resRec.assign(nullptr); | 268 | | | 269 | 79.9k | return resRec; | 270 | 125k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv6TLVOptionHeader::IPv6Option>::getFirstTLVRecord(unsigned char*, unsigned long) const pcpp::TLVRecordReader<pcpp::NdpOption>::getFirstTLVRecord(unsigned char*, unsigned long) const Line | Count | Source | 255 | 2.27k | { | 256 | 2.27k | TLVRecordType resRec(nullptr); // for NRVO optimization | 257 | 2.27k | if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen)) | 258 | 266 | return resRec; | 259 | | | 260 | 2.00k | resRec.assign(tlvDataBasePtr); | 261 | | // resRec pointer is out-bounds of the TLV records memory | 262 | 2.00k | if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 263 | 34 | resRec.assign(nullptr); | 264 | | | 265 | | // check if there are records at all and the total size is not zero | 266 | 2.00k | if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0)) | 267 | 632 | resRec.assign(nullptr); | 268 | | | 269 | 2.00k | return resRec; | 270 | 2.27k | } |
pcpp::TLVRecordReader<pcpp::NflogTlv>::getFirstTLVRecord(unsigned char*, unsigned long) const Line | Count | Source | 255 | 3.28k | { | 256 | 3.28k | TLVRecordType resRec(nullptr); // for NRVO optimization | 257 | 3.28k | if (!TLVRecordType::canAssign(tlvDataBasePtr, tlvDataLen)) | 258 | 65 | return resRec; | 259 | | | 260 | 3.22k | resRec.assign(tlvDataBasePtr); | 261 | | // resRec pointer is out-bounds of the TLV records memory | 262 | 3.22k | if (resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 263 | 1.32k | resRec.assign(nullptr); | 264 | | | 265 | | // check if there are records at all and the total size is not zero | 266 | 3.22k | if (!resRec.isNull() && (tlvDataLen == 0 || resRec.getTotalSize() == 0)) | 267 | 693 | resRec.assign(nullptr); | 268 | | | 269 | 3.22k | return resRec; | 270 | 3.28k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::PPPoEDiscoveryLayer::PPPoETag>::getFirstTLVRecord(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::RadiusAttribute>::getFirstTLVRecord(unsigned char*, unsigned long) const |
271 | | |
272 | | // cppcheck-suppress [constParameterReference, functionStatic] |
273 | | /// Get a TLV record that follows a given TLV record in a byte stream |
274 | | /// @param[in] record A given TLV record |
275 | | /// @param[in] tlvDataBasePtr A pointer to the TLV data byte stream |
276 | | /// @param[in] tlvDataLen The TLV data byte stream length |
277 | | /// @return An instance of type TLVRecordType that wraps the record following the record given as input. If the |
278 | | /// input record.isNull() is true or if the next record is out of bounds of the byte stream, a logical null |
279 | | /// instance of TLVRecordType will be returned, meaning TLVRecordType.isNull() will return true |
280 | | TLVRecordType getNextTLVRecord(TLVRecordType& record, const uint8_t* tlvDataBasePtr, size_t tlvDataLen) const |
281 | 1.01M | { |
282 | 1.01M | TLVRecordType resRec(nullptr); // for NRVO optimization |
283 | | |
284 | 1.01M | if (record.isNull()) |
285 | 0 | return resRec; |
286 | | |
287 | 1.01M | if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(), |
288 | 1.01M | tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen - |
289 | 1.01M | record.getTotalSize())) |
290 | 45.6k | return resRec; |
291 | | |
292 | 971k | resRec.assign(record.getRecordBasePtr() + record.getTotalSize()); |
293 | | |
294 | 971k | if (resRec.getTotalSize() == 0) |
295 | 1.47k | resRec.assign(nullptr); |
296 | | |
297 | | // resRec pointer is out-bounds of the TLV records memory |
298 | 971k | if ((resRec.getRecordBasePtr() - tlvDataBasePtr) < 0) |
299 | 1.47k | resRec.assign(nullptr); |
300 | | |
301 | | // resRec pointer is out-bounds of the TLV records memory |
302 | 971k | if (!resRec.isNull() && resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) |
303 | 9.25k | resRec.assign(nullptr); |
304 | | |
305 | 971k | return resRec; |
306 | 1.01M | } pcpp::TLVRecordReader<pcpp::DhcpOption>::getNextTLVRecord(pcpp::DhcpOption&, unsigned char const*, unsigned long) const Line | Count | Source | 281 | 837k | { | 282 | 837k | TLVRecordType resRec(nullptr); // for NRVO optimization | 283 | | | 284 | 837k | if (record.isNull()) | 285 | 0 | return resRec; | 286 | | | 287 | 837k | if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(), | 288 | 837k | tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen - | 289 | 837k | record.getTotalSize())) | 290 | 7.83k | return resRec; | 291 | | | 292 | 829k | resRec.assign(record.getRecordBasePtr() + record.getTotalSize()); | 293 | | | 294 | 829k | if (resRec.getTotalSize() == 0) | 295 | 0 | resRec.assign(nullptr); | 296 | | | 297 | | // resRec pointer is out-bounds of the TLV records memory | 298 | 829k | if ((resRec.getRecordBasePtr() - tlvDataBasePtr) < 0) | 299 | 0 | resRec.assign(nullptr); | 300 | | | 301 | | // resRec pointer is out-bounds of the TLV records memory | 302 | 829k | if (!resRec.isNull() && resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 303 | 4.42k | resRec.assign(nullptr); | 304 | | | 305 | 829k | return resRec; | 306 | 837k | } |
pcpp::TLVRecordReader<pcpp::DhcpV6Option>::getNextTLVRecord(pcpp::DhcpV6Option&, unsigned char const*, unsigned long) const Line | Count | Source | 281 | 12.4k | { | 282 | 12.4k | TLVRecordType resRec(nullptr); // for NRVO optimization | 283 | | | 284 | 12.4k | if (record.isNull()) | 285 | 0 | return resRec; | 286 | | | 287 | 12.4k | if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(), | 288 | 12.4k | tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen - | 289 | 12.4k | record.getTotalSize())) | 290 | 1.50k | return resRec; | 291 | | | 292 | 10.9k | resRec.assign(record.getRecordBasePtr() + record.getTotalSize()); | 293 | | | 294 | 10.9k | if (resRec.getTotalSize() == 0) | 295 | 0 | resRec.assign(nullptr); | 296 | | | 297 | | // resRec pointer is out-bounds of the TLV records memory | 298 | 10.9k | if ((resRec.getRecordBasePtr() - tlvDataBasePtr) < 0) | 299 | 0 | resRec.assign(nullptr); | 300 | | | 301 | | // resRec pointer is out-bounds of the TLV records memory | 302 | 10.9k | if (!resRec.isNull() && resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 303 | 898 | resRec.assign(nullptr); | 304 | | | 305 | 10.9k | return resRec; | 306 | 12.4k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::GtpV2InformationElement>::getNextTLVRecord(pcpp::GtpV2InformationElement&, unsigned char const*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv4Option>::getNextTLVRecord(pcpp::IPv4Option&, unsigned char const*, unsigned long) const pcpp::TLVRecordReader<pcpp::TcpOption>::getNextTLVRecord(pcpp::TcpOption&, unsigned char const*, unsigned long) const Line | Count | Source | 281 | 162k | { | 282 | 162k | TLVRecordType resRec(nullptr); // for NRVO optimization | 283 | | | 284 | 162k | if (record.isNull()) | 285 | 0 | return resRec; | 286 | | | 287 | 162k | if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(), | 288 | 162k | tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen - | 289 | 162k | record.getTotalSize())) | 290 | 36.1k | return resRec; | 291 | | | 292 | 126k | resRec.assign(record.getRecordBasePtr() + record.getTotalSize()); | 293 | | | 294 | 126k | if (resRec.getTotalSize() == 0) | 295 | 756 | resRec.assign(nullptr); | 296 | | | 297 | | // resRec pointer is out-bounds of the TLV records memory | 298 | 126k | if ((resRec.getRecordBasePtr() - tlvDataBasePtr) < 0) | 299 | 756 | resRec.assign(nullptr); | 300 | | | 301 | | // resRec pointer is out-bounds of the TLV records memory | 302 | 126k | if (!resRec.isNull() && resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 303 | 3.72k | resRec.assign(nullptr); | 304 | | | 305 | 126k | return resRec; | 306 | 162k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv6TLVOptionHeader::IPv6Option>::getNextTLVRecord(pcpp::IPv6TLVOptionHeader::IPv6Option&, unsigned char const*, unsigned long) const pcpp::TLVRecordReader<pcpp::NdpOption>::getNextTLVRecord(pcpp::NdpOption&, unsigned char const*, unsigned long) const Line | Count | Source | 281 | 150 | { | 282 | 150 | TLVRecordType resRec(nullptr); // for NRVO optimization | 283 | | | 284 | 150 | if (record.isNull()) | 285 | 0 | return resRec; | 286 | | | 287 | 150 | if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(), | 288 | 150 | tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen - | 289 | 150 | record.getTotalSize())) | 290 | 0 | return resRec; | 291 | | | 292 | 150 | resRec.assign(record.getRecordBasePtr() + record.getTotalSize()); | 293 | | | 294 | 150 | if (resRec.getTotalSize() == 0) | 295 | 0 | resRec.assign(nullptr); | 296 | | | 297 | | // resRec pointer is out-bounds of the TLV records memory | 298 | 150 | if ((resRec.getRecordBasePtr() - tlvDataBasePtr) < 0) | 299 | 0 | resRec.assign(nullptr); | 300 | | | 301 | | // resRec pointer is out-bounds of the TLV records memory | 302 | 150 | if (!resRec.isNull() && resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 303 | 74 | resRec.assign(nullptr); | 304 | | | 305 | 150 | return resRec; | 306 | 150 | } |
pcpp::TLVRecordReader<pcpp::NflogTlv>::getNextTLVRecord(pcpp::NflogTlv&, unsigned char const*, unsigned long) const Line | Count | Source | 281 | 4.82k | { | 282 | 4.82k | TLVRecordType resRec(nullptr); // for NRVO optimization | 283 | | | 284 | 4.82k | if (record.isNull()) | 285 | 0 | return resRec; | 286 | | | 287 | 4.82k | if (!TLVRecordType::canAssign(record.getRecordBasePtr() + record.getTotalSize(), | 288 | 4.82k | tlvDataBasePtr - record.getRecordBasePtr() + tlvDataLen - | 289 | 4.82k | record.getTotalSize())) | 290 | 144 | return resRec; | 291 | | | 292 | 4.68k | resRec.assign(record.getRecordBasePtr() + record.getTotalSize()); | 293 | | | 294 | 4.68k | if (resRec.getTotalSize() == 0) | 295 | 720 | resRec.assign(nullptr); | 296 | | | 297 | | // resRec pointer is out-bounds of the TLV records memory | 298 | 4.68k | if ((resRec.getRecordBasePtr() - tlvDataBasePtr) < 0) | 299 | 720 | resRec.assign(nullptr); | 300 | | | 301 | | // resRec pointer is out-bounds of the TLV records memory | 302 | 4.68k | if (!resRec.isNull() && resRec.getRecordBasePtr() + resRec.getTotalSize() > tlvDataBasePtr + tlvDataLen) | 303 | 132 | resRec.assign(nullptr); | 304 | | | 305 | 4.68k | return resRec; | 306 | 4.82k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::PPPoEDiscoveryLayer::PPPoETag>::getNextTLVRecord(pcpp::PPPoEDiscoveryLayer::PPPoETag&, unsigned char const*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::RadiusAttribute>::getNextTLVRecord(pcpp::RadiusAttribute&, unsigned char const*, unsigned long) const |
307 | | |
308 | | /// Search for the first TLV record that corresponds to a given record type (the 'T' in __Type__-Length-Value) |
309 | | /// @param[in] recordType The record type to search for |
310 | | /// @param[in] tlvDataBasePtr A pointer to the TLV data byte stream |
311 | | /// @param[in] tlvDataLen The TLV data byte stream length |
312 | | /// @return An instance of type TLVRecordType that contains the result record. If record was not found a logical |
313 | | /// null instance of TLVRecordType will be returned, meaning TLVRecordType.isNull() will return true |
314 | | TLVRecordType getTLVRecord(uint32_t recordType, uint8_t* tlvDataBasePtr, size_t tlvDataLen) const |
315 | 109k | { |
316 | 109k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); |
317 | 484k | while (!curRec.isNull()) |
318 | 422k | { |
319 | 422k | if (curRec.getType() == recordType) |
320 | 47.9k | { |
321 | 47.9k | return curRec; |
322 | 47.9k | } |
323 | | |
324 | 374k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); |
325 | 374k | } |
326 | | |
327 | 61.2k | curRec.assign(nullptr); |
328 | 61.2k | return curRec; // for NRVO optimization |
329 | 109k | } pcpp::TLVRecordReader<pcpp::DhcpOption>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const Line | Count | Source | 315 | 14.9k | { | 316 | 14.9k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); | 317 | 360k | while (!curRec.isNull()) | 318 | 355k | { | 319 | 355k | if (curRec.getType() == recordType) | 320 | 9.89k | { | 321 | 9.89k | return curRec; | 322 | 9.89k | } | 323 | | | 324 | 345k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); | 325 | 345k | } | 326 | | | 327 | 5.06k | curRec.assign(nullptr); | 328 | 5.06k | return curRec; // for NRVO optimization | 329 | 14.9k | } |
pcpp::TLVRecordReader<pcpp::DhcpV6Option>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const Line | Count | Source | 315 | 850 | { | 316 | 850 | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); | 317 | 4.46k | while (!curRec.isNull()) | 318 | 3.75k | { | 319 | 3.75k | if (curRec.getType() == recordType) | 320 | 148 | { | 321 | 148 | return curRec; | 322 | 148 | } | 323 | | | 324 | 3.61k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); | 325 | 3.61k | } | 326 | | | 327 | 702 | curRec.assign(nullptr); | 328 | 702 | return curRec; // for NRVO optimization | 329 | 850 | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::GtpV2InformationElement>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv4Option>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const pcpp::TLVRecordReader<pcpp::TcpOption>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const Line | Count | Source | 315 | 88.9k | { | 316 | 88.9k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); | 317 | 111k | while (!curRec.isNull()) | 318 | 59.0k | { | 319 | 59.0k | if (curRec.getType() == recordType) | 320 | 36.5k | { | 321 | 36.5k | return curRec; | 322 | 36.5k | } | 323 | | | 324 | 22.4k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); | 325 | 22.4k | } | 326 | | | 327 | 52.4k | curRec.assign(nullptr); | 328 | 52.4k | return curRec; // for NRVO optimization | 329 | 88.9k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv6TLVOptionHeader::IPv6Option>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const pcpp::TLVRecordReader<pcpp::NdpOption>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const Line | Count | Source | 315 | 2.27k | { | 316 | 2.27k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); | 317 | 2.42k | while (!curRec.isNull()) | 318 | 1.41k | { | 319 | 1.41k | if (curRec.getType() == recordType) | 320 | 1.26k | { | 321 | 1.26k | return curRec; | 322 | 1.26k | } | 323 | | | 324 | 150 | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); | 325 | 150 | } | 326 | | | 327 | 1.00k | curRec.assign(nullptr); | 328 | 1.00k | return curRec; // for NRVO optimization | 329 | 2.27k | } |
pcpp::TLVRecordReader<pcpp::NflogTlv>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const Line | Count | Source | 315 | 2.14k | { | 316 | 2.14k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); | 317 | 5.40k | while (!curRec.isNull()) | 318 | 3.40k | { | 319 | 3.40k | if (curRec.getType() == recordType) | 320 | 141 | { | 321 | 141 | return curRec; | 322 | 141 | } | 323 | | | 324 | 3.25k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); | 325 | 3.25k | } | 326 | | | 327 | 2.00k | curRec.assign(nullptr); | 328 | 2.00k | return curRec; // for NRVO optimization | 329 | 2.14k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::PPPoEDiscoveryLayer::PPPoETag>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::RadiusAttribute>::getTLVRecord(unsigned int, unsigned char*, unsigned long) const |
330 | | |
331 | | /// Get the TLV record count in a given TLV data byte stream. For efficiency purposes the count is being cached |
332 | | /// so only the first call to this method will go over all the TLV records, while all consequent calls will |
333 | | /// return the cached number. This implies that if there is a change in the number of records, it's the user's |
334 | | /// responsibility to call changeTLVRecordCount() with the record count change |
335 | | /// @param[in] tlvDataBasePtr A pointer to the TLV data byte stream |
336 | | /// @param[in] tlvDataLen The TLV data byte stream length |
337 | | /// @return The TLV record count |
338 | | size_t getTLVRecordCount(uint8_t* tlvDataBasePtr, size_t tlvDataLen) const |
339 | 259k | { |
340 | 259k | if (m_RecordCount != static_cast<size_t>(-1)) |
341 | 254k | return m_RecordCount; |
342 | | |
343 | 4.93k | m_RecordCount = 0; |
344 | 4.93k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); |
345 | 255k | while (!curRec.isNull()) |
346 | 250k | { |
347 | 250k | m_RecordCount++; |
348 | 250k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); |
349 | 250k | } |
350 | | |
351 | 4.93k | return m_RecordCount; |
352 | 259k | } pcpp::TLVRecordReader<pcpp::DhcpOption>::getTLVRecordCount(unsigned char*, unsigned long) const Line | Count | Source | 339 | 253k | { | 340 | 253k | if (m_RecordCount != static_cast<size_t>(-1)) | 341 | 249k | return m_RecordCount; | 342 | | | 343 | 3.73k | m_RecordCount = 0; | 344 | 3.73k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); | 345 | 249k | while (!curRec.isNull()) | 346 | 245k | { | 347 | 245k | m_RecordCount++; | 348 | 245k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); | 349 | 245k | } | 350 | | | 351 | 3.73k | return m_RecordCount; | 352 | 253k | } |
pcpp::TLVRecordReader<pcpp::DhcpV6Option>::getTLVRecordCount(unsigned char*, unsigned long) const Line | Count | Source | 339 | 6.47k | { | 340 | 6.47k | if (m_RecordCount != static_cast<size_t>(-1)) | 341 | 5.28k | return m_RecordCount; | 342 | | | 343 | 1.19k | m_RecordCount = 0; | 344 | 1.19k | TLVRecordType curRec = getFirstTLVRecord(tlvDataBasePtr, tlvDataLen); | 345 | 5.62k | while (!curRec.isNull()) | 346 | 4.43k | { | 347 | 4.43k | m_RecordCount++; | 348 | 4.43k | curRec = getNextTLVRecord(curRec, tlvDataBasePtr, tlvDataLen); | 349 | 4.43k | } | 350 | | | 351 | 1.19k | return m_RecordCount; | 352 | 6.47k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::GtpV2InformationElement>::getTLVRecordCount(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv4Option>::getTLVRecordCount(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::TcpOption>::getTLVRecordCount(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv6TLVOptionHeader::IPv6Option>::getTLVRecordCount(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::NdpOption>::getTLVRecordCount(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::PPPoEDiscoveryLayer::PPPoETag>::getTLVRecordCount(unsigned char*, unsigned long) const Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::RadiusAttribute>::getTLVRecordCount(unsigned char*, unsigned long) const |
353 | | |
354 | | /// As described in getTLVRecordCount(), the TLV record count is being cached for efficiency purposes. So if the |
355 | | /// number of TLV records change, it's the user's responsibility to call this method with the number of TLV |
356 | | /// records being added or removed. If records were added the change should be a positive number, or a negative |
357 | | /// number if records were removed |
358 | | /// @param[in] changedBy Number of records that were added or removed |
359 | | void changeTLVRecordCount(int changedBy) |
360 | 36.5k | { |
361 | 36.5k | if (m_RecordCount != static_cast<size_t>(-1)) |
362 | 0 | m_RecordCount += changedBy; |
363 | 36.5k | } Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::DhcpOption>::changeTLVRecordCount(int) Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::DhcpV6Option>::changeTLVRecordCount(int) Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::GtpV2InformationElement>::changeTLVRecordCount(int) Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv4Option>::changeTLVRecordCount(int) pcpp::TLVRecordReader<pcpp::TcpOption>::changeTLVRecordCount(int) Line | Count | Source | 360 | 36.5k | { | 361 | 36.5k | if (m_RecordCount != static_cast<size_t>(-1)) | 362 | 0 | m_RecordCount += changedBy; | 363 | 36.5k | } |
Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::IPv6TLVOptionHeader::IPv6Option>::changeTLVRecordCount(int) Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::NdpOption>::changeTLVRecordCount(int) Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::PPPoEDiscoveryLayer::PPPoETag>::changeTLVRecordCount(int) Unexecuted instantiation: pcpp::TLVRecordReader<pcpp::RadiusAttribute>::changeTLVRecordCount(int) |
364 | | }; |
365 | | |
366 | | /// @class TLVRecordBuilder |
367 | | /// A base class for building Type-Length-Value (TLV) records. This builder receives the record parameters in its |
368 | | /// c'tor, builds the record raw buffer and provides a method to build a TLVRecord object out of it. Please notice |
369 | | /// this is a base class that lacks the capability of actually building TLVRecord objects and also cannot be |
370 | | /// instantiated. The reason for that is that different protocols build TLV records in different ways, so these |
371 | | /// missing capabilities will be implemented by the derived classes which are specific to each protocol. This class |
372 | | /// only provides the common infrastructure that will be used by them |
373 | | class TLVRecordBuilder |
374 | | { |
375 | | protected: |
376 | | TLVRecordBuilder(); |
377 | | |
378 | | TLVRecordBuilder(uint32_t recType, const uint8_t* recValue, uint8_t recValueLen); |
379 | | |
380 | | TLVRecordBuilder(uint32_t recType, uint8_t recValue); |
381 | | |
382 | | TLVRecordBuilder(uint32_t recType, uint16_t recValue); |
383 | | |
384 | | TLVRecordBuilder(uint32_t recType, uint32_t recValue); |
385 | | |
386 | | TLVRecordBuilder(uint32_t recType, const IPv4Address& recValue); |
387 | | |
388 | | TLVRecordBuilder(uint32_t recType, const std::string& recValue, bool valueIsHexString = false); |
389 | | |
390 | | TLVRecordBuilder(const TLVRecordBuilder& other); |
391 | | |
392 | | TLVRecordBuilder& operator=(const TLVRecordBuilder& other); |
393 | | |
394 | | virtual ~TLVRecordBuilder(); |
395 | | |
396 | | void init(uint32_t recType, const uint8_t* recValue, size_t recValueLen); |
397 | | |
398 | | uint8_t* m_RecValue; |
399 | | size_t m_RecValueLen; |
400 | | uint32_t m_RecType; |
401 | | |
402 | | private: |
403 | | void copyData(const TLVRecordBuilder& other); |
404 | | }; |
405 | | } // namespace pcpp |