wol.h
Go to the documentation of this file.
1 /*
2  * rcdiscover - the network discovery tool for Roboception devices
3  *
4  * Copyright (c) 2017 Roboception GmbH
5  * All rights reserved
6  *
7  * Author: Raphael Schaller
8  *
9  * Redistribution and use in source and binary forms, with or without
10  * modification, are permitted provided that the following conditions are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright notice,
13  * this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright notice,
16  * this list of conditions and the following disclaimer in the documentation
17  * and/or other materials provided with the distribution.
18  *
19  * 3. Neither the name of the copyright holder nor the names of its contributors
20  * may be used to endorse or promote products derived from this software without
21  * specific prior written permission.
22  *
23  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
24  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
27  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
28  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
29  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
30  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
31  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
32  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
33  * POSSIBILITY OF SUCH DAMAGE.
34  */
35 
36 #ifndef RCDISCOVER_WOL_H
37 #define RCDISCOVER_WOL_H
38 
39 #include <array>
40 #include <vector>
41 #include <memory>
42 #include <cstdint>
43 
44 #ifdef WIN32
45 #include <winsock2.h>
46 #else
47 #include <netinet/in.h>
48 #endif
49 
50 namespace rcdiscover
51 {
52 
53 #ifdef WIN32
54 class SocketWindows;
55 #else
56 class SocketLinux;
57 #endif
58 
62 class WOL
63 {
64  private:
65 #ifdef WIN32
66  typedef SocketWindows SocketType;
67 #else
69 #endif
70 
71  public:
77  WOL(uint64_t hardware_addr, uint16_t port) noexcept;
78 
84  WOL(std::array<uint8_t, 6> hardware_addr, uint16_t port) noexcept;
85  ~WOL() = default;
86 
87  public:
91  void send() const;
92 
97  void send(const std::array<uint8_t, 4>& password) const;
98 
99  private:
107  std::vector<uint8_t>& appendMagicPacket(
108  std::vector<uint8_t>& sendbuf,
109  const std::array<uint8_t, 4> *password) const;
110 
114  template<uint8_t num>
115  std::array<uint8_t, num> toByteArray(uint64_t data) noexcept;
116 
121  void sendImpl(const std::array<uint8_t, 4> *password) const;
122 
123  private:
124  const std::array<uint8_t, 6> hardware_addr_;
125  uint16_t port_;
126 };
127 
128 }
129 
130 #endif // RCDISCOVER_WOL_H
~WOL()=default
std::vector< uint8_t > & appendMagicPacket(std::vector< uint8_t > &sendbuf, const std::array< uint8_t, 4 > *password) const
Appends a magic packet to a data buffer.
Definition: wol.cc:69
Class for Magic Packet (Wake-on-Lan (WOL)) reset of device.
Definition: wol.h:62
WOL(uint64_t hardware_addr, uint16_t port) noexcept
Constructor.
Definition: wol.cc:49
std::array< uint8_t, num > toByteArray(uint64_t data) noexcept
Converts a larger-than-byte data type to an array of bytes.
Definition: wol.cc:96
uint16_t port_
Definition: wol.h:125
Socket implementation for Linux.
Definition: socket_linux.h:51
void sendImpl(const std::array< uint8_t, 4 > *password) const
sendImpl Actually send Magic packet with specified data.
Definition: wol.cc:106
SocketLinux SocketType
Definition: wol.h:68
const std::array< uint8_t, 6 > hardware_addr_
Definition: wol.h:124
void send() const
Send Magic Packet without any data ("password").
Definition: wol.cc:59


rcdiscover
Author(s): Heiko Hirschmueller , Raphael Schaller
autogenerated on Sun Apr 18 2021 02:16:32