POSIX: PCAP: Enable if permissions are set, with a warning otherwise
On Linux, raw packet capture requires CAP_NET_RAW (or root). If we can't capture raw packets, we will not be able to find/connect to devices over ethernet.pull/32/head
parent
a460e27657
commit
9dc4b302ef
|
|
@ -5,13 +5,13 @@
|
||||||
#include "icsneo/device/tree/neoobd2pro/neoobd2pro.h"
|
#include "icsneo/device/tree/neoobd2pro/neoobd2pro.h"
|
||||||
#include "icsneo/device/tree/neoobd2sim/neoobd2sim.h"
|
#include "icsneo/device/tree/neoobd2sim/neoobd2sim.h"
|
||||||
#include "icsneo/device/tree/neovifire/neovifire.h"
|
#include "icsneo/device/tree/neovifire/neovifire.h"
|
||||||
//#include "icsneo/device/tree/neovifire2/neovifire2eth.h"
|
#include "icsneo/device/tree/neovifire2/neovifire2eth.h"
|
||||||
#include "icsneo/device/tree/neovifire2/neovifire2usb.h"
|
#include "icsneo/device/tree/neovifire2/neovifire2usb.h"
|
||||||
#include "icsneo/device/tree/plasion/neoviion.h"
|
#include "icsneo/device/tree/plasion/neoviion.h"
|
||||||
#include "icsneo/device/tree/plasion/neoviplasma.h"
|
#include "icsneo/device/tree/plasion/neoviplasma.h"
|
||||||
//#include "icsneo/device/tree/radgalaxy/radgalaxy.h"
|
#include "icsneo/device/tree/radgalaxy/radgalaxy.h"
|
||||||
#include "icsneo/device/tree/radpluto/radplutousb.h"
|
#include "icsneo/device/tree/radpluto/radplutousb.h"
|
||||||
//#include "icsneo/device/tree/radstar2/radstar2eth.h"
|
#include "icsneo/device/tree/radstar2/radstar2eth.h"
|
||||||
#include "icsneo/device/tree/radstar2/radstar2usb.h"
|
#include "icsneo/device/tree/radstar2/radstar2usb.h"
|
||||||
#include "icsneo/device/tree/radsupermoon/radsupermoon.h"
|
#include "icsneo/device/tree/radsupermoon/radsupermoon.h"
|
||||||
#include "icsneo/device/tree/valuecan3/valuecan3.h"
|
#include "icsneo/device/tree/valuecan3/valuecan3.h"
|
||||||
|
|
|
||||||
|
|
@ -4,7 +4,6 @@
|
||||||
#include "icsneo/communication/packetizer.h"
|
#include "icsneo/communication/packetizer.h"
|
||||||
#include <codecvt>
|
#include <codecvt>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <iostream>
|
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <sys/socket.h>
|
#include <sys/socket.h>
|
||||||
|
|
@ -20,6 +19,7 @@ static const uint8_t ICS_UNSET_MAC[6] = { 0x00, 0xFC, 0x70, 0xFF, 0xFF, 0xFF };
|
||||||
std::vector<PCAP::NetworkInterface> PCAP::knownInterfaces;
|
std::vector<PCAP::NetworkInterface> PCAP::knownInterfaces;
|
||||||
|
|
||||||
std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
||||||
|
static bool warned = false; // Only warn once for failure to open devices
|
||||||
std::vector<PCAPFoundDevice> foundDevices;
|
std::vector<PCAPFoundDevice> foundDevices;
|
||||||
|
|
||||||
// First we ask WinPCAP to give us all of the devices
|
// First we ask WinPCAP to give us all of the devices
|
||||||
|
|
@ -92,12 +92,17 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
||||||
|
|
||||||
errbuf[0] = '\0';
|
errbuf[0] = '\0';
|
||||||
interface.fp = pcap_open_live(interface.nameFromWinPCAP.c_str(), 65536, 1, -1, errbuf);
|
interface.fp = pcap_open_live(interface.nameFromWinPCAP.c_str(), 65536, 1, -1, errbuf);
|
||||||
if(strlen(errbuf) != 0) { // This means a warning
|
// TODO Handle warnings
|
||||||
std::cout << "Warning for " << interface.nameFromWinPCAP << " " << errbuf << std::endl;
|
// if(strlen(errbuf) != 0) { // This means a warning
|
||||||
}
|
// std::cout << "Warning for " << interface.nameFromWinPCAP << " " << errbuf << std::endl;
|
||||||
|
// }
|
||||||
|
|
||||||
if(interface.fp == nullptr) {
|
if(interface.fp == nullptr) {
|
||||||
std::cout << "pcap_open_live failed for " << interface.nameFromWinPCAP << " with " << errbuf << std::endl;
|
if (!warned) {
|
||||||
|
warned = true;
|
||||||
|
EventManager::GetInstance().add(APIEvent::Type::PCAPCouldNotFindDevices, APIEvent::Severity::EventWarning);
|
||||||
|
// std::cout << "pcap_open_live failed for " << interface.nameFromWinPCAP << " with " << errbuf << std::endl;
|
||||||
|
}
|
||||||
continue; // Could not open the interface
|
continue; // Could not open the interface
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -122,7 +127,11 @@ std::vector<PCAP::PCAPFoundDevice> PCAP::FindAll() {
|
||||||
const uint8_t* data;
|
const uint8_t* data;
|
||||||
auto res = pcap_next_ex(interface.fp, &header, &data);
|
auto res = pcap_next_ex(interface.fp, &header, &data);
|
||||||
if(res < 0) {
|
if(res < 0) {
|
||||||
std::cout << "pcapnextex failed with " << res << std::endl;
|
if (!warned) {
|
||||||
|
warned = true;
|
||||||
|
EventManager::GetInstance().add(APIEvent::Type::PCAPCouldNotFindDevices, APIEvent::Severity::EventWarning);
|
||||||
|
// std::cout << "pcapnextex failed with " << res << std::endl;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
if(res == 0)
|
if(res == 0)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue