Skip to content

Commit 5d49353

Browse files
committed
Add logging around pcap open
1 parent b046ab9 commit 5d49353

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/inputs/pcap/PcapInputStream.cpp

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include <pcapplusplus/EthLayer.h>
2020
#include <pcapplusplus/IPv4Layer.h>
2121
#include <pcapplusplus/IPv6Layer.h>
22+
#include <pcapplusplus/IpUtils.h>
2223
#include <pcapplusplus/Logger.h>
2324
#include <pcapplusplus/PacketUtils.h>
2425
#include <pcapplusplus/PcapFileDevice.h>
@@ -28,7 +29,6 @@
2829
#endif
2930
#include <assert.h>
3031
#include <cstdint>
31-
#include <pcapplusplus/IpUtils.h>
3232
#include <sstream>
3333

3434
using namespace std::chrono;
@@ -537,6 +537,10 @@ void PcapInputStream::_open_af_packet_iface(const std::string &iface, const std:
537537

538538
void PcapInputStream::_open_libpcap_iface(const std::string &bpfFilter)
539539
{
540+
bool logEnabled = pcpp::Logger::getInstance().logsEnabled();
541+
pcpp::Logger::LogLevel logLevel = pcpp::Logger::getInstance().getLogLevel(pcpp::PcapLogModuleLiveDevice);
542+
pcpp::Logger::getInstance().enableLogs();
543+
pcpp::Logger::getInstance().setLogLevel(pcpp::PcapLogModuleLiveDevice, pcpp::Logger::LogLevel::Debug);
540544

541545
pcpp::PcapLiveDevice::DeviceConfiguration config;
542546
/*
@@ -560,6 +564,9 @@ void PcapInputStream::_open_libpcap_iface(const std::string &bpfFilter)
560564

561565
// try to open device
562566
if (!_pcapDevice->open(config)) {
567+
pcpp::Logger::getInstance().setLogLevel(pcpp::PcapLogModuleLiveDevice, logLevel);
568+
if (!logEnabled)
569+
pcpp::Logger::getInstance().suppressLogs();
563570
throw PcapException("Cannot open interface for packet capture");
564571
}
565572

0 commit comments

Comments
 (0)