Gast
#856050
Hallo! Ich bin einwenig am Basteln mit der LibPcap Library um Netzwerkpakete zu versenden und zu empfangen. Wie in der Dokumentation beschrieben wartet in pcap_next() das Programm endlos auf ein nicht ankommendes Paket, obwohl beim Öffnen des Adapters eine Wartezeit von 100ms angegeben wurde. Der Text aus der Dokumentation lautet: Note that pcap_next() will, on some platforms, loop reading packets from the OS; that loop will not necessarily be terminated by a signal, so pcap_breakloop() should be used to terminate packet processing even if pcap_next() is being used. OK, das scheint normal zu sein und es gibt eine Funktion die das Problem lösen sollte. Da das aktuelle Programm aber in einer Endlosschleife irgend wo in pcap_next hängt kann ich nicht aus dem aktuellen Programm heraus beenden. Einen neuen Thread starten? Scheint laut Dokumentation auch nicht zu gehen (abgesehen davon weiss ich auch nicht wie man das in ANSI C umsetzen könnte): Note also that, in a multi-threaded application, if one thread is blocked in pcap_dispatch(), pcap_loop(), pcap_next(), or pcap_next_ex(), a call to pcap_breakloop() in a different thread will not unblock that thread; you will need to use whatever mechanism the OS provides for breaking a thread out of blocking calls in order to unblock the thread, such as thread cancellation in systems that support POSIX threads. Das wirft bei mir mehr Fragen auf als Lösungen. Hat da jemand Erfahrung damit? Es kann a nicht sein, dass ich weil kein Paket angekommen ist das ganze Programm beenden muss... Wenn also jemand das gleiche Problem und eine Lösung dazu hat, oder in einem anderen Kontext ein ähnliches Problem hatte: her mit den Tipps ;) Grüsse