| 40 | } |
| 41 | |
| 42 | int CArp::WakeOnLan(QSharedPointer<CParameterWakeOnLan> para) |
| 43 | { |
| 44 | int nRet = 0; |
| 45 | |
| 46 | if(!para) |
| 47 | return -1; |
| 48 | |
| 49 | if(para->GetMac().isEmpty()) |
| 50 | { |
| 51 | qCritical(log) << "The mac address is empty"; |
| 52 | return -2; |
| 53 | } |
| 54 | #ifdef HAVE_PCAPPLUSPLUS |
| 55 | auto it = m_Para.find(para->m_Net.GetHost().toStdString()); |
| 56 | if(it != m_Para.end()) |
| 57 | { |
| 58 | if((*it)->bWakeOnLan) { |
| 59 | qDebug(log) << "The wake on lan is existed" |
| 60 | << (*it)->para->m_Net.GetHost(); |
| 61 | return 0; |
| 62 | } |
| 63 | } |
| 64 | |
| 65 | m_Wol.SetBroadcastAddress(para->GetBroadcastAddress()); |
| 66 | if(para->GetPassword().isEmpty()) |
| 67 | m_Wol.SendMagicPacket(para->GetMac()); |
| 68 | else |
| 69 | m_Wol.SendSecureMagicPacket(para->GetMac(), para->GetPassword()); |
| 70 | |
| 71 | #if defined(Q_OS_UNIX) |
| 72 | if(RabbitCommon::CTools::HasAdministratorPrivilege()) |
| 73 | { |
| 74 | QSharedPointer<ArpRequest> aq(new ArpRequest(para)); |
| 75 | if(!aq) { |
| 76 | qCritical(log) << "new ArpRequest fail"; |
| 77 | return -3; |
| 78 | } |
| 79 | aq->bWakeOnLan = true; |
| 80 | nRet = GetMac(para, aq); |
| 81 | } |
| 82 | #else |
| 83 | QSharedPointer<ArpRequest> aq(new ArpRequest(para)); |
| 84 | if(!aq) { |
| 85 | qCritical(log) << "new ArpRequest fail"; |
| 86 | return -3; |
| 87 | } |
| 88 | aq->bWakeOnLan = true; |
| 89 | nRet = GetMac(para, aq); |
| 90 | #endif |
| 91 | |
| 92 | #else |
| 93 | qDebug(log) << "There is not pcapplusplus"; |
| 94 | #endif |
| 95 | return nRet; |
| 96 | } |
| 97 | |
| 98 | #ifdef HAVE_PCAPPLUSPLUS |
| 99 | int CArp::StopCapture() |
no test coverage detected