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