Rabbit Remote Control 0.0.30
Loading...
Searching...
No Matches
WakeOnLanQt.cpp
1// Author: Kang Lin <kl222@126.com>
2
3#include "WakeOnLanQt.h"
4
5#include <QLoggingCategory>
6#include <QUdpSocket>
7
8static Q_LOGGING_CATEGORY(log, "WOL")
9CWakeOnLanQt::CWakeOnLanQt(const QString &szBroadcastAddress, QObject *parent)
10 : QObject(parent), CWakeOnLan(szBroadcastAddress.toStdString())
11{}
12
13void CWakeOnLanQt::SetBroadcastAddress(const QString &szBroadcastAddress)
14{
15 CWakeOnLan::SetBroadcastAddress(szBroadcastAddress.toStdString());
16}
17
18QString CWakeOnLanQt::SetBroadcastAddress(
19 const QString &szIP, const QString &szMask)
20{
21 return CWakeOnLan::SetBroadcastAddress(
22 szIP.toStdString(), szMask.toStdString()).c_str();
23}
24
25bool CWakeOnLanQt::SendMagicPacket(const QString &szMac, uint16_t portNum) {
26 return CWakeOnLan::SendMagicPacket(szMac.toStdString(), portNum);
27}
28
29bool CWakeOnLanQt::SendSecureMagicPacket(const QString &szMac,
30 const QString &szPassword,
31 uint16_t portNum) {
32 if(szPassword.length() < 6) {
33 qCritical(log) << "The password must be 6. current length:"
34 << szPassword.length();
35 return false;
36 }
37 // character
38 if(szPassword.length() == 6) {
39 QByteArray data = szPassword.toLocal8Bit().toHex(':');
40 return SendSecureMagicPacket(szMac.toStdString().c_str(),
41 data.data(), portNum);
42 }
43 // Hexadecimal characters
44 return CWakeOnLan::SendSecureMagicPacket(szMac.toStdString(),
45 szPassword.toStdString(), portNum);
46}
47
48int CWakeOnLanQt::SendPacket(const char *data, int64_t size,
49 std::string addr, uint16_t port)
50{
51 // Send the packet via UDP
52 QUdpSocket udpSocket;
53 int nRet = udpSocket.writeDatagram(data, size,
54 QHostAddress(addr.c_str()), port);
55 return nRet;
56}
bool SendMagicPacket(const QString &szMac, uint16_t portNum=9)
SendMagicPacket.
bool SendSecureMagicPacket(const QString &szMac, const QString &szPassword, uint16_t portNum=9)
SendSecureMagicPacket.
bool SendSecureMagicPacket(const std::string &szMac, const std::string szPassword, uint16_t portNum=9)
SendSecureMagicPacket.
Definition WakeOnLan.cpp:70
bool SendMagicPacket(const std::string &szMac, uint16_t portNum=9)
SendMagicPacket.
Definition WakeOnLan.cpp:66