MCPcopy Create free account
hub / github.com/KangLin/RabbitRemoteControl / SendArpPackage

Method SendArpPackage

Plugins/WakeOnLan/Arp.cpp:115–149  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

113}
114
115int CArp::SendArpPackage(pcpp::PcapLiveDevice* device,
116 std::string szSourceIp, std::string szTargetIp)
117{
118 pcpp::MacAddress sourceMac;
119 pcpp::IPv4Address sourceIP(szSourceIp);
120 pcpp::IPv4Address targetIP(szTargetIp);
121
122 if(!device || szSourceIp.empty() || szTargetIp.empty())
123 return -1;
124 if(!pcpp::IPv4Address::isValidIPv4Address(szSourceIp))
125 sourceIP = device->getIPv4Address();
126 sourceMac = device->getMacAddress();
127
128 // create an ARP request from sourceMac and sourceIP and ask for target IP
129 pcpp::Packet arpRequest(100);
130 pcpp::MacAddress destMac(0xff, 0xff, 0xff, 0xff, 0xff, 0xff);
131 pcpp::EthLayer ethLayer(sourceMac, destMac);
132 pcpp::ArpLayer arpLayer(pcpp::ARP_REQUEST,
133 sourceMac, destMac, sourceIP, targetIP);
134 if (!arpRequest.addLayer(&ethLayer))
135 {
136 qCritical(log) << "Couldn't build Eth layer for ARP request";
137 return -2;
138 }
139 if (!arpRequest.addLayer(&arpLayer))
140 {
141 qCritical(log) << "Couldn't build ARP layer for ARP request";
142 return -3;
143 }
144 arpRequest.computeCalculateFields();
145 // send the ARP request
146 bool bRet = device->sendPacket(&arpRequest);
147 if(bRet) return 0;
148 return -4;
149}
150
151static void cbArpPacketReceived(pcpp::RawPacket* rawPacket,
152 pcpp::PcapLiveDevice*, void* userCookie)

Callers

nothing calls this directly

Calls 1

sendPacketMethod · 0.80

Tested by

no test coverage detected