I’m developing a simple packet sender/receiver for some purpose (in Dev c++)..wanna add more features to it. But I’m stuck at a point where I’m getting a strange error “Too many arguments to function”..My code is
#include <iostream>
#include <windows.h>
using namespace std;
int main(int argc, char *argv[])
{
HINSTANCE dllhandle = LoadLibrary("wpcap.dll");
FARPROC sendpacket = NULL, iface_handle = NULL;
iface_handle = GetProcAddress(dllhandle, "pcap_open");
char* iface_name = "\\Device\\NPF_{EADB4C21-B0AF-4EF2-86AB-80A37F399D1C}";
char *errbuf[256];
int iface = iface_handle(iface_name, 1000, 1, 500, NULL, errbuf); // The Error is here
system("pause");
return 0;
}
Can anyone tell me where I am going wrong?
First, refer to the official documentation for
pcap_open():Then look at the definition of
FARPROCinwindef.h: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: