PcapPlusPlus  24.09
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 (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 
155  {}
156 
160  size_t getHeaderLen() const
161  {
162  return m_DataLen;
163  }
164 
167  {}
168 
173  {
174  return OsiModelDataLinkLayer;
175  }
176 
180  std::string toString() const;
181  };
182 } // namespace pcpp
Definition: IpAddress.h:32
Definition: Layer.h:70
Definition: MacAddress.h:25
Definition: Packet.h:27
Definition: WakeOnLanLayer.h:19
WakeOnLanLayer(const pcpp::MacAddress &targetAddr, const IPv4Address &password)
pcpp::MacAddress getTargetAddr() const
bool setPassword(const uint8_t *password, uint8_t len)
size_t getHeaderLen() const
Definition: WakeOnLanLayer.h:160
bool setPassword(const std::string &password)
void parseNextLayer()
Parses the next layer. Wake on LAN is the always last so does nothing for this layer.
Definition: WakeOnLanLayer.h:154
WakeOnLanLayer(const pcpp::MacAddress &targetAddr)
wol_header * getWakeOnLanHeader() const
Definition: WakeOnLanLayer.h:82
void computeCalculateFields()
Does nothing for this layer.
Definition: WakeOnLanLayer.h:166
static bool isDataValid(const uint8_t *data, size_t dataSize)
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)
std::string toString() const
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
OsiModelLayer getOsiModelLayer() const
Definition: WakeOnLanLayer.h:172
The main namespace for the PcapPlusPlus lib.
const ProtocolType WakeOnLan
Definition: ProtocolType.h:298
OsiModelLayer
Definition: ProtocolType.h:354
@ OsiModelDataLinkLayer
Definition: ProtocolType.h:358
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