ユーザーがネットワークをスキャンできるようにするGUIプログラムがありますが、問題は、pcap_loop関数が呼び出されると、GUIプログラムが応答しなくなることです(pcap_loopは現在のスレッドをブロックします)。
pthreadを使用しようとすると、pcap_loop関数でSIGSEGVエラーが発生しました。なぜですか?スレッドがprocPacket関数自体を認識できないようです。
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.