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 
12 namespace pcpp
13 {
14 
19 #pragma pack(push, 1)
21  {
23  uint8_t dstMac[6];
25  uint8_t srcMac[6];
27  uint16_t length;
28  };
29 #pragma pack(pop)
30 
35  class EthDot3Layer : public Layer
36  {
37  public:
44  EthDot3Layer(uint8_t* data, size_t dataLen, Packet* packet)
45  : Layer(data, dataLen, nullptr, packet, EthernetDot3)
46  {}
47 
55  EthDot3Layer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
56  : Layer(data, dataLen, prevLayer, packet, EthernetDot3)
57  {}
58 
65  EthDot3Layer(const MacAddress& sourceMac, const MacAddress& destMac, uint16_t length);
66 
67  ~EthDot3Layer() override = default;
68 
75  {
76  return reinterpret_cast<ether_dot3_header*>(m_Data);
77  }
78 
84  {
85  return MacAddress(getEthHeader()->srcMac);
86  }
87 
92  void setSourceMac(const MacAddress& sourceMac)
93  {
94  sourceMac.copyTo(getEthHeader()->srcMac);
95  }
96 
102  {
103  return MacAddress(getEthHeader()->dstMac);
104  }
105 
110  void setDestMac(const MacAddress& destMac)
111  {
112  destMac.copyTo(getEthHeader()->dstMac);
113  }
114 
115  // implement abstract methods
116 
120  void parseNextLayer() override;
121 
125  size_t getHeaderLen() const override
126  {
127  return sizeof(ether_dot3_header);
128  }
129 
133  void computeCalculateFields() override
134  {}
135 
136  std::string toString() const override;
137 
139  {
140  return OsiModelDataLinkLayer;
141  }
142 
149  static bool isDataValid(const uint8_t* data, size_t dataLen);
150  };
151 
152 } // namespace pcpp
Definition: EthDot3Layer.h:36
EthDot3Layer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: EthDot3Layer.h:55
size_t getHeaderLen() const override
Definition: EthDot3Layer.h:125
void setDestMac(const MacAddress &destMac)
Definition: EthDot3Layer.h:110
MacAddress getSourceMac() const
Definition: EthDot3Layer.h:83
EthDot3Layer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: EthDot3Layer.h:44
MacAddress getDestMac() const
Definition: EthDot3Layer.h:101
std::string toString() const override
OsiModelLayer getOsiModelLayer() const override
Definition: EthDot3Layer.h:138
static bool isDataValid(const uint8_t *data, size_t dataLen)
void computeCalculateFields() override
Definition: EthDot3Layer.h:133
EthDot3Layer(const MacAddress &sourceMac, const MacAddress &destMac, uint16_t length)
void setSourceMac(const MacAddress &sourceMac)
Definition: EthDot3Layer.h:92
void parseNextLayer() override
ether_dot3_header * getEthHeader() const
Definition: EthDot3Layer.h:74
Definition: Layer.h:69
Definition: MacAddress.h:25
void copyTo(uint8_t **arr) const
Definition: MacAddress.h:152
Definition: Packet.h:27
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelDataLinkLayer
Definition: ProtocolType.h:368
const ProtocolType EthernetDot3
Definition: ProtocolType.h:228
Definition: EthDot3Layer.h:21
uint16_t length
Definition: EthDot3Layer.h:27
uint8_t srcMac[6]
Definition: EthDot3Layer.h:25
uint8_t dstMac[6]
Definition: EthDot3Layer.h:23