/src/PcapPlusPlus/Packet++/header/PacketTrailerLayer.h
Line | Count | Source (jump to first uncovered line) |
1 | | #pragma once |
2 | | |
3 | | /// @file |
4 | | |
5 | | #include "Layer.h" |
6 | | |
7 | | namespace pcpp |
8 | | { |
9 | | /** |
10 | | * @class PacketTrailerLayer |
11 | | * A class for representing packet tailer (a.k.a footer or padding) which refers to supplemental data placed at the end of a block of data |
12 | | * being stored or transmitted, which may contain information for the handling of the data block, or just mark its end |
13 | | * (taken from Wikipedia: https://en.wikipedia.org/wiki/Trailer_(computing) ) |
14 | | * |
15 | | * There are various reasons for adding a packet trailer, one of the most famous is FCS (Frame check sequence) which refers to the extra |
16 | | * error-detecting code added to a frame. Another usage is padding which means adding data to reach a minimum required packet length. |
17 | | * |
18 | | * Although this layer inherits from the Layer class, it is not a standard layer in the sense that it can't be constructed by the user. |
19 | | * This layer may be only be constructed in the Packet class, in the process of parsing the packet and creating the layers; if at the end |
20 | | * of the parsing process there is data left that is not allocated to any layer, it's assumed to be the packet trailer and an instance of |
21 | | * this class is created. This means this layer can only exist as the last layer in a packet, if a packet trailer indeed exists. |
22 | | * |
23 | | * No layer can be added by the user after this layer (trying to do that will result with an error). |
24 | | * |
25 | | * This layer can be removed by the user or extended/shortened, as any layer. |
26 | | * |
27 | | * It also contains method to extract the trailer data |
28 | | */ |
29 | | class PacketTrailerLayer : public Layer |
30 | | { |
31 | | public: |
32 | | /** A constructor that creates the layer from an existing packet raw data |
33 | | * @param[in] data A pointer to the raw data |
34 | | * @param[in] dataLen Size of the data in bytes |
35 | | * @param[in] prevLayer A pointer to the previous layer |
36 | | * @param[in] packet A pointer to the Packet instance where layer will be stored in |
37 | | */ |
38 | 23.7k | PacketTrailerLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = PacketTrailer; } |
39 | | |
40 | 0 | ~PacketTrailerLayer() {} |
41 | | |
42 | | /** |
43 | | * Get a pointer to the trailer data |
44 | | * @return A pointer to the trailer data |
45 | | */ |
46 | 0 | uint8_t* getTrailerData() const { return m_Data; } |
47 | | |
48 | | /** |
49 | | * @return Trailer data as hex string |
50 | | */ |
51 | | std::string getTrailerDataAsHexString() const; |
52 | | |
53 | | /** |
54 | | * Get the trailer data length |
55 | | * @return The trailer data length in bytes |
56 | | */ |
57 | 0 | size_t getTrailerLen() const { return m_DataLen; } |
58 | | |
59 | | // implement abstract methods |
60 | | |
61 | | /** |
62 | | * Does nothing for this layer (PacketTrailerLayer is always last) |
63 | | */ |
64 | 0 | void parseNextLayer() {} |
65 | | |
66 | | /** |
67 | | * @return trailer data length in bytes |
68 | | */ |
69 | 55.6k | size_t getHeaderLen() const { return m_DataLen; } |
70 | | |
71 | | /** |
72 | | * Does nothing for this layer |
73 | | */ |
74 | 23.7k | void computeCalculateFields() {} |
75 | | |
76 | | std::string toString() const; |
77 | | |
78 | 0 | OsiModelLayer getOsiModelLayer() const { return OsiModelDataLinkLayer; } |
79 | | }; |
80 | | |
81 | | } |