PcapPlusPlus  20.08+
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 {
23  uint8_t dstMac[6];
25  uint8_t srcMac[6];
27  uint16_t etherType;
28  };
29 #pragma pack(pop)
30 
31  /* Ethernet protocol ID's */
32 
34 #define PCPP_ETHERTYPE_IP 0x0800
35 
36 #define PCPP_ETHERTYPE_ARP 0x0806
37 
38 #define PCPP_ETHERTYPE_REVARP 0x8035
39 
40 #define PCPP_ETHERTYPE_AT 0x809B
41 
42 #define PCPP_ETHERTYPE_AARP 0x80F3
43 
44 #define PCPP_ETHERTYPE_VLAN 0x8100
45 
46 #define PCPP_ETHERTYPE_IPX 0x8137
47 
48 #define PCPP_ETHERTYPE_IPV6 0x86dd
49 
50 #define PCPP_ETHERTYPE_LOOPBACK 0x9000
51 
52 #define PCPP_ETHERTYPE_PPPOED 0x8863
53 
54 #define PCPP_ETHERTYPE_PPPOES 0x8864
55 
56 #define PCPP_ETHERTYPE_MPLS 0x8847
57 
58 #define PCPP_ETHERTYPE_PPP 0x880B
59 
60 
65  class EthLayer : public Layer
66  {
67  public:
74  EthLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, NULL, packet) { m_Protocol = Ethernet; }
75 
83  EthLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = Ethernet; }
84 
91  EthLayer(const MacAddress& sourceMac, const MacAddress& destMac, uint16_t etherType = 0);
92 
93  ~EthLayer() {}
94 
99  ether_header* getEthHeader() const { return (ether_header*)m_Data; }
100 
105  MacAddress getSourceMac() const { return MacAddress(getEthHeader()->srcMac); }
106 
111  void setSourceMac(const MacAddress& sourceMac) { sourceMac.copyTo(getEthHeader()->srcMac); }
112 
117  MacAddress getDestMac() const { return MacAddress(getEthHeader()->dstMac); }
118 
123  void setDestMac(const MacAddress& destMac) { destMac.copyTo(getEthHeader()->dstMac); }
124 
125  // implement abstract methods
126 
132  void parseNextLayer();
133 
137  size_t getHeaderLen() const { return sizeof(ether_header); }
138 
142  void computeCalculateFields();
143 
144  std::string toString() const;
145 
147  };
148 
149 } // namespace pcpp
150 
151 #endif /* PACKETPP_ETH_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:233
size_t getHeaderLen() const
Definition: EthLayer.h:137
uint16_t etherType
Definition: EthLayer.h:27
EthLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: EthLayer.h:83
uint8_t dstMac[6]
Definition: EthLayer.h:23
Definition: ProtocolType.h:238
Definition: Layer.h:70
EthLayer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: EthLayer.h:74
Definition: Packet.h:26
OsiModelLayer getOsiModelLayer() const
Definition: EthLayer.h:146
ether_header * getEthHeader() const
Definition: EthLayer.h:99
void copyTo(uint8_t **arr) const
Definition: MacAddress.h:143
Definition: EthLayer.h:65
const ProtocolType Ethernet
Definition: ProtocolType.h:28
uint8_t srcMac[6]
Definition: EthLayer.h:25
MacAddress getSourceMac() const
Definition: EthLayer.h:105
MacAddress getDestMac() const
Definition: EthLayer.h:117
Definition: EthLayer.h:21
Definition: MacAddress.h:27
void setSourceMac(const MacAddress &sourceMac)
Definition: EthLayer.h:111
void setDestMac(const MacAddress &destMac)
Definition: EthLayer.h:123