Threading and pcap issues.
- by cftmon
I have a GUI program that allows a user a scan a network, the issue is that when the pcap_loop function is called, my GUI program becomes unresponsive.(the pcap_loop blocks the current thread).
When i try to use pthreads, i got a SIGSEGV fault at the pcap_loop function.Why?It's as if the thread can't see the procPacket function itself.
void procPacket(u_char *arg, const struct pcap_pkthdr *pkthdr, const u_char *packet)
{
//show packets here
}
void* pcapLooper(void* param)
{
pcap_t* handler = (pcap_t*) param;
pcap_loop(handler, 900 ,procPacket, NULL );
}
//some function that runs when a button is pressed
//handler has been opened through pcap_open_live
pthread_t scanner;
int t = pthread_create(&scanner,NULL,&pcapLooper, &handler );
if(t)
{
std::cout << "failed" << std::endl;
}
pthread_join(scanner,NULL);
//do other stuff.