PcapPlusPlus  21.11
EthLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_ETH_LAYER
2 #define PACKETPP_ETH_LAYER
3 
4 #include "Layer.h"
5 #include "MacAddress.h"
6 
8 
13 namespace pcpp
14 {
15 
20 #pragma pack(push, 1)
21  struct ether_header
22  {
24  uint8_t dstMac[6];
26  uint8_t srcMac[6];
28  uint16_t etherType;
29  };
30 #pragma pack(pop)
31 
32  /* Ethernet protocol ID's */
33 
35 #define PCPP_ETHERTYPE_IP 0x0800
36 
37 #define PCPP_ETHERTYPE_ARP 0x0806
38 
39 #define PCPP_ETHERTYPE_ETHBRIDGE 0x6558
40 
41 #define PCPP_ETHERTYPE_REVARP 0x8035
42 
43 #define PCPP_ETHERTYPE_AT 0x809B
44 
45 #define PCPP_ETHERTYPE_AARP 0x80F3
46 
47 #define PCPP_ETHERTYPE_VLAN 0x8100
48 
49 #define PCPP_ETHERTYPE_IPX 0x8137
50 
51 #define PCPP_ETHERTYPE_IPV6 0x86dd
52 
53 #define PCPP_ETHERTYPE_LOOPBACK 0x9000
54 
55 #define PCPP_ETHERTYPE_PPPOED 0x8863
56 
57 #define PCPP_ETHERTYPE_PPPOES 0x8864
58 
59 #define PCPP_ETHERTYPE_MPLS 0x8847
60 
61 #define PCPP_ETHERTYPE_PPP 0x880B
62 
63 #define PCPP_ETHERTYPE_ROCEV1 0x8915
64 
65 #define PCPP_ETHERTYPE_IEEE_802_1AD 0x88A8
66 
67 
72  class EthLayer : public Layer
73  {
74  public:
81  EthLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, NULL, packet) { m_Protocol = Ethernet; }
82 
90  EthLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = Ethernet; }
91 
98  EthLayer(const MacAddress& sourceMac, const MacAddress& destMac, uint16_t etherType = 0);
99 
100  ~EthLayer() {}
101 
106  ether_header* getEthHeader() const { return (ether_header*)m_Data; }
107 
112  MacAddress getSourceMac() const { return MacAddress(getEthHeader()->srcMac); }
113 
118  void setSourceMac(const MacAddress& sourceMac) { sourceMac.copyTo(getEthHeader()->srcMac); }
119 
124  MacAddress getDestMac() const { return MacAddress(getEthHeader()->dstMac); }
125 
130  void setDestMac(const MacAddress& destMac) { destMac.copyTo(getEthHeader()->dstMac); }
131 
132  // implement abstract methods
133 
139  void parseNextLayer();
140 
144  size_t getHeaderLen() const { return sizeof(ether_header); }
145 
149  void computeCalculateFields();
150 
151  std::string toString() const;
152 
154 
161  static bool isDataValid(const uint8_t* data, size_t dataLen);
162  };
163 
164 } // namespace pcpp
165 
166 #endif /* PACKETPP_ETH_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:258
size_t getHeaderLen() const
Definition: EthLayer.h:144
uint16_t etherType
Definition: EthLayer.h:28
EthLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: EthLayer.h:90
uint8_t dstMac[6]
Definition: EthLayer.h:24
Definition: ProtocolType.h:263
Definition: Layer.h:70
EthLayer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: EthLayer.h:81
Definition: Packet.h:26
OsiModelLayer getOsiModelLayer() const
Definition: EthLayer.h:153
ether_header * getEthHeader() const
Definition: EthLayer.h:106
void copyTo(uint8_t **arr) const
Definition: MacAddress.h:146
Definition: EthLayer.h:72
const ProtocolType Ethernet
Definition: ProtocolType.h:28
uint8_t srcMac[6]
Definition: EthLayer.h:26
MacAddress getSourceMac() const
Definition: EthLayer.h:112
MacAddress getDestMac() const
Definition: EthLayer.h:124
Definition: EthLayer.h:21
Definition: MacAddress.h:28
void setSourceMac(const MacAddress &sourceMac)
Definition: EthLayer.h:118
void setDestMac(const MacAddress &destMac)
Definition: EthLayer.h:130