Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 19 additions & 2 deletions src/inputs/pcap/PcapInputStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ void PcapInputStream::start()
interfaceIP4 = TARGET;
interfaceIP6 = TARGET;
}
std::string ifNameList = _get_interface_list();

if (_cur_pcap_source == PcapSource::libpcap) {
pcpp::PcapLiveDevice *pcapDevice;
Expand All @@ -152,7 +153,7 @@ void PcapInputStream::start()
} else {
pcapDevice = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDeviceByName(TARGET);
if (pcapDevice == nullptr) {
throw PcapException("Couldn't find interface by provided name: " + TARGET);
throw PcapException(fmt::format("Couldn't find interface by provided name: \"{}\". Available interfaces: {}", TARGET, ifNameList));
}
}

Expand All @@ -177,7 +178,7 @@ void PcapInputStream::start()

pcap_freealldevs(interfaceList);
if (_pcapDevice == nullptr) {
throw PcapException("Couldn't find interface by provided name: " + TARGET);
throw PcapException(fmt::format("Couldn't find interface by provided name: \"{}\". Available interfaces: {}", TARGET, ifNameList));
}
// end upstream PcapPlusPlus incompatibility block

Expand All @@ -204,6 +205,21 @@ void PcapInputStream::start()
_running = true;
}

std::string PcapInputStream::_get_interface_list() const
{
// gather list of valid interfaces
std::vector<std::string> ifNameListV;
auto l = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList();
for (const auto &ifd : l) {
ifNameListV.push_back(ifd->getName());
}
std::string ifNameList = std::accumulate(std::begin(ifNameListV), std::end(ifNameListV), std::string(),
[](std::string &ss, std::string &s) {
return ss.empty() ? s : ss + "," + s;
});
return ifNameList;
}

void PcapInputStream::stop()
{
if (!_running) {
Expand Down Expand Up @@ -530,6 +546,7 @@ void PcapInputStream::info_json(json &j) const
{
common_info_json(j);
json info;
info["available_iface"] = _get_interface_list();
info["host_ips"] = json::object();
for (auto &i : _hostIPv4) {
std::stringstream out;
Expand Down
1 change: 1 addition & 0 deletions src/inputs/pcap/PcapInputStream.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@ class PcapInputStream : public visor::InputStream
void _open_libpcap_iface(const std::string &bpfFilter = "");
void _get_hosts_from_libpcap_iface();
void _generate_mock_traffic();
std::string _get_interface_list() const;

#ifdef __linux__
void _open_af_packet_iface(const std::string &iface, const std::string &bpfFilter);
Expand Down