PcapPlusPlus  Next
EthDot3Layer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "Layer.h"
4 #include "MacAddress.h"
5 
7 
10 namespace pcpp
11 {
12 
15 #pragma pack(push, 1)
17  {
19  uint8_t dstMac[6];
21  uint8_t srcMac[6];
23  uint16_t length;
24  };
25 #pragma pack(pop)
26  static_assert(sizeof(ether_dot3_header) == 14, "ether_dot3_header size is not 14 bytes");
27 
30  class EthDot3Layer : public Layer
31  {
32  public:
37  EthDot3Layer(uint8_t* data, size_t dataLen, Packet* packet)
38  : Layer(data, dataLen, nullptr, packet, EthernetDot3)
39  {}
40 
46  EthDot3Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
47  : Layer(data, dataLen, prevLayer, packet, EthernetDot3)
48  {}
49 
54  EthDot3Layer(const MacAddress& sourceMac, const MacAddress& destMac, uint16_t length);
55 
56  ~EthDot3Layer() override = default;
57 
62  {
63  return reinterpret_cast<ether_dot3_header*>(m_Data);
64  }
65 
69  {
70  return MacAddress(getEthHeader()->srcMac);
71  }
72 
75  void setSourceMac(const MacAddress& sourceMac)
76  {
77  sourceMac.copyTo(getEthHeader()->srcMac);
78  }
79 
83  {
84  return MacAddress(getEthHeader()->dstMac);
85  }
86 
89  void setDestMac(const MacAddress& destMac)
90  {
91  destMac.copyTo(getEthHeader()->dstMac);
92  }
93 
94  // implement abstract methods
95 
97  void parseNextLayer() override;
98 
100  size_t getHeaderLen() const override
101  {
102  return sizeof(ether_dot3_header);
103  }
104 
106  void computeCalculateFields() override
107  {}
108 
109  std::string toString() const override;
110 
112  {
113  return OsiModelDataLinkLayer;
114  }
115 
120  static bool isDataValid(const uint8_t* data, size_t dataLen);
121  };
122 
123 } // namespace pcpp
Definition: EthDot3Layer.h:31
EthDot3Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: EthDot3Layer.h:46
size_t getHeaderLen() const override
Definition: EthDot3Layer.h:100
void setDestMac(const MacAddress &destMac)
Definition: EthDot3Layer.h:89
MacAddress getSourceMac() const
Definition: EthDot3Layer.h:68
EthDot3Layer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: EthDot3Layer.h:37
MacAddress getDestMac() const
Definition: EthDot3Layer.h:82
std::string toString() const override
OsiModelLayer getOsiModelLayer() const override
Definition: EthDot3Layer.h:111
static bool isDataValid(const uint8_t *data, size_t dataLen)
void computeCalculateFields() override
Does nothing for this layer.
Definition: EthDot3Layer.h:106
EthDot3Layer(const MacAddress &sourceMac, const MacAddress &destMac, uint16_t length)
void setSourceMac(const MacAddress &sourceMac)
Definition: EthDot3Layer.h:75
void parseNextLayer() override
Parses next layer.
ether_dot3_header * getEthHeader() const
Definition: EthDot3Layer.h:61
Definition: Layer.h:60
Definition: MacAddress.h:21
void copyTo(uint8_t **arr) const
Definition: MacAddress.h:130
Definition: Packet.h:22
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
An enum representing OSI model layers.
Definition: ProtocolType.h:225
@ OsiModelDataLinkLayer
Data link layer (layer 2)
Definition: ProtocolType.h:229
const ProtocolType EthernetDot3
IEEE 802.3 Ethernet protocol.
Definition: ProtocolType.h:140
Definition: EthDot3Layer.h:17
uint16_t length
EtherType.
Definition: EthDot3Layer.h:23
uint8_t srcMac[6]
Source MAC.
Definition: EthDot3Layer.h:21
uint8_t dstMac[6]
Destination MAC.
Definition: EthDot3Layer.h:19