/** @ingroup wpcap_tut
 */


/** @defgroup wpcap_tut4 Capturing the packets without the loopback
 *  @{

The sample showed in this lesson behaves exacltly like the one of the previous one (\ref wpcap_tut2), but it uses pcap_next_ex() instead of pcap_loop().

The callback-based capture mechanism of pcap_loop() is elegant and proves to be a good interface in several situations. However, handling a callback is sometimes not practical: it often makes the program more complex and it becomes a pain in situations like multithreaded applications or C++ classes.

In these cases, pcap_next_ex() allows to receive the packets with a direct call. Its parameters are the same of a capture callback: it receives an adapter descriptor and a couple of pointers that will be initialized and returned to the user: one to a pcap_pkthdr structure and another to a buffer with the packet data. 

In the following program, we recycle the callback code of the previous lesson's example and move it inside the main of the program, after the call to pcap_next_ex().


\include misc/basic_dump_ex.c

\note pcap_next_ex() at the moment is available only under Win32, because it's not a part of the original libpcap API. This means that source code that relies on it will not be portable under Unix.

Why we use pcap_next_ex() and not pcap_next(), that is instead available in libpcap as well? Because pcap_next() has some annoying limitations, that discourage its use in most situations. First of all, it is inefficient because it hides the callback method but still relies on pcap_dispatch(). Second, it is not able to detect EOF, so it's hardly useful when gathering packets from a file.

Notice instead that pcap_next_ex() returns different values for success, timeout elapsed, error and EOF conditions. 

@}*/
