Coverage Report

Created: 2023-01-17 06:15

/src/PcapPlusPlus/Packet++/header/SllLayer.h
Line
Count
Source (jump to first uncovered line)
1
#ifndef PACKETPP_SLL_LAYER
2
#define PACKETPP_SLL_LAYER
3
4
#include "MacAddress.h"
5
#include "Layer.h"
6
7
/// @file
8
9
/**
10
 * \namespace pcpp
11
 * \brief The main namespace for the PcapPlusPlus lib
12
 */
13
namespace pcpp
14
{
15
16
  /**
17
   * @struct sll_header
18
   * Represents SLL header
19
   */
20
#pragma pack(push, 1)
21
  struct sll_header
22
  {
23
    /** Specifies whether packet was: specifically sent to us by somebody else (value=0);
24
     *  broadcast by somebody else (value=1); multicast, but not broadcast, by somebody else (value=2);
25
     *  sent to somebody else by somebody else (value=3); sent by us (value=4)
26
     **/
27
    uint16_t packet_type;
28
    /** Contains a Linux ARPHRD_ value for the link-layer device type */
29
    uint16_t ARPHRD_type;
30
    /** Contains the length of the link-layer address of the sender of the packet. That length could be zero */
31
    uint16_t link_layer_addr_len;
32
    /** contains the link-layer address of the sender of the packet; the number of bytes of that field that are
33
     *  meaningful is specified by the link-layer address length field
34
     **/
35
    uint8_t link_layer_addr[8];
36
    /** Contains an Ethernet protocol type of the next layer */
37
    uint16_t protocol_type;
38
  };
39
#pragma pack(pop)
40
41
  /**
42
   * @class SllLayer
43
   * Represents an SLL (Linux cooked capture) protocol layer
44
   */
45
  class SllLayer : public Layer
46
  {
47
  public:
48
    /**
49
     * A constructor that creates the layer from an existing packet raw data
50
     * @param[in] data A pointer to the raw data (will be casted to ether_header)
51
     * @param[in] dataLen Size of the data in bytes
52
     * @param[in] packet A pointer to the Packet instance where layer will be stored in
53
     */
54
8.22k
    SllLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, NULL, packet) { m_Protocol = SLL; }
55
56
    /**
57
     * A constructor that creates a new SLL header and allocates the data
58
     * @param[in] packetType The packet type
59
     * @param[in] ARPHRDType The ARPHRD type
60
     */
61
    SllLayer(uint16_t packetType, uint16_t ARPHRDType);
62
63
0
    ~SllLayer() {}
64
65
    /**
66
     * Get a pointer to the Sll header. Notice this points directly to the data, so every change will change the actual packet data
67
     * @return A pointer to the sll_header
68
     */
69
6.18k
    sll_header* getSllHeader() const { return (sll_header*)m_Data; }
70
71
    /**
72
     * A setter for the link layer address field
73
     * @param[in] addr The address to set. Memory will be copied to packet
74
     * @param[in] addrLength Address length, must be lower or equal to 8 (which is max length for SLL address)
75
     * @return True if address was set successfully, or false of addrLength is out of bounds (0 or larger than 8)
76
     */
77
    bool setLinkLayerAddr(uint8_t* addr, size_t addrLength);
78
79
    /**
80
     * Set a MAC address in the link layer address field
81
     * @param[in] macAddr MAC address to set
82
     * @return True if address was set successfully, false if MAC address isn't valid or if set failed
83
     */
84
    bool setMacAddressAsLinkLayer(MacAddress macAddr);
85
86
    /**
87
     * Currently identifies the following next layers: IPv4Layer, IPv6Layer, ArpLayer, VlanLayer, PPPoESessionLayer, PPPoEDiscoveryLayer,
88
     * MplsLayer.
89
     * Otherwise sets PayloadLayer
90
     */
91
    void parseNextLayer();
92
93
    /**
94
     * @return Size of sll_header
95
     */
96
0
    size_t getHeaderLen() const { return sizeof(sll_header); }
97
98
    /**
99
     * Calculate the next protocol type for known protocols: IPv4, IPv6, ARP, VLAN
100
     */
101
    void computeCalculateFields();
102
103
    std::string toString() const;
104
105
8.22k
    OsiModelLayer getOsiModelLayer() const { return OsiModelDataLinkLayer; }
106
  };
107
108
} // namespace pcpp
109
110
#endif /* PACKETPP_SLL_LAYER */