A wrapper class for pcap_t* which is the libpcap packet capture descriptor. This class is used to manage the lifecycle of the pcap_t* object.
More...
#include <PcapLiveDevice.h>
|
|
constexpr | PcapHandle () noexcept=default |
| | Creates an empty handle.
|
| |
| | PcapHandle (pcap_t *pcapDescriptor) noexcept |
| | Creates a handle from the provided pcap descriptor. More...
|
| |
| bool | isValid () const noexcept |
| |
| pcap_t * | get () const noexcept |
| |
| pcap_t * | release () noexcept |
| | Releases ownership of the handle and returns the pcap descriptor. More...
|
| |
| void | reset (pcap_t *pcapDescriptor=nullptr) noexcept |
| | Replaces the managed handle with the provided one. More...
|
| |
| char const * | getLastError () const noexcept |
| | Helper function to retrieve a view of the last error string for this handle. More...
|
| |
| bool | setFilter (std::string const &filter) |
| | Sets a filter on the handle. Only packets that match the filter will be captured by the handle. More...
|
| |
| bool | clearFilter () |
| | Clears the filter currently set on the handle. More...
|
| |
| bool | getStatistics (PcapStats &stats) const |
| | Retrieves statistics from the pcap handle. More...
|
| |
| | operator bool () const noexcept |
| |
A wrapper class for pcap_t* which is the libpcap packet capture descriptor. This class is used to manage the lifecycle of the pcap_t* object.
◆ PcapHandle()
| pcpp::internal::PcapHandle::PcapHandle |
( |
pcap_t * |
pcapDescriptor | ) |
|
|
explicitnoexcept |
Creates a handle from the provided pcap descriptor.
- Parameters
-
| pcapDescriptor | The pcap descriptor to wrap. |
◆ clearFilter()
| bool pcpp::internal::PcapHandle::clearFilter |
( |
| ) |
|
Clears the filter currently set on the handle.
- Returns
- True if the filter was removed successfully or if no filter was set, false otherwise.
◆ get()
| pcap_t* pcpp::internal::PcapHandle::get |
( |
| ) |
const |
|
inlinenoexcept |
- Returns
- The underlying pcap descriptor.
◆ getLastError()
| char const* pcpp::internal::PcapHandle::getLastError |
( |
| ) |
const |
|
noexcept |
Helper function to retrieve a view of the last error string for this handle.
- Returns
- A null-terminated view of the last error string.
◆ getStatistics()
| bool pcpp::internal::PcapHandle::getStatistics |
( |
PcapStats & |
stats | ) |
const |
Retrieves statistics from the pcap handle.
The function internally calls pcap_stats() to retrieve the statistics and only works on live devices.
- Parameters
-
| stats | Structure to store the statistics. |
- Returns
- True if the statistics were retrieved successfully, false otherwise.
◆ isValid()
| bool pcpp::internal::PcapHandle::isValid |
( |
| ) |
const |
|
inlinenoexcept |
- Returns
- True if the handle is not null, false otherwise.
◆ operator bool()
| pcpp::internal::PcapHandle::operator bool |
( |
| ) |
const |
|
inlineexplicitnoexcept |
- Returns
- True if the handle is not null, false otherwise.
◆ release()
| pcap_t* pcpp::internal::PcapHandle::release |
( |
| ) |
|
|
noexcept |
Releases ownership of the handle and returns the pcap descriptor.
- Returns
- The pcap descriptor or nullptr if no handle is owned.
◆ reset()
| void pcpp::internal::PcapHandle::reset |
( |
pcap_t * |
pcapDescriptor = nullptr | ) |
|
|
noexcept |
Replaces the managed handle with the provided one.
- Parameters
-
| pcapDescriptor | A new pcap descriptor to manage. |
◆ setFilter()
| bool pcpp::internal::PcapHandle::setFilter |
( |
std::string const & |
filter | ) |
|
Sets a filter on the handle. Only packets that match the filter will be captured by the handle.
The filter uses Berkeley Packet Filter (BPF) syntax (http://biot.com/capstats/bpf.html).
- Parameters
-
| [in] | filter | The filter to set in Berkeley Packet Filter (BPF) syntax. |
- Returns
- True if the filter was set successfully, false otherwise.