PcapPlusPlus  Next
WakeOnLanLayer.h
Go to the documentation of this file.
1 #pragma once
2 
3 #include "IpAddress.h"
4 #include "Layer.h"
5 #include "MacAddress.h"
6 
8 
13 namespace pcpp
14 {
18  class WakeOnLanLayer : public Layer
19  {
20  private:
21  void init(uint16_t len);
22 
23  public:
28 #pragma pack(push, 1)
29  struct wol_header
30  {
32  uint8_t sync[6];
34  uint8_t addrBody[6 * 16];
35  };
36 #pragma pack(pop)
37 
45  WakeOnLanLayer(uint8_t* data, size_t dataLen, Layer* prevLayer, Packet* packet)
46  : Layer(data, dataLen, prevLayer, packet, WakeOnLan)
47  {}
48 
53  explicit WakeOnLanLayer(const pcpp::MacAddress& targetAddr);
54 
61  WakeOnLanLayer(const pcpp::MacAddress& targetAddr, uint8_t* password, uint8_t len);
62 
68  WakeOnLanLayer(const pcpp::MacAddress& targetAddr, const pcpp::MacAddress& password);
69 
75  WakeOnLanLayer(const pcpp::MacAddress& targetAddr, const IPv4Address& password);
76 
83  {
84  return reinterpret_cast<wol_header*>(m_Data);
85  }
86 
92 
97  void setTargetAddr(const pcpp::MacAddress& targetAddr);
98 
103  std::string getPassword() const;
104 
111  bool setPassword(const uint8_t* password, uint8_t len);
112 
118  bool setPassword(const std::string& password);
119 
125  bool setPassword(const MacAddress& addr);
126 
132  bool setPassword(const IPv4Address& addr);
133 
138  static bool isWakeOnLanPort(uint16_t port)
139  {
140  return (port == 0) || (port == 7) || (port == 9);
141  }
142 
149  static bool isDataValid(const uint8_t* data, size_t dataSize);
150 
151  // overridden methods
152 
154  void parseNextLayer() override
155  {}
156 
160  size_t getHeaderLen() const override
161  {
162  return m_DataLen;
163  }
164 
166  void computeCalculateFields() override
167  {}
168 
173  {
174  return OsiModelDataLinkLayer;
175  }
176 
180  std::string toString() const override;
181  };
182 } // namespace pcpp
Definition: IpAddress.h:32
Definition: Layer.h:69
Definition: MacAddress.h:25
Definition: Packet.h:27
Definition: WakeOnLanLayer.h:19
WakeOnLanLayer(const pcpp::MacAddress &targetAddr, const IPv4Address &password)
std::string toString() const override
OsiModelLayer getOsiModelLayer() const override
Definition: WakeOnLanLayer.h:172
void computeCalculateFields() override
Does nothing for this layer.
Definition: WakeOnLanLayer.h:166
pcpp::MacAddress getTargetAddr() const
bool setPassword(const uint8_t *password, uint8_t len)
bool setPassword(const std::string &password)
WakeOnLanLayer(const pcpp::MacAddress &targetAddr)
wol_header * getWakeOnLanHeader() const
Definition: WakeOnLanLayer.h:82
static bool isDataValid(const uint8_t *data, size_t dataSize)
size_t getHeaderLen() const override
Definition: WakeOnLanLayer.h:160
WakeOnLanLayer(const pcpp::MacAddress &targetAddr, uint8_t *password, uint8_t len)
bool setPassword(const MacAddress &addr)
bool setPassword(const IPv4Address &addr)
WakeOnLanLayer(const pcpp::MacAddress &targetAddr, const pcpp::MacAddress &password)
void setTargetAddr(const pcpp::MacAddress &targetAddr)
static bool isWakeOnLanPort(uint16_t port)
Definition: WakeOnLanLayer.h:138
std::string getPassword() const
WakeOnLanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: WakeOnLanLayer.h:45
void parseNextLayer() override
Parses the next layer. Wake on LAN is the always last so does nothing for this layer.
Definition: WakeOnLanLayer.h:154
The main namespace for the PcapPlusPlus lib.
const ProtocolType WakeOnLan
Definition: ProtocolType.h:298
OsiModelLayer
Definition: ProtocolType.h:364
@ OsiModelDataLinkLayer
Definition: ProtocolType.h:368
Definition: WakeOnLanLayer.h:30
uint8_t sync[6]
Sync stream (FF FF FF FF FF FF)
Definition: WakeOnLanLayer.h:32
uint8_t addrBody[6 *16]
Target MAC address repeated 16 times.
Definition: WakeOnLanLayer.h:34