Helper class for dealing with libpcap handles. More...
#include <pcap-helper.hpp>
Classes | |
class | Error |
Public Member Functions | |
PcapHelper (const std::string &interfaceName) | |
Create a libpcap context for live packet capture on a network interface. More... | |
~PcapHelper () | |
void | activate (int dlt) |
Start capturing packets. More... | |
void | close () noexcept |
Stop capturing and close the handle. More... | |
int | getFd () const |
Obtain a file descriptor that can be used in calls such as select(2) and poll(2). More... | |
std::string | getLastError () const noexcept |
Get last error message. More... | |
size_t | getNDropped () const |
Get the number of packets dropped by the kernel, as reported by libpcap. More... | |
void | setPacketFilter (const char *filter) const |
Install a BPF filter on the receiving socket. More... | |
std::tuple< span< const uint8_t >, std::string > | readNextPacket () const noexcept |
Read the next packet captured on the interface. More... | |
operator pcap_t * () const noexcept | |
Helper class for dealing with libpcap handles.
Definition at line 45 of file pcap-helper.hpp.
|
explicit |
Create a libpcap context for live packet capture on a network interface.
Error | on any error |
Definition at line 41 of file pcap-helper.cpp.
References ndn::ethernet::HDR_LEN, ndn::MAX_NDN_PACKET_SIZE, and NDN_THROW.
Referenced by nfd::face::PcapHelper::Error::Error().
nfd::face::PcapHelper::~PcapHelper | ( | ) |
Definition at line 60 of file pcap-helper.cpp.
References close().
Referenced by nfd::face::PcapHelper::Error::Error().
void nfd::face::PcapHelper::activate | ( | int | dlt | ) |
Start capturing packets.
dlt | The link-layer header type to be used. |
Error | on any error |
Definition at line 66 of file pcap-helper.cpp.
References getLastError(), NDN_THROW, and nfd::PrivilegeHelper::runElevated().
Referenced by nfd::face::PcapHelper::Error::Error(), nfd::face::EthernetTransport::EthernetTransport(), and nfd::face::EthernetChannel::listen().
|
noexcept |
Stop capturing and close the handle.
Definition at line 82 of file pcap-helper.cpp.
Referenced by nfd::face::EthernetTransport::doClose(), nfd::face::PcapHelper::Error::Error(), and ~PcapHelper().
int nfd::face::PcapHelper::getFd | ( | ) | const |
Obtain a file descriptor that can be used in calls such as select(2) and poll(2).
Error | on any error |
Definition at line 91 of file pcap-helper.cpp.
References NDN_THROW.
Referenced by nfd::face::PcapHelper::Error::Error(), nfd::face::EthernetTransport::EthernetTransport(), and nfd::face::EthernetChannel::listen().
|
noexcept |
Get last error message.
Definition at line 103 of file pcap-helper.cpp.
Referenced by activate(), nfd::face::EthernetTransport::doClose(), nfd::face::PcapHelper::Error::Error(), getNDropped(), readNextPacket(), and setPacketFilter().
size_t nfd::face::PcapHelper::getNDropped | ( | ) | const |
Get the number of packets dropped by the kernel, as reported by libpcap.
Error | on any error |
Definition at line 109 of file pcap-helper.cpp.
References getLastError(), and NDN_THROW.
Referenced by nfd::face::EthernetTransport::doClose(), nfd::face::PcapHelper::Error::Error(), and nfd::face::EthernetChannel::listen().
void nfd::face::PcapHelper::setPacketFilter | ( | const char * | filter | ) | const |
Install a BPF filter on the receiving socket.
filter | Null-terminated string containing the BPF program source. |
Error | on any error |
Definition at line 119 of file pcap-helper.cpp.
References getLastError(), NDN_THROW, and PCAP_NETMASK_UNKNOWN.
Referenced by nfd::face::PcapHelper::Error::Error(), nfd::face::EthernetChannel::listen(), nfd::face::MulticastEthernetTransport::MulticastEthernetTransport(), and nfd::face::UnicastEthernetTransport::UnicastEthernetTransport().
|
noexcept |
Read the next packet captured on the interface.
Definition at line 132 of file pcap-helper.cpp.
References getLastError().
Referenced by nfd::face::EthernetTransport::doClose(), nfd::face::PcapHelper::Error::Error(), and nfd::face::EthernetChannel::listen().
|
inlinenoexcept |
Definition at line 133 of file pcap-helper.hpp.