Bryan Esbaugh wrote:

I just getting use to using WinPCap and had it working with my old IDE. However I've upgraded and starting messing with it again and now I've run into a problem that's driving me nuts.

I seem to be getting this error:

error C2664: 'pcap_loop' : cannot convert parameter 3 from 'void (u_char *,const pcap_pkthdr *,const u_char *)' to 'pcap_handler'


I tried wrapping the packet_handler class is extern "C" {...} and still same thing.



my code is pretty much this...

//copied more or less from the examples.....

void TableState::listen(void)
{
   pcap_if_t *alldevs;
   pcap_if_t *d;
   int inum;
   int j=0;
   pcap_t *adhandle;
   char errbuf[PCAP_ERRBUF_SIZE];

if (pcap_findalldevs(&alldevs, errbuf) == -1)
{
fprintf(stderr,"Error in pcap_findalldevs: %s\n", errbuf);
exit(1);
}
/* Print the list */
//Just use the first adapter.... inum = 1;
/* Jump to the selected adapter */
for(d=alldevs, j=0; j< inum-1 ;d=d->next, j++);
/* Open the adapter */
if ( (adhandle= pcap_open_live(d->name, // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs.
1, // promiscuous mode
1000, // read timeout
errbuf // error buffer
) ) == NULL)
{
fprintf(stderr,"\nUnable to open the adapter. %s is not supported by WinPcap\n");
/* Free the device list */
pcap_freealldevs(alldevs);
}
printf("\nlistening on %s...\n", d->description);
/* At this point, we don't need any more the device list. Free it */
pcap_freealldevs(alldevs);
/* start the capture */
pcap_loop(adhandle, 0,packet_handler, NULL);


}


void TableState::packet_handler(u_char * param, const struct pcap_pkthdr * header, const u_char * pkt_data)
{


//Just to show that I'm handling packets........
   ddlg->PostMessage(WM_SETMESSAGE,400,4);
}

I am no expert with winpcap by far, but The first thing that strikes me is that you are defining your packet handler as a member of the class TableState. Perhaps your callback function, packet_handler... whatever you decide to call it, needs to be a standalone function and not part of the class. Also you referenced wrapping the code in extern "C", and I see the idea there is to tell the linker to expect C functions not C++. I was reading a site the other day on using the extern keyword with C++ class members to tell the linker to give them C linkage, and I don't think it's that simple from what I read. I just googled for like 15 minutes and I can't find that site again, but I KNOW the site contained details on how to give C linkage to something that's in a C++ class member function. If you can find an article that talks about that you're probably homefree. Otherwise I'd just remove your packet_handler function from the C++ class.
Wish I could've given you a URL, but I hope it helps some anyway.


Cheers,
Mario




================================================================== This is the WinPcap users list. It is archived at http://www.mail-archive.com/winpcap-users@winpcap.polito.it/

To unsubscribe use mailto: [EMAIL PROTECTED]
==================================================================






==================================================================
This is the WinPcap users list. It is archived at
http://www.mail-archive.com/winpcap-users@winpcap.polito.it/

To unsubscribe use mailto: [EMAIL PROTECTED]
==================================================================

Reply via email to