How to create a new stream for compatibility of pcap_loop () and gtk_main ()?

These two functions are infinite loops,

and the program freezes, once called in the same thread.

gtk_main(); 
...
pcap_loop(adhandle, 0, packet_handler, NULL);

When I press the Start button, I want pcapto start , and if I click the Stop button, pcap stop .

How to create a child thread and run pcap_loop(adhandle, 0, packet_handler, NULL);instead?

+3
source share
2 answers

- , , GTK +, libpcap , . , GTK +, libpcap: pcap_next() pcap_next_ex(), .

, g_timeout_add() g_idle_add(), .

+3

g_thread_create(). GTK.

gtk_main() , . "" g_thread_create(), pcap_loop().

"" , GLib . - ; , , GMutex. g_mutex_lock(), g_mutex_unlock(). packet_handler , . , , , pcap .

+1

Source: https://habr.com/ru/post/1744596/


All Articles