Resolve build issues with new pcap driver
parent
3aaccaad74
commit
bead22bc36
|
|
@ -84,7 +84,7 @@ protected:
|
||||||
|
|
||||||
virtual void setupDecoder(Decoder& decoder) override {
|
virtual void setupDecoder(Decoder& decoder) override {
|
||||||
Device::setupDecoder(decoder);
|
Device::setupDecoder(decoder);
|
||||||
decoder.timestampMultiplier = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
decoder.timestampResolution = 10; // Timestamps are in 10ns increments instead of the usual 25ns
|
||||||
}
|
}
|
||||||
|
|
||||||
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
virtual void setupSupportedRXNetworks(std::vector<Network>& rxNetworks) override {
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,6 @@ public:
|
||||||
bool isOpen();
|
bool isOpen();
|
||||||
bool close();
|
bool close();
|
||||||
private:
|
private:
|
||||||
device_errorhandler_t err;
|
|
||||||
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
|
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
|
||||||
neodevice_t& device;
|
neodevice_t& device;
|
||||||
uint8_t deviceMAC[6];
|
uint8_t deviceMAC[6];
|
||||||
|
|
@ -38,8 +37,8 @@ private:
|
||||||
public:
|
public:
|
||||||
uint8_t uuid;
|
uint8_t uuid;
|
||||||
uint8_t macAddress[8];
|
uint8_t macAddress[8];
|
||||||
std::string nameFromWinPCAP;
|
std::string nameFromPCAP;
|
||||||
std::string descriptionFromWinPCAP;
|
std::string descriptionFromPCAP;
|
||||||
std::string fullName;
|
std::string fullName;
|
||||||
pcap_t* fp = nullptr;
|
pcap_t* fp = nullptr;
|
||||||
pcap_stat stats;
|
pcap_stat stats;
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@ std::vector<PCAP::NetworkInterface> PCAP::knownInterfaces;
|
||||||
std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
||||||
std::vector<PCAPFoundDevice> foundDevices;
|
std::vector<PCAPFoundDevice> foundDevices;
|
||||||
|
|
||||||
// First we ask WinPCAP to give us all of the devices
|
// First we ask libpcap to give us all of the devices
|
||||||
pcap_if_t* alldevs;
|
pcap_if_t* alldevs;
|
||||||
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
|
char errbuf[PCAP_ERRBUF_SIZE] = { 0 };
|
||||||
bool success = false;
|
bool success = false;
|
||||||
|
|
@ -46,9 +46,9 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
NetworkInterface netif;
|
NetworkInterface netif;
|
||||||
netif.nameFromWinPCAP = dev->name;
|
netif.nameFromPCAP = dev->name;
|
||||||
if(dev->description)
|
if(dev->description)
|
||||||
netif.descriptionFromWinPCAP = dev->description;
|
netif.descriptionFromPCAP = dev->description;
|
||||||
pcap_addr* currentAddress = dev->addresses;
|
pcap_addr* currentAddress = dev->addresses;
|
||||||
bool hasAddress = false;
|
bool hasAddress = false;
|
||||||
while(!hasAddress && currentAddress != nullptr) {
|
while(!hasAddress && currentAddress != nullptr) {
|
||||||
|
|
@ -80,19 +80,19 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
||||||
|
|
||||||
for(size_t i = 0; i < knownInterfaces.size(); i++) {
|
for(size_t i = 0; i < knownInterfaces.size(); i++) {
|
||||||
auto& interface = knownInterfaces[i];
|
auto& interface = knownInterfaces[i];
|
||||||
// if(interface.fullName.length() == 0)
|
|
||||||
// continue; // Win32 did not find this interface in the previous step
|
|
||||||
|
|
||||||
errbuf[0] = '\0';
|
errbuf[0] = '\0';
|
||||||
interface.fp = pcap_open_live(interface.nameFromWinPCAP.c_str(), UINT16_MAX, 1, 0, errbuf);
|
interface.fp = pcap_open_live(interface.nameFromPCAP.c_str(), UINT16_MAX, 1, 0, errbuf);
|
||||||
if(strlen(errbuf) != 0) { // This means a warning
|
if(interface.fp == nullptr) {
|
||||||
std::cout << "Warning for " << interface.nameFromWinPCAP << " " << errbuf << std::endl;
|
// TODO Flag error that interface could not be opened?
|
||||||
|
// This can happen if, on Linux, you are not running as root
|
||||||
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(interface.fp == nullptr) {
|
// TODO Propagate this up
|
||||||
std::cout << "pcap_open_live failed for " << interface.nameFromWinPCAP << " with " << errbuf << std::endl;
|
// if(strlen(errbuf) != 0) { // The open succeeded but we got a warning
|
||||||
continue; // Could not open the interface
|
// std::cout << "Warning for " << interface.nameFromPCAP << " " << errbuf << std::endl;
|
||||||
}
|
// }
|
||||||
|
|
||||||
pcap_setnonblock(interface.fp, 1, errbuf);
|
pcap_setnonblock(interface.fp, 1, errbuf);
|
||||||
|
|
||||||
|
|
@ -167,7 +167,7 @@ bool PCAP::IsHandleValid(neodevice_handle_t handle) {
|
||||||
return (netifIndex < knownInterfaces.size());
|
return (netifIndex < knownInterfaces.size());
|
||||||
}
|
}
|
||||||
|
|
||||||
PCAP::PCAP(device_errorhandler_t err, neodevice_t& forDevice) : err(err), device(forDevice) {
|
PCAP::PCAP(device_errorhandler_t err, neodevice_t& forDevice) : ICommunication(err), device(forDevice) {
|
||||||
if(IsHandleValid(device.handle)) {
|
if(IsHandleValid(device.handle)) {
|
||||||
interface = knownInterfaces[(device.handle >> 24) & 0xFF];
|
interface = knownInterfaces[(device.handle >> 24) & 0xFF];
|
||||||
interface.fp = nullptr; // We're going to open our own connection to the interface. This should already be nullptr but just in case.
|
interface.fp = nullptr; // We're going to open our own connection to the interface. This should already be nullptr but just in case.
|
||||||
|
|
@ -191,7 +191,7 @@ bool PCAP::open() {
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
// Open the interface
|
// Open the interface
|
||||||
interface.fp = pcap_open_live(interface.nameFromWinPCAP.c_str(), INT16_MAX, 1, 0, errbuf);
|
interface.fp = pcap_open_live(interface.nameFromPCAP.c_str(), INT16_MAX, 1, 0, errbuf);
|
||||||
if(interface.fp == nullptr) {
|
if(interface.fp == nullptr) {
|
||||||
err(APIError::DriverFailedToOpen);
|
err(APIError::DriverFailedToOpen);
|
||||||
return false;
|
return false;
|
||||||
|
|
@ -277,6 +277,7 @@ void PCAP::writeTask() {
|
||||||
if(!closing)
|
if(!closing)
|
||||||
pcap_sendpacket(interface.fp, bs.data(), (int)bs.size());
|
pcap_sendpacket(interface.fp, bs.data(), (int)bs.size());
|
||||||
// TODO Handle packet send errors
|
// TODO Handle packet send errors
|
||||||
|
onWrite();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue