1

I am trying to install the NPCap library into Visual Studio so I can run this code from the documentation.

#include "pcap.h"

main()
{
pcap_if_t* alldevs;
pcap_if_t* d;
int i = 0;
char errbuf[PCAP_ERRBUF_SIZE];

/* Retrieve the device list from the local machine */
if (pcap_findalldevs_ex(PCAP_SRC_IF_STRING, NULL /* auth is not needed */, &alldevs, errbuf) == -1)
{
    fprintf(stderr, "Error in pcap_findalldevs_ex: %s\n", errbuf);
    exit(1);
}

/* Print the list */
for (d = alldevs; d != NULL; d = d->next)
{
    printf("%d. %s", ++i, d->name);
    if (d->description)
        printf(" (%s)\n", d->description);
    else
        printf(" (No description available)\n");
}

if (i == 0)
{
    printf("\nNo interfaces found! Make sure Npcap is installed.\n");
    return;
}

/* We don't need any more the device list. Free it */
pcap_freealldevs(alldevs);

} When I run this code I get many errors, one of which is "cannot open source file "pcap/pcap.h". The other errors state that the variables are undefined. I believe I have not installed the library correctly.

I have both the .lib files and the .h files in the same directory in my desktop, as can be seen in this screenshot.

directory

I have also changed the directories in Visual Studio to the appropriate folder.

change1

change2

As per the instructions found in: How to add additional libraries to Visual Studio project?

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
Lyra Orwell
  • 1,048
  • 4
  • 17
  • 46

1 Answers1

0

From the error

"cannot open source file "pcap/pcap.h"

it looks like it is expecting a directory structure. Directory named "pcap" with all the header files in it.

Can you confirm you added this folder path in Library Directory as well. Link for reference.

  1. https://learn.microsoft.com/en-us/cpp/build/reference/vcpp-directories-property-page?view=vs-2019
  2. https://www.tutorialspoint.com/how-to-include-libraries-in-visual-studio-2012
newbash
  • 101
  • 2