First, refer to the official documentation for pcap_open()
:
pcap_t* pcap_open ( const char * source,
int snaplen,
int flags,
int read_timeout,
struct pcap_rmtauth * auth,
char * errbuf
)
Then look at the definition of FARPROC
in windef.h
:
typedef INT_PTR (FAR WINAPI *FARPROC)();
You're attempting to call pcap_open()
using a completely wrong function signature. That's why the compiler is complaining that there's too many arguments. If you even manage to make this compile, you're almost certainly going to screw up the stack.
And why are you dynamically loading the WinPcap dll using LoadLibrary()
? Why not use the method outlined in the official documentation?
To create an application that uses wpcap.dll with Microsoft Visual
C++, follow these steps:
Include the file pcap.h at the beginning of every source file that
uses the functions exported by library.
If your program uses Win32 specific functions of WinPcap, remember
to include WPCAP among the preprocessor definitions.
If your program uses the remote capture capabilities of WinPcap, add
*HAVE_REMOTE* among the preprocessor definitions. Do not include
remote-ext.h directly in your source files.
Set the options of the linker to include the wpcap.lib library file
specific for your target (x86 or x64). wpcap.lib for x86 can be found
in the \lib folder of the WinPcap developer's pack, wpcap.lib for x64
can be found in the \lib\x64 folder.
You're using Dev C++, which probably doesn't have the VC++ compiler. You still need to declare the proper function signature. One possible way is through a typedef
:
#include <iostream>
#include <windows.h>
struct pcap_t;
struct pcap_rmtauth;
typedef pcap_t* (*pcap_open_func_ptr)(const char *source,
int snaplen, int flags, int read_timeout,
pcap_rmtauth *auth, char *errbuf);
int main(int argc, char *argv[])
{
HINSTANCE dllhandle = LoadLibrary("wpcap.dll");
pcap_open_func_ptr iface_handle =
reinterpret_cast<pcap_open_func_ptr>(
GetProcAddress(dllhandle, "pcap_open"));
char *errbuf[256];
pcap_t* iface = iface_handle(iface_name, 1000, 1, 500, NULL, errbuf);
// ...
return 0;
}