Coverage Report

Created: 2024-02-25 06:29

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