13 typedef pcap_if pcap_if_t;
15 typedef struct pcap_addr pcap_addr_t;
88 pcap_t* m_PcapSendDescriptor;
89 int m_PcapSelectableFd;
96 std::thread m_CaptureThread;
97 std::thread m_StatsThread;
98 bool m_StatsThreadStarted;
101 std::atomic<bool> m_StopThread;
103 std::atomic<bool> m_CaptureThreadStarted;
106 void* m_cbOnPacketArrivesUserCookie;
108 void* m_cbOnStatsUpdateUserCookie;
110 void* m_cbOnPacketArrivesBlockingModeUserCookie;
111 int m_IntervalToUpdateStats;
113 bool m_CaptureCallbackMode;
118 PcapLiveDevice(pcap_if_t* pInterface,
bool calculateMTU,
bool calculateMacAddress,
bool calculateDefaultGateway)
120 calculateDefaultGateway)
122 PcapLiveDevice(DeviceInterfaceDetails interfaceDetails,
bool calculateMTU,
bool calculateMacAddress,
123 bool calculateDefaultGateway);
126 void setDeviceMacAddress();
127 void setDefaultGateway();
130 void captureThreadMain();
131 void statsThreadMain();
133 static void onPacketArrives(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
134 static void onPacketArrivesNoCallback(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
135 static void onPacketArrivesBlockingMode(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
297 return m_InterfaceDetails.
name;
398 void* onStatsUpdateUserCookie);
417 void* onStatsUpdateUserCookie);
458 const double timeout);
502 bool sendPacket(
const uint8_t* packetData,
int packetDataLength,
int packetPayloadLength);
519 bool sendPacket(
const uint8_t* packetData,
int packetDataLength,
bool checkMtu =
false,
606 bool isNflogDevice()
const;
Definition: PcapDevice.h:104
Definition: IpAddress.h:28
Definition: IpAddress.h:156
Definition: MacAddress.h:21
Definition: PcapLiveDevice.h:66
PcapDirection
Definition: PcapLiveDevice.h:161
@ PCPP_IN
Only capture incoming traffics.
Definition: PcapLiveDevice.h:165
@ PCPP_OUT
Only capture outgoing traffics.
Definition: PcapLiveDevice.h:167
@ PCPP_INOUT
Capture traffics both incoming and outgoing.
Definition: PcapLiveDevice.h:163
void close() override
Close the device.
LiveDeviceType
The type of the live device.
Definition: PcapLiveDevice.h:140
@ WinPcapDevice
WinPcap/Npcap live device.
Definition: PcapLiveDevice.h:144
@ RemoteDevice
WinPcap/Npcap Remote Capture device.
Definition: PcapLiveDevice.h:146
@ LibPcapDevice
libPcap live device
Definition: PcapLiveDevice.h:142
virtual int startCaptureBlockingMode(OnPacketArrivesStopBlocking onPacketArrives, void *userCookie, const double timeout)
DeviceMode
Device capturing mode.
Definition: PcapLiveDevice.h:151
@ Normal
Only packets that their destination is this NIC are captured.
Definition: PcapLiveDevice.h:153
@ Promiscuous
All packets that arrive to the NIC are captured, even packets that their destination isn't this NIC.
Definition: PcapLiveDevice.h:155
virtual bool startCapture(int intervalInSecondsToUpdateStats, OnStatsUpdateCallback onStatsUpdate, void *onStatsUpdateUserCookie)
bool sendPacket(RawPacket const &rawPacket, bool checkMtu=false)
virtual uint32_t getMtu() const
Definition: PcapLiveDevice.h:314
virtual bool startCapture(OnPacketArrivesCallback onPacketArrives, void *onPacketArrivesUserCookie)
void getStatistics(IPcapDevice::PcapStats &stats) const override
bool open(const DeviceConfiguration &config)
bool doMtuCheck(int packetPayloadLength) const
virtual MacAddress getMacAddress() const
Definition: PcapLiveDevice.h:332
bool sendPacket(const uint8_t *packetData, int packetDataLength, int packetPayloadLength)
IPv4Address getDefaultGateway() const
std::string getDesc() const
Definition: PcapLiveDevice.h:302
bool sendPacket(const uint8_t *packetData, int packetDataLength, bool checkMtu=false, pcpp::LinkLayerType linkType=pcpp::LINKTYPE_ETHERNET)
const std::vector< IPv4Address > & getDnsServers() const
virtual int sendPackets(Packet **packetsArr, int arrLength, bool checkMtu=true)
virtual LiveDeviceType getDeviceType() const
Definition: PcapLiveDevice.h:289
virtual bool startCapture(OnPacketArrivesCallback onPacketArrives, void *onPacketArrivesUserCookie, int intervalInSecondsToUpdateStats, OnStatsUpdateCallback onStatsUpdate, void *onStatsUpdateUserCookie)
TimestampPrecision
Definition: PcapLiveDevice.h:191
@ Microseconds
use timestamps with microsecond precision, default
@ Nanoseconds
use timestamps with nanosecond precision
IPv6Address getIPv6Address() const
virtual bool startCapture(RawPacketVector &capturedPacketsVector)
~PcapLiveDevice() override
A destructor for this class.
std::string getName() const
Definition: PcapLiveDevice.h:295
IPv4Address getIPv4Address() const
bool sendPacket(Packet *packet, bool checkMtu=true)
virtual int sendPackets(const RawPacketVector &rawPackets, bool checkMtu=false)
virtual int sendPackets(RawPacket *rawPacketsArr, int arrLength, bool checkMtu=false)
virtual LinkLayerType getLinkType() const
Definition: PcapLiveDevice.h:320
TimestampProvider
Definition: PcapLiveDevice.h:173
@ AdapterUnsynced
device-provided, not synced with the system clock
@ HostLowPrecision
host-provided, low precision, synced with the system clock
@ Adapter
device-provided, synced with the system clock
@ HostHighPrecision
host-provided, high precision, synced with the system clock
@ Host
host-provided, unknown characteristics, default
@ HostHighPrecisionUnsynced
host-provided, high precision, not synced with the system clock
bool getLoopback() const
Definition: PcapLiveDevice.h:308
virtual PcapLiveDevice * clone() const
std::vector< IPAddress > getIPAddresses() const
Definition: PcapLiveDevice.h:326
Definition: PcapLiveDeviceList.h:20
Definition: PointerVector.h:50
Definition: RawPacket.h:259
A wrapper class for pcap_t* which is the libpcap packet capture descriptor. This class is used to man...
Definition: PcapDevice.h:25
The main namespace for the PcapPlusPlus lib.
std::function< bool(RawPacket *, PcapLiveDevice *, void *)> OnPacketArrivesStopBlocking
Definition: PcapLiveDevice.h:36
std::function< void(RawPacket *, PcapLiveDevice *, void *)> OnPacketArrivesCallback
Definition: PcapLiveDevice.h:29
std::function< void(IPcapDevice::PcapStats &, void *)> OnStatsUpdateCallback
Definition: PcapLiveDevice.h:42
LinkLayerType
An enum describing all known link layer type. Taken from: http://www.tcpdump.org/linktypes....
Definition: RawPacket.h:20
@ LINKTYPE_ETHERNET
IEEE 802.3 Ethernet.
Definition: RawPacket.h:24
Definition: PcapDevice.h:116
Definition: PcapLiveDevice.h:202
int packetBufferTimeoutMs
Definition: PcapLiveDevice.h:209
int snapshotLength
Definition: PcapLiveDevice.h:228
TimestampProvider timestampProvider
Definition: PcapLiveDevice.h:239
DeviceConfiguration(DeviceMode mode=Promiscuous, int packetBufferTimeoutMs=0, int packetBufferSize=0, PcapDirection direction=PCPP_INOUT, int snapshotLength=0, unsigned int nflogGroup=0, bool usePoll=false, TimestampProvider timestampProvider=TimestampProvider::Host, TimestampPrecision timestampPrecision=TimestampPrecision::Microseconds)
Definition: PcapLiveDevice.h:265
bool usePoll
In Unix-like system, use poll() for blocking mode.
Definition: PcapLiveDevice.h:235
int packetBufferSize
Definition: PcapLiveDevice.h:217
unsigned int nflogGroup
Definition: PcapLiveDevice.h:232
PcapDirection direction
Definition: PcapLiveDevice.h:221
TimestampPrecision timestampPrecision
Definition: PcapLiveDevice.h:243
DeviceMode mode
Indicates whether to open the device in promiscuous or normal mode.
Definition: PcapLiveDevice.h:204
A struct that contains all details of a network interface.
Definition: PcapLiveDevice.h:73
std::string description
Description of the device.
Definition: PcapLiveDevice.h:78
std::string name
Name of the device.
Definition: PcapLiveDevice.h:76
std::vector< IPAddress > addresses
IP addresses associated with the device.
Definition: PcapLiveDevice.h:80
bool isLoopback
Flag to indicate if the device is a loopback device.
Definition: PcapLiveDevice.h:82