15 typedef pcap_if pcap_if_t;
17 typedef struct pcap_addr pcap_addr_t;
101 pcap_t* m_PcapSendDescriptor;
102 int m_PcapSelectableFd;
106 uint32_t m_DeviceMtu;
109 std::thread m_CaptureThread;
110 std::thread m_StatsThread;
111 bool m_StatsThreadStarted;
114 std::atomic<bool> m_StopThread;
116 std::atomic<bool> m_CaptureThreadStarted;
119 void* m_cbOnPacketArrivesUserCookie;
121 void* m_cbOnStatsUpdateUserCookie;
123 void* m_cbOnPacketArrivesBlockingModeUserCookie;
124 int m_IntervalToUpdateStats;
126 bool m_CaptureCallbackMode;
131 PcapLiveDevice(pcap_if_t* pInterface,
bool calculateMTU,
bool calculateMacAddress,
bool calculateDefaultGateway)
133 calculateDefaultGateway)
135 PcapLiveDevice(DeviceInterfaceDetails interfaceDetails,
bool calculateMTU,
bool calculateMacAddress,
136 bool calculateDefaultGateway);
139 void setDeviceMacAddress();
140 void setDefaultGateway();
143 void captureThreadMain();
144 void statsThreadMain();
146 static void onPacketArrives(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
147 static void onPacketArrivesNoCallback(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
148 static void onPacketArrivesBlockingMode(uint8_t* user,
const struct pcap_pkthdr* pkthdr,
const uint8_t* packet);
290 return m_InterfaceDetails.
name;
415 void* onStatsUpdateUserCookie);
436 void* onStatsUpdateUserCookie);
480 const double timeout);
534 bool sendPacket(
const uint8_t* packetData,
int packetDataLength,
int packetPayloadLength);
553 bool sendPacket(
const uint8_t* packetData,
int packetDataLength,
bool checkMtu =
false,
Definition: PcapDevice.h:114
Definition: IpAddress.h:32
Definition: IpAddress.h:199
Definition: MacAddress.h:25
Definition: PcapLiveDevice.h:79
PcapDirection
Definition: PcapLiveDevice.h:180
@ PCPP_IN
Definition: PcapLiveDevice.h:184
@ PCPP_OUT
Definition: PcapLiveDevice.h:186
@ PCPP_INOUT
Definition: PcapLiveDevice.h:182
LiveDeviceType
Definition: PcapLiveDevice.h:155
@ WinPcapDevice
Definition: PcapLiveDevice.h:159
@ RemoteDevice
Definition: PcapLiveDevice.h:161
@ LibPcapDevice
Definition: PcapLiveDevice.h:157
virtual int startCaptureBlockingMode(OnPacketArrivesStopBlocking onPacketArrives, void *userCookie, const double timeout)
DeviceMode
Definition: PcapLiveDevice.h:168
@ Normal
Definition: PcapLiveDevice.h:170
@ Promiscuous
Definition: PcapLiveDevice.h:172
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:313
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:337
bool sendPacket(const uint8_t *packetData, int packetDataLength, int packetPayloadLength)
IPv4Address getDefaultGateway() const
std::string getDesc() const
Definition: PcapLiveDevice.h:297
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:280
virtual bool startCapture(OnPacketArrivesCallback onPacketArrives, void *onPacketArrivesUserCookie, int intervalInSecondsToUpdateStats, OnStatsUpdateCallback onStatsUpdate, void *onStatsUpdateUserCookie)
IPv6Address getIPv6Address() const
virtual bool startCapture(RawPacketVector &capturedPacketsVector)
~PcapLiveDevice() override
std::string getName() const
Definition: PcapLiveDevice.h:288
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:321
bool getLoopback() const
Definition: PcapLiveDevice.h:305
virtual PcapLiveDevice * clone() const
std::vector< IPAddress > getIPAddresses() const
Definition: PcapLiveDevice.h:329
Definition: PcapLiveDeviceList.h:25
Definition: PointerVector.h:58
Definition: RawPacket.h:269
The main namespace for the PcapPlusPlus lib.
std::function< bool(RawPacket *, PcapLiveDevice *, void *)> OnPacketArrivesStopBlocking
Definition: PcapLiveDevice.h:45
std::function< void(RawPacket *, PcapLiveDevice *, void *)> OnPacketArrivesCallback
Definition: PcapLiveDevice.h:36
std::function< void(IPcapDevice::PcapStats &, void *)> OnStatsUpdateCallback
Definition: PcapLiveDevice.h:53
LinkLayerType
Definition: RawPacket.h:25
@ LINKTYPE_ETHERNET
Definition: RawPacket.h:29
Definition: PcapDevice.h:128
Definition: PcapLiveDevice.h:195
int packetBufferTimeoutMs
Definition: PcapLiveDevice.h:203
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:256
int snapshotLength
Definition: PcapLiveDevice.h:228
bool usePoll
In Unix-like system, use poll() for blocking mode.
Definition: PcapLiveDevice.h:237
int packetBufferSize
Definition: PcapLiveDevice.h:213
unsigned int nflogGroup
Definition: PcapLiveDevice.h:234
PcapDirection direction
Definition: PcapLiveDevice.h:219
DeviceMode mode
Definition: PcapLiveDevice.h:197
A struct that contains all details of a network interface.
Definition: PcapLiveDevice.h:86
std::string description
Description of the device.
Definition: PcapLiveDevice.h:91
std::string name
Name of the device.
Definition: PcapLiveDevice.h:89
std::vector< IPAddress > addresses
IP addresses associated with the device.
Definition: PcapLiveDevice.h:93
bool isLoopback
Flag to indicate if the device is a loopback device.
Definition: PcapLiveDevice.h:95