PcapPlusPlus  19.12
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_PUP 0x0200
35 
36 #define PCPP_ETHERTYPE_SPRITE 0x0500
37 
38 #define PCPP_ETHERTYPE_IP 0x0800
39 
40 #define PCPP_ETHERTYPE_ARP 0x0806
41 
42 #define PCPP_ETHERTYPE_REVARP 0x8035
43 
44 #define PCPP_ETHERTYPE_AT 0x809B
45 
46 #define PCPP_ETHERTYPE_AARP 0x80F3
47 
48 #define PCPP_ETHERTYPE_VLAN 0x8100
49 
50 #define PCPP_ETHERTYPE_IPX 0x8137
51 
52 #define PCPP_ETHERTYPE_IPV6 0x86dd
53 
54 #define PCPP_ETHERTYPE_LOOPBACK 0x9000
55 
56 #define PCPP_ETHERTYPE_PPPOED 0x8863
57 
58 #define PCPP_ETHERTYPE_PPPOES 0x8864
59 
60 #define PCPP_ETHERTYPE_MPLS 0x8847
61 
62 #define PCPP_ETHERTYPE_PPP 0x880B
63 
64 
69  class EthLayer : public Layer
70  {
71  public:
78  EthLayer(uint8_t* data, size_t dataLen, Packet* packet) : Layer(data, dataLen, NULL, packet) { m_Protocol = Ethernet; }
79 
87  EthLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet) : Layer(data, dataLen, prevLayer, packet) { m_Protocol = Ethernet; }
88 
95  EthLayer(const MacAddress& sourceMac, const MacAddress& destMac, uint16_t etherType = 0);
96 
97  ~EthLayer() {}
98 
103  ether_header* getEthHeader() const { return (ether_header*)m_Data; }
104 
109  MacAddress getSourceMac() const { return MacAddress(getEthHeader()->srcMac); }
110 
115  void setSourceMac(const MacAddress& sourceMac) { sourceMac.copyTo(getEthHeader()->srcMac); }
116 
121  MacAddress getDestMac() const { return MacAddress(getEthHeader()->dstMac); }
122 
127  void setDestMac(const MacAddress& destMac) { destMac.copyTo(getEthHeader()->dstMac); }
128 
129  // implement abstract methods
130 
136  void parseNextLayer();
137 
141  size_t getHeaderLen() const { return sizeof(ether_header); }
142 
146  void computeCalculateFields();
147 
148  std::string toString() const;
149 
151  };
152 
153 } // namespace pcpp
154 
155 #endif /* PACKETPP_ETH_LAYER */
pcpp::EthLayer::getOsiModelLayer
OsiModelLayer getOsiModelLayer() const
Definition: EthLayer.h:150
pcpp::OsiModelLayer
OsiModelLayer
Definition: ProtocolType.h:224
pcpp::EthLayer::EthLayer
EthLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: EthLayer.h:87
pcpp::Packet
Definition: Packet.h:26
pcpp::EthLayer::getDestMac
MacAddress getDestMac() const
Definition: EthLayer.h:121
pcpp::EthLayer::computeCalculateFields
void computeCalculateFields()
pcpp::OsiModelDataLinkLayer
Definition: ProtocolType.h:229
pcpp::EthLayer::parseNextLayer
void parseNextLayer()
Layer.h
MacAddress.h
pcpp::ether_header::srcMac
uint8_t srcMac[6]
Definition: EthLayer.h:25
pcpp::MacAddress::copyTo
void copyTo(uint8_t **arr) const
Definition: MacAddress.h:143
pcpp::MacAddress
Definition: MacAddress.h:27
pcpp::EthLayer::getHeaderLen
size_t getHeaderLen() const
Definition: EthLayer.h:141
pcpp::EthLayer::setDestMac
void setDestMac(const MacAddress &destMac)
Definition: EthLayer.h:127
pcpp::ether_header::etherType
uint16_t etherType
Definition: EthLayer.h:27
pcpp::ether_header
Definition: EthLayer.h:21
pcpp::EthLayer::EthLayer
EthLayer(uint8_t *data, size_t dataLen, Packet *packet)
Definition: EthLayer.h:78
pcpp
The main namespace for the PcapPlusPlus lib.
pcpp::EthLayer::getSourceMac
MacAddress getSourceMac() const
Definition: EthLayer.h:109
pcpp::Layer
Definition: Layer.h:70
pcpp::EthLayer
Definition: EthLayer.h:69
pcpp::ether_header::dstMac
uint8_t dstMac[6]
Definition: EthLayer.h:23
pcpp::EthLayer::toString
std::string toString() const
pcpp::EthLayer::setSourceMac
void setSourceMac(const MacAddress &sourceMac)
Definition: EthLayer.h:115
pcpp::Ethernet
Definition: ProtocolType.h:26
pcpp::EthLayer::getEthHeader
ether_header * getEthHeader() const
Definition: EthLayer.h:103