사용자가 네트워크를 검색 할 수있는 GUI 프로그램이 있는데 문제는 pcap_loop 함수가 호출 될 때 GUI 프로그램이 응답하지 않는 것입니다 (pcap_loop가 현재 스레드를 차단 함).스레딩 및 pcap 문제
pthreads를 사용하려고하면 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.