PcapPlusPlus  24.09
pcpp::internal::PcapHandle Class Reference

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 <PcapDevice.h>

Public Member Functions

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...
 
 operator bool () const noexcept
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ PcapHandle()

pcpp::internal::PcapHandle::PcapHandle ( pcap_t *  pcapDescriptor)
explicitnoexcept

Creates a handle from the provided pcap descriptor.

Parameters
pcapDescriptorThe pcap descriptor to wrap.

Member Function Documentation

◆ 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.
Remarks
The returned view is only valid until the next call to a pcap function.

◆ 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
pcapDescriptorA new pcap descriptor to manage.
Remarks
If the handle contains a non-null descriptor it will be closed.