0

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.

vekoze
  • 1
  • 1
  • 1
  • Do you have WinPcap installed or do you have Npcap installed? – user16139739 Mar 05 '23 at 01:52
  • Yes, I have installed Npcap (already tried to reinstall it and reboot several times). Ncap appears in Windows "Add/Remove Programs", moreover `System32\drivers\npcap.sys` and `C:\Program Files\Npcap` do exist. – vekoze Mar 05 '23 at 03:40
  • You didn't post the entire output of your program. Are you seeing any error? Maybe `Error searching for devices`? – seladb Mar 05 '23 at 09:37
  • There is no error, the function `getPcapLiveDevicesList()` executes correctly and returns an empty vector. When I run the code I get "Empty device list". – vekoze Mar 05 '23 at 15:15

0 Answers0