At the moment, I am interested in networking and in order to learn more, I decided to use the PcapPlusPlus library to capture packets on my local network. My goal is to understand how packets are structured, position and content of the different headers (ethernet,ip,etc)
I compile in C++20 using cmake and vcpkg to manage my dependencies, I develop on the Visual Studio 2022 IDE on Windows. I'm able to compile and use the library. However, I get an empty list when I try to retrieve the different interfaces from my computer.
Here is the code I am using to list the interfaces :
#include <iostream>
#include <PcapLiveDeviceList.h>
int main()
{
const std::vector<pcpp::PcapLiveDevice*>& devList = pcpp::PcapLiveDeviceList::getInstance().getPcapLiveDevicesList();
if (devList.empty())
{
std::cout << "Empty device list" << std::endl;
return 1;
}
std::cout << "Network interfaces:" << std::endl;
for (std::vector<pcpp::PcapLiveDevice*>::const_iterator iter = devList.begin(); iter != devList.end(); iter++)
{
std::cout << " -> Name: '" << (*iter)->getName() << "' IP address: " << (*iter)->getIPv4Address().toString() << std::endl;
}
return 0;
}
Here is the CMakeLists:
cmake_minimum_required (VERSION 3.8)
set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
project ("test_pcap")
file(GLOB SOURCES *.cpp)
find_package(unofficial-pcapplusplus CONFIG REQUIRED)
add_executable (${PROJECT_NAME} ${SOURCES})
target_link_libraries(${PROJECT_NAME} PRIVATE
unofficial::pcapplusplus::pcappp
unofficial::pcapplusplus::packetpp
unofficial::pcapplusplus::commonpp
)
target_link_libraries(${PROJECT_NAME} PRIVATE ws2_32)
In order to fix the problem:
- I tried to run the program with administrator privileges without success.
- I tried to launch the program on another computer, again without success.
And finally I ran an example application provided by PcapPlusPlus (Arping) which allows to list the interfaces and it worked.
I think I must be missing a dependency, but as I have no error, I have no idea how to solve my problem.