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