15 typedef pcap_if pcap_if_t;
17 typedef struct pcap_addr pcap_addr_t;
90 pcap_t* m_PcapSendDescriptor;
91 int m_PcapSelectableFd;
98 std::thread m_CaptureThread;
99 std::thread m_StatsThread;
100 bool m_StatsThreadStarted;
103 std::atomic<bool> m_StopThread;
105 std::atomic<bool> m_CaptureThreadStarted;
108 void* m_cbOnPacketArrivesUserCookie;
110 void* m_cbOnStatsUpdateUserCookie;
112 void* m_cbOnPacketArrivesBlockingModeUserCookie;
113 int m_IntervalToUpdateStats;
115 bool m_CaptureCallbackMode;
120 PcapLiveDevice(pcap_if_t* pInterface,
bool calculateMTU,
bool calculateMacAddress,
bool calculateDefaultGateway)
122 calculateDefaultGateway)
124 PcapLiveDevice(DeviceInterfaceDetails interfaceDetails,
bool calculateMTU,
bool calculateMacAddress,
125 bool calculateDefaultGateway);
128 void setDeviceMacAddress();
129 void setDefaultGateway();
132 void captureThreadMain();
133 void statsThreadMain();
135 static void onPacketArrives(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
136 static void onPacketArrivesNoCallback(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
137 static void onPacketArrivesBlockingMode(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
255 return m_InterfaceDetails.
name;
356 void* onStatsUpdateUserCookie);
375 void* onStatsUpdateUserCookie);
416 const double timeout);
460 bool sendPacket(
const uint8_t* packetData,
int packetDataLength,
int packetPayloadLength);
477 bool sendPacket(
const uint8_t* packetData,
int packetDataLength,
bool checkMtu =
false,
Definition: PcapDevice.h:92
Definition: IpAddress.h:28
Definition: IpAddress.h:156
Definition: MacAddress.h:21
Definition: PcapLiveDevice.h:68
PcapDirection
Definition: PcapLiveDevice.h:163
@ PCPP_IN
Only capture incoming traffics.
Definition: PcapLiveDevice.h:167
@ PCPP_OUT
Only capture outgoing traffics.
Definition: PcapLiveDevice.h:169
@ PCPP_INOUT
Capture traffics both incoming and outgoing.
Definition: PcapLiveDevice.h:165
void close() override
Close the device.
LiveDeviceType
The type of the live device.
Definition: PcapLiveDevice.h:142
@ WinPcapDevice
WinPcap/Npcap live device.
Definition: PcapLiveDevice.h:146
@ RemoteDevice
WinPcap/Npcap Remote Capture device.
Definition: PcapLiveDevice.h:148
@ LibPcapDevice
libPcap live device
Definition: PcapLiveDevice.h:144
virtual int startCaptureBlockingMode(OnPacketArrivesStopBlocking onPacketArrives, void *userCookie, const double timeout)
DeviceMode
Device capturing mode.
Definition: PcapLiveDevice.h:153
@ Normal
Only packets that their destination is this NIC are captured.
Definition: PcapLiveDevice.h:155
@ Promiscuous
All packets that arrive to the NIC are captured, even packets that their destination isn't this NIC.
Definition: PcapLiveDevice.h:157
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:272
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:290
bool sendPacket(const uint8_t *packetData, int packetDataLength, int packetPayloadLength)
IPv4Address getDefaultGateway() const
std::string getDesc() const
Definition: PcapLiveDevice.h:260
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:247
virtual bool startCapture(OnPacketArrivesCallback onPacketArrives, void *onPacketArrivesUserCookie, int intervalInSecondsToUpdateStats, OnStatsUpdateCallback onStatsUpdate, void *onStatsUpdateUserCookie)
IPv6Address getIPv6Address() const
virtual bool startCapture(RawPacketVector &capturedPacketsVector)
~PcapLiveDevice() override
A destructor for this class.
std::string getName() const
Definition: PcapLiveDevice.h:253
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:278
bool getLoopback() const
Definition: PcapLiveDevice.h:266
virtual PcapLiveDevice * clone() const
std::vector< IPAddress > getIPAddresses() const
Definition: PcapLiveDevice.h:284
Definition: PcapLiveDeviceList.h:20
Definition: PointerVector.h:50
Definition: RawPacket.h:269
The main namespace for the PcapPlusPlus lib.
std::function< bool(RawPacket *, PcapLiveDevice *, void *)> OnPacketArrivesStopBlocking
Definition: PcapLiveDevice.h:38
std::function< void(RawPacket *, PcapLiveDevice *, void *)> OnPacketArrivesCallback
Definition: PcapLiveDevice.h:31
std::function< void(IPcapDevice::PcapStats &, void *)> OnStatsUpdateCallback
Definition: PcapLiveDevice.h:44
LinkLayerType
Definition: RawPacket.h:25
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:29
Definition: PcapDevice.h:104
Definition: PcapLiveDevice.h:176
int packetBufferTimeoutMs
Definition: PcapLiveDevice.h:183
DeviceConfiguration(DeviceMode mode=Promiscuous, int packetBufferTimeoutMs=0, int packetBufferSize=0, PcapDirection direction=PCPP_INOUT, int snapshotLength=0, unsigned int nflogGroup=0, bool usePoll=false)
Definition: PcapLiveDevice.h:227
int snapshotLength
Definition: PcapLiveDevice.h:202
bool usePoll
In Unix-like system, use poll() for blocking mode.
Definition: PcapLiveDevice.h:209
int packetBufferSize
Definition: PcapLiveDevice.h:191
unsigned int nflogGroup
Definition: PcapLiveDevice.h:206
PcapDirection direction
Definition: PcapLiveDevice.h:195
DeviceMode mode
Indicates whether to open the device in promiscuous or normal mode.
Definition: PcapLiveDevice.h:178
A struct that contains all details of a network interface.
Definition: PcapLiveDevice.h:75
std::string description
Description of the device.
Definition: PcapLiveDevice.h:80
std::string name
Name of the device.
Definition: PcapLiveDevice.h:78
std::vector< IPAddress > addresses
IP addresses associated with the device.
Definition: PcapLiveDevice.h:82
bool isLoopback
Flag to indicate if the device is a loopback device.
Definition: PcapLiveDevice.h:84