PcapPlusPlus  23.09
WakeOnLanLayer.h
Go to the documentation of this file.
1 #ifndef PACKETPP_WAKEONLAN_LAYER
2 #define PACKETPP_WAKEONLAN_LAYER
3 
4 #include "IpAddress.h"
5 #include "Layer.h"
6 #include "MacAddress.h"
7 
9 
14 namespace pcpp
15 {
19  class WakeOnLanLayer : public Layer
20  {
21  private:
22  void init(uint16_t len);
23 
24  public:
29 #pragma pack(push, 1)
30  struct wol_header
31  {
33  uint8_t sync[6];
35  uint8_t addrBody[6 * 16];
36  };
37 #pragma pack(pop)
38 
46  WakeOnLanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
47  : Layer(data, dataLen, prevLayer, packet)
48  {
49  m_Protocol = WakeOnLan;
50  }
51 
56  explicit WakeOnLanLayer(const pcpp::MacAddress &targetAddr);
57 
64  WakeOnLanLayer(const pcpp::MacAddress &targetAddr, uint8_t *password, uint8_t len);
65 
71  WakeOnLanLayer(const pcpp::MacAddress &targetAddr, const pcpp::MacAddress &password);
72 
78  WakeOnLanLayer(const pcpp::MacAddress &targetAddr, const IPv4Address &password);
79 
85  inline wol_header *getWakeOnLanHeader() const { return (wol_header *)m_Data; }
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) { return (port == 0) || (port == 7) || (port == 9); }
139 
146  static bool isDataValid(const uint8_t *data, size_t dataSize);
147 
148  // overridden methods
149 
151  void parseNextLayer() {}
152 
156  size_t getHeaderLen() const { return m_DataLen; }
157 
160 
165 
169  std::string toString() const;
170  };
171 } // namespace pcpp
172 
173 #endif /* PACKETPP_WAKEONLAN_LAYER */
The main namespace for the PcapPlusPlus lib.
OsiModelLayer
Definition: ProtocolType.h:333
WakeOnLanLayer(uint8_t *data, size_t dataLen, Layer *prevLayer, Packet *packet)
Definition: WakeOnLanLayer.h:46
void setTargetAddr(const pcpp::MacAddress &targetAddr)
Definition: ProtocolType.h:338
Definition: Layer.h:70
uint8_t addrBody[6 *16]
Target MAC address repeated 16 times.
Definition: WakeOnLanLayer.h:35
Definition: Packet.h:26
const ProtocolType WakeOnLan
Definition: ProtocolType.h:293
std::string toString() const
wol_header * getWakeOnLanHeader() const
Definition: WakeOnLanLayer.h:85
std::string getPassword() const
Definition: IpAddress.h:42
Definition: WakeOnLanLayer.h:30
uint8_t sync[6]
Sync stream (FF FF FF FF FF FF)
Definition: WakeOnLanLayer.h:33
bool setPassword(const uint8_t *password, uint8_t len)
Definition: WakeOnLanLayer.h:19
size_t getHeaderLen() const
Definition: WakeOnLanLayer.h:156
OsiModelLayer getOsiModelLayer() const
Definition: WakeOnLanLayer.h:164
void parseNextLayer()
Parses the next layer. Wake on LAN is the always last so does nothing for this layer.
Definition: WakeOnLanLayer.h:151
static bool isWakeOnLanPort(uint16_t port)
Definition: WakeOnLanLayer.h:138
static bool isDataValid(const uint8_t *data, size_t dataSize)
pcpp::MacAddress getTargetAddr() const
Definition: MacAddress.h:28
void computeCalculateFields()
Does nothing for this layer.
Definition: WakeOnLanLayer.h:159