| 113 | } |
| 114 | |
| 115 | int 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(ðLayer)) |
| 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 | |
| 151 | static void cbArpPacketReceived(pcpp::RawPacket* rawPacket, |
| 152 | pcpp::PcapLiveDevice*, void* userCookie) |
nothing calls this directly
no test coverage detected