Using Sniffer within a class

26 views
Skip to first unread message

savio

unread,
Oct 23, 2013, 4:13:32 PM10/23/13
to libcr...@googlegroups.com
Hi Esteban ,

I have a problem with using the Sniffer within a class, no matter the changes i make, the member function does'nt match the sniffer packet handler function type.

My Program has the following structure:

using namespace std;
using namespace Crafter;

class Proto{

private:
Sniffer *sniff;

public:
void packet_handler(Packet *packet,void *user)
{
packet->Print();
}

void My_Sniffer()
{
sniff = new Sniffer("","eth0",&Proto::packet_handler);
sniff->Capture();
}
};

The problem is with the packet handler function. I keep getting this compilation error:

error: no matching function for call to 'Crafter::Sniffer::Sniffer(std::string, std::string, void (Proto::*)(Crafter::Packet*, void*))

I hope you can help me with a fix, A correction code would be much appreciated.

Thank You


savio

unread,
Oct 23, 2013, 6:11:16 PM10/23/13
to libcr...@googlegroups.com
Nevermind I solved it by converting the function:

Void (*func_ptr)(packet*,void*) = &Proto::packer_handler;

Sniffer sniff("","eth0",func_ptr);

And I declared the member function as static

Esteban Pellegrino

unread,
Oct 23, 2013, 11:10:02 PM10/23/13
to libcr...@googlegroups.com

Yes, glad you figure it out...  The problem is that member functions on c++ has an extra "this" pointer and that is not the signature of the function the Sniffer expects. You should declare it as static member function or use another function external to the class.

Best,

Esteban

--
You received this message because you are subscribed to the Google Groups "libcrafter" group.
To unsubscribe from this group and stop receiving emails from it, send an email to libcrafter+...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.
Reply all
Reply to author
Forward
0 new messages